blob: e37d3fa9f357457820cdb986e703447871b96fac [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
cliechtie542b362011-03-18 00:49:16 +000018import serial
19
20
21class Test_URL(unittest.TestCase):
22 """Test serial_for_url"""
23
24 def test_loop(self):
25 """loop interface"""
Chris Liechti8e37ba92016-02-03 01:22:22 +010026 serial.serial_for_url('loop://', do_not_open=True)
cliechtie542b362011-03-18 00:49:16 +000027
28 def test_bad_url(self):
29 """invalid protocol specified"""
Chris Liechtidedd3b72015-12-11 20:44:22 +010030 self.assertRaises(ValueError, serial.serial_for_url, "imnotknown://")
cliechtie542b362011-03-18 00:49:16 +000031
32 def test_custom_url(self):
33 """custom protocol handlers"""
34 # it's unknown
Chris Liechtidedd3b72015-12-11 20:44:22 +010035 self.assertRaises(ValueError, serial.serial_for_url, "test://")
cliechtie542b362011-03-18 00:49:16 +000036 # add search path
37 serial.protocol_handler_packages.append('handlers')
38 # now it should work
Chris Liechti8e37ba92016-02-03 01:22:22 +010039 serial.serial_for_url("test://")
cliechtie542b362011-03-18 00:49:16 +000040 # remove our handler again
41 serial.protocol_handler_packages.remove('handlers')
42 # so it should not work anymore
Chris Liechtidedd3b72015-12-11 20:44:22 +010043 self.assertRaises(ValueError, serial.serial_for_url, "test://")
cliechtie542b362011-03-18 00:49:16 +000044
45
46if __name__ == '__main__':
47 import sys
48 sys.stdout.write(__doc__)
49 sys.argv[1:] = ['-v']
50 # When this module is executed from the command-line, it runs all its tests
51 unittest.main()