From 122a93209cd7f0ef3d6089f1c5d70a74ca25de80 Mon Sep 17 00:00:00 2001 From: Chris Liechti Date: Mon, 12 Sep 2016 23:42:51 +0200 Subject: test: add tests for to_bytes and iterbytes --- test/test_util.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/test_util.py diff --git a/test/test_util.py b/test/test_util.py new file mode 100644 index 0000000..cd0e0fb --- /dev/null +++ b/test/test_util.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# +# This file is part of pySerial - Cross platform serial port support for Python +# (C) 2016 Chris Liechti +# +# SPDX-License-Identifier: BSD-3-Clause +"""\ +Tests for utility functions of serualutil. +""" + +import os +import unittest +import serial +import time + + +class Test_util(unittest.TestCase): + """Test serial utility functions""" + + def test_to_bytes(self): + self.assertEqual(serial.to_bytes([1, 2, 3]), b'\x01\x02\x03') + self.assertEqual(serial.to_bytes(b'\x01\x02\x03'), b'\x01\x02\x03') + self.assertEqual(serial.to_bytes(bytearray([1,2,3])), b'\x01\x02\x03') + self.assertRaises(TypeError, serial.to_bytes, u'hello') + + def test_iterbytes(self): + self.assertEqual(list(serial.iterbytes(b'\x01\x02\x03')), [b'\x01', b'\x02', b'\x03']) + + + +if __name__ == '__main__': + import sys + sys.stdout.write(__doc__) + if len(sys.argv) > 1: + PORT = sys.argv[1] + sys.argv[1:] = ['-v'] + # When this module is executed from the command-line, it runs all its tests + unittest.main() -- cgit v1.2.1