-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_serial.py
66 lines (46 loc) · 1.8 KB
/
test_serial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
pylibftdi - python wrapper for libftdi
Copyright (c) 2010-2014 Ben Bass <benbass@codedstructure.net>
See LICENSE file for details and (absence of) warranty
pylibftdi: https://github.com/codedstructure/pylibftdi
This module contains some basic tests for the higher-level
functionality without requiring an actual hardware device
to be attached.
"""
import unittest
from pylibftdi.serial_device import SerialDevice
from tests.test_common import CallCheckMixin, LoopDevice
class LoopSerialDevice(SerialDevice, LoopDevice):
pass
SerialDevice = LoopSerialDevice # type: ignore
# and now some test cases...
class SerialFunctions(CallCheckMixin, unittest.TestCase):
def setUp(self):
self.sd = SerialDevice()
def _read_test(self, item):
# check we ask for the modem status to get this
self.assertCalls(lambda: getattr(self.sd, item), "ftdi_poll_modem_status")
# check it isn't settable
self.assertRaises(AttributeError, lambda: setattr(self.sd, "dsr", 1))
def _write_test(self, item):
# check writes call appropriate libftdi function
self.assertCalls(lambda: setattr(self.sd, item, 1), "ftdi_set" + item)
# check reads don't call anything
self.assertCallsExact(lambda: getattr(self.sd, item), [])
def test_cts(self):
"""check setting and getting cts"""
self._read_test("cts")
def test_dsr(self):
"""check setting and getting dsr"""
self._read_test("dsr")
def test_ri(self):
"""check setting and getting ri"""
self._read_test("ri")
def test_dtr(self):
"""check setting and getting dtr"""
self._write_test("dtr")
def test_rts(self):
"""check setting and getting rts"""
self._write_test("rts")
if __name__ == "__main__":
unittest.main()