cliechti | e542b36 | 2011-03-18 00:49:16 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
cliechti | e542b36 | 2011-03-18 00:49:16 +0000 | [diff] [blame] | 2 | # |
Chris Liechti | 7c032f1 | 2015-10-27 23:02:00 +0100 | [diff] [blame] | 3 | # This file is part of pySerial - Cross platform serial port support for Python |
| 4 | # (C) 2001-2015 Chris Liechti <cliechti@gmx.net> |
| 5 | # |
| 6 | # SPDX-License-Identifier: BSD-3-Clause |
cliechti | e542b36 | 2011-03-18 00:49:16 +0000 | [diff] [blame] | 7 | """\ |
| 8 | Some tests for the serial module. |
| 9 | Part of pySerial (http://pyserial.sf.net) (C)2001-2011 cliechti@gmx.net |
| 10 | |
| 11 | Intended to be run on different platforms, to ensure portability of |
| 12 | the code. |
| 13 | |
| 14 | Cover some of the aspects of serial_for_url and the extension mechanism. |
| 15 | """ |
| 16 | |
| 17 | import unittest |
| 18 | import time |
| 19 | import sys |
| 20 | import serial |
| 21 | |
| 22 | |
| 23 | class Test_URL(unittest.TestCase): |
| 24 | """Test serial_for_url""" |
| 25 | |
| 26 | def test_loop(self): |
| 27 | """loop interface""" |
| 28 | s = serial.serial_for_url('loop://', do_not_open=True) |
| 29 | |
| 30 | def test_bad_url(self): |
| 31 | """invalid protocol specified""" |
Chris Liechti | dedd3b7 | 2015-12-11 20:44:22 +0100 | [diff] [blame^] | 32 | self.assertRaises(ValueError, serial.serial_for_url, "imnotknown://") |
cliechti | e542b36 | 2011-03-18 00:49:16 +0000 | [diff] [blame] | 33 | |
| 34 | def test_custom_url(self): |
| 35 | """custom protocol handlers""" |
| 36 | # it's unknown |
Chris Liechti | dedd3b7 | 2015-12-11 20:44:22 +0100 | [diff] [blame^] | 37 | self.assertRaises(ValueError, serial.serial_for_url, "test://") |
cliechti | e542b36 | 2011-03-18 00:49:16 +0000 | [diff] [blame] | 38 | # add search path |
| 39 | serial.protocol_handler_packages.append('handlers') |
| 40 | # now it should work |
| 41 | s = serial.serial_for_url("test://") |
| 42 | # remove our handler again |
| 43 | serial.protocol_handler_packages.remove('handlers') |
| 44 | # so it should not work anymore |
Chris Liechti | dedd3b7 | 2015-12-11 20:44:22 +0100 | [diff] [blame^] | 45 | self.assertRaises(ValueError, serial.serial_for_url, "test://") |
cliechti | e542b36 | 2011-03-18 00:49:16 +0000 | [diff] [blame] | 46 | |
| 47 | |
| 48 | if __name__ == '__main__': |
| 49 | import sys |
| 50 | sys.stdout.write(__doc__) |
| 51 | sys.argv[1:] = ['-v'] |
| 52 | # When this module is executed from the command-line, it runs all its tests |
| 53 | unittest.main() |