diff options
author | Chris Liechti <cliechti@gmx.net> | 2017-03-03 23:43:39 +0100 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2017-03-03 23:43:39 +0100 |
commit | d26ec4c0b6b3613b7bcd0f5075352b893e4c7713 (patch) | |
tree | 80a48a93c46f6b0b7ab2a5387ed19e9860627c5a | |
parent | a18a2afafa8596a3329ec1bbe2584ebbb47e2a02 (diff) | |
download | pyserial-git-d26ec4c0b6b3613b7bcd0f5075352b893e4c7713.tar.gz |
test: add simple test for exclusive flag
-rw-r--r-- | test/test_exclusive.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test_exclusive.py b/test/test_exclusive.py new file mode 100644 index 0000000..c8942d2 --- /dev/null +++ b/test/test_exclusive.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# +# This file is part of pySerial - Cross platform serial port support for Python +# (C) 2017 Chris Liechti <cliechti@gmx.net> +# +# SPDX-License-Identifier: BSD-3-Clause +"""\ +Tests for exclusive access feature. +""" + +import os +import unittest +import sys +import serial + +# on which port should the tests be performed: +PORT = 'loop://' + +class Test_exclusive(unittest.TestCase): + """Test serial port locking""" + + def setUp(self): + if not isinstance(serial.serial_for_url(PORT), serial.Serial): + raise unittest.SkipTest("exclusive test only compatible with real serial port") + + @unittest.skipIf(os.name != 'posix', "exclusive setting not supported on platform") + def test_exclusive(self): + """test if port can be opened twice""" + a = serial.Serial(PORT, exclusive=True) + with self.assertRaises(serial.SerialException): + b = serial.Serial(PORT, exclusive=True) + + +if __name__ == '__main__': + sys.stdout.write(__doc__) + if len(sys.argv) > 1: + PORT = sys.argv[1] + sys.stdout.write("Testing port: {!r}\n".format(PORT)) + sys.argv[1:] = ['-v'] + # When this module is executed from the command-line, it runs all its tests + unittest.main() |