summaryrefslogtreecommitdiff
path: root/test/test_rfc2217.py
blob: 7dbe2a6828c0c83071fb6c598c2158cb72d716a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/env python
#
# This file is part of pySerial - Cross platform serial port support for Python
# (C) 2015 Chris Liechti <cliechti@gmx.net>
#
# SPDX-License-Identifier:    BSD-3-Clause
"""\
Test RFC 2217 related functionality.
"""

import unittest
import serial
import serial.rfc2217


class Test_RFC2217(unittest.TestCase):
    """Test RFC 2217 related functionality"""

    def test_failed_connection(self):
        # connection to closed port
        s = serial.serial_for_url('rfc2217://127.99.99.99:2217', do_not_open=True)
        self.assertRaises(serial.SerialException, s.open)
        self.assertFalse(s.is_open)
        s.close()  # no errors expected
        # invalid address
        s = serial.serial_for_url('rfc2217://127goingtofail', do_not_open=True)
        self.assertRaises(serial.SerialException, s.open)
        self.assertFalse(s.is_open)
        s.close()  # no errors expected
        # close w/o open is also OK
        s = serial.serial_for_url('rfc2217://irrelevant', do_not_open=True)
        self.assertFalse(s.is_open)
        s.close()  # no errors expected


if __name__ == '__main__':
    import sys
    sys.stdout.write(__doc__)
    sys.stdout.write("Testing connection on localhost\n")
    sys.argv[1:] = ['-v']
    # When this module is executed from the command-line, it runs all its tests
    unittest.main()