Browse Source

fix py2 unit tests

main
AJ Schmidt 3 years ago
parent
commit
355ff9cc6d
2 changed files with 8 additions and 2 deletions
  1. +4
    -1
      alarmdecoder/util.py
  2. +4
    -1
      test/test_devices.py

+ 4
- 1
alarmdecoder/util.py View File

@@ -97,7 +97,10 @@ def filter_ad2prot_byte(buf):
"""
Return the byte sent in back if valid visible terminal characters or line terminators.
"""
c = buf[0]
if sys.version_info > (3,):
c = buf[0]
else:
c = ord(buf)

if (c == 10 or c == 13):
return buf


+ 4
- 1
test/test_devices.py View File

@@ -80,8 +80,11 @@ class TestSerialDevice(TestCase):
def test_read(self):
self._device.interface = '/dev/ttyS0'
self._device.open(no_reader_thread=True)
side_effect = ["t"]
if sys.version_info > (3,):
side_effect = ["t".encode('utf-8')]

with patch.object(self._device._device, 'read', return_value=[1]) as mock:
with patch.object(self._device._device, 'read', side_effect=side_effect) as mock:
with patch('serial.Serial.fileno', return_value=1):
with patch.object(select, 'select', return_value=[[1], [], []]):
ret = self._device.read()


Loading…
Cancel
Save