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