Browse Source

Merge pull request #57 from ajschmidt8/unit-tests

Fix Broken Unit Tests
main
AJ Schmidt 4 years ago
committed by GitHub
parent
commit
29e7dd16bd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions
  1. +4
    -1
      alarmdecoder/util.py
  2. +2
    -0
      test/test_ad2.py
  3. +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. 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): if (c == 10 or c == 13):
return buf return buf


+ 2
- 0
test/test_ad2.py View File

@@ -362,5 +362,7 @@ class TestAlarmDecoder(TestCase):
self._decoder._on_read(self, data=b'[00010001000000000A--],005,[f70000051003000008020000000000],"FAULT 05 "') self._decoder._on_read(self, data=b'[00010001000000000A--],005,[f70000051003000008020000000000],"FAULT 05 "')
self.assertEquals(self._zone_faulted, 5) self.assertEquals(self._zone_faulted, 5)


self._decoder._on_read(self, data=b'[00010001000000000A--],004,[f70000051003000008020000000000],"FAULT 04 "')
self._decoder._on_read(self, data=b'[00010001000000000A--],004,[f70000051003000008020000000000],"FAULT 05 "')
self._decoder._on_read(self, data=b'[00010001000000000A--],004,[f70000051003000008020000000000],"FAULT 04 "') self._decoder._on_read(self, data=b'[00010001000000000A--],004,[f70000051003000008020000000000],"FAULT 04 "')
self.assertEquals(self._zone_restored, 3) self.assertEquals(self._zone_restored, 3)

+ 4
- 1
test/test_devices.py View File

@@ -80,8 +80,11 @@ class TestSerialDevice(TestCase):
def test_read(self): def test_read(self):
self._device.interface = '/dev/ttyS0' self._device.interface = '/dev/ttyS0'
self._device.open(no_reader_thread=True) 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') 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('serial.Serial.fileno', return_value=1):
with patch.object(select, 'select', return_value=[[1], [], []]): with patch.object(select, 'select', return_value=[[1], [], []]):
ret = self._device.read() ret = self._device.read()


||||||
x
 
000:0
Loading…
Cancel
Save