diff options
author | Chris Liechti <cliechti@gmx.net> | 2016-09-08 23:36:57 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2016-09-08 23:56:30 +0200 |
commit | 790be842b1c2e752210d5328dad05acb05d337bb (patch) | |
tree | 953b16de80c2ad56eeb5354ec4f62d9340e744b5 | |
parent | d3168894f0ada5fb9b02972242baeeeaf907d1ef (diff) | |
download | pyserial-git-790be842b1c2e752210d5328dad05acb05d337bb.tar.gz |
test: add minimal test for serial.theaded
-rw-r--r-- | test/test_threaded.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/test_threaded.py b/test/test_threaded.py new file mode 100644 index 0000000..90ccb85 --- /dev/null +++ b/test/test_threaded.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# +# This file is part of pySerial - Cross platform serial port support for Python +# (C) 2016 Chris Liechti <cliechti@gmx.net> +# +# SPDX-License-Identifier: BSD-3-Clause +"""\ +Test serial.threaded related functionality. +""" + +import os +import unittest +import serial +import serial.threaded +import time + + +# on which port should the tests be performed: +PORT = 'loop://' + +class Test_asyncio(unittest.TestCase): + """Test asyncio related functionality""" + + def test_line_reader(self): + """simple test of line reader class""" + + class TestLines(serial.threaded.LineReader): + def __init__(self): + super(TestLines, self).__init__() + self.received_lines = [] + + def handle_line(self, data): + self.received_lines.append(data) + + ser = serial.serial_for_url(PORT, baudrate=115200, timeout=1) + with serial.threaded.ReaderThread(ser, TestLines) as protocol: + protocol.write_line('hello') + time.sleep(1) + self.assertEqual(protocol.received_lines, ['hello']) + + +if __name__ == '__main__': + import sys + 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() |