• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /usr/bin/env python
2#
3# This file is part of pySerial - Cross platform serial port support for Python
4# (C) 2017 Guillaume Galeazzi <guillaume.g@leazzi.ch>
5#
6# SPDX-License-Identifier:    BSD-3-Clause
7"""\
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 context management
15"""
16
17import unittest
18import serial
19
20# on which port should the tests be performed:
21PORT = 'loop://'
22
23
24class Test_Context(unittest.TestCase):
25    """Test context"""
26
27    def setUp(self):
28        # create a closed serial port
29        self.s = serial.serial_for_url(PORT)
30
31    def tearDown(self):
32        self.s.close()
33
34    def test_with_idempotent(self):
35        with self.s as stream:
36            stream.write(b'1234')
37
38        # do other stuff like calling an exe which use COM4
39
40        with self.s as stream:
41            stream.write(b'5678')
42
43
44if __name__ == '__main__':
45    import sys
46    sys.stdout.write(__doc__)
47    sys.argv[1:] = ['-v']
48    # When this module is executed from the command-line, it runs all its tests
49    unittest.main()
50