blob: 700bdbb2b164a5778aad1d764808d675f164bc13 [file] [log] [blame]
cliechtie542b362011-03-18 00:49:16 +00001#! /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"""\
9Some tests for the serial module.
10Part of pySerial (http://pyserial.sf.net) (C)2001-2011 cliechti@gmx.net
11
12Intended to be run on different platforms, to ensure portability of
13the code.
14
15Cover some of the aspects of serial_for_url and the extension mechanism.
16"""
17
18import unittest
19import time
20import sys
21import serial
22
23
24class 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
49if __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()