blob: cd0e0fb9c2486c28a1fa405c0786477087e081b6 [file] [log] [blame]
Chris Liechti122a9322016-09-12 23:42:51 +02001#!/usr/bin/env python
2#
3# This file is part of pySerial - Cross platform serial port support for Python
4# (C) 2016 Chris Liechti <cliechti@gmx.net>
5#
6# SPDX-License-Identifier: BSD-3-Clause
7"""\
8Tests for utility functions of serualutil.
9"""
10
11import os
12import unittest
13import serial
14import time
15
16
17class Test_util(unittest.TestCase):
18 """Test serial utility functions"""
19
20 def test_to_bytes(self):
21 self.assertEqual(serial.to_bytes([1, 2, 3]), b'\x01\x02\x03')
22 self.assertEqual(serial.to_bytes(b'\x01\x02\x03'), b'\x01\x02\x03')
23 self.assertEqual(serial.to_bytes(bytearray([1,2,3])), b'\x01\x02\x03')
24 self.assertRaises(TypeError, serial.to_bytes, u'hello')
25
26 def test_iterbytes(self):
27 self.assertEqual(list(serial.iterbytes(b'\x01\x02\x03')), [b'\x01', b'\x02', b'\x03'])
28
29
30
31if __name__ == '__main__':
32 import sys
33 sys.stdout.write(__doc__)
34 if len(sys.argv) > 1:
35 PORT = sys.argv[1]
36 sys.argv[1:] = ['-v']
37 # When this module is executed from the command-line, it runs all its tests
38 unittest.main()