blob: 3f39cd0bb82732602cc3b5e3c56edd733ee4aba8 [file] [log] [blame]
cliechtie542b362011-03-18 00:49:16 +00001#! /usr/bin/env python
cliechtie542b362011-03-18 00:49:16 +00002#
Chris Liechti7c032f12015-10-27 23:02:00 +01003# 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
cliechtie542b362011-03-18 00:49:16 +00007"""\
8Some tests for the serial module.
9Part of pySerial (http://pyserial.sf.net) (C)2001-2011 cliechti@gmx.net
10
11Intended to be run on different platforms, to ensure portability of
12the code.
13
14Cover some of the aspects of serial_for_url and the extension mechanism.
15"""
16
17import unittest
18import time
19import sys
20import serial
21
22
23class 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"""
32 self.failUnlessRaises(ValueError, serial.serial_for_url, "imnotknown://")
33
34 def test_custom_url(self):
35 """custom protocol handlers"""
36 # it's unknown
37 self.failUnlessRaises(ValueError, serial.serial_for_url, "test://")
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
45 self.failUnlessRaises(ValueError, serial.serial_for_url, "test://")
46
47
48if __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()