@@ -58,7 +58,7 @@ class AlarmDecoderProtocol(basic.LineReceiver):
'''
# Protocol Stuff
delimiter = '\r\n'
delimiter = b '\r\n'
dropLine = True
def lineReceived(self, line):
@@ -71,7 +71,8 @@ class AlarmDecoderProtocol(basic.LineReceiver):
# (and apparently flush the remaining line), so detect
# when we get a prompt, and there was more data, and
# ignore the line
if line[-3:] == '\n!>' and len(line) > 3:
print(repr(line))
if line[-3:] == b'\n!>' and len(line) > 3:
return
self.on_read(data=line)
@@ -133,18 +134,18 @@ class TestADProtocol(unittest.TestCase):
openmock.assert_called_once_with(self.adp)
self.assertEqual(self.tr.value(), 'C\rV\r')
self.assertEqual(self.tr.value(), b 'C\rV\r')
self.tr.clear()
self.adp.dataReceived('VZ;RF;ZX;RE;AU;3X;CG;DD;MF;LR;KE;MK;CB\r\n')
self.adp.dataReceived('!CONFIG>ADDRESS=18&CONFIGBITS=ff00&LRR=N&EXP=NNNNN&REL=NNNN&MASK=ffffffff&DEDUPLICATE=N\r\n')
self.adp.dataReceived('!VER:ffffffff,V2.2a.6,TX;RX;SM;VZ;RF;ZX;RE;AU;3X;CG;DD;MF;LR;KE;MK;CB\r\n')
self.adp.dataReceived(b 'VZ;RF;ZX;RE;AU;3X;CG;DD;MF;LR;KE;MK;CB\r\n')
self.adp.dataReceived(b '!CONFIG>ADDRESS=18&CONFIGBITS=ff00&LRR=N&EXP=NNNNN&REL=NNNN&MASK=ffffffff&DEDUPLICATE=N\r\n')
self.adp.dataReceived(b '!VER:ffffffff,V2.2a.6,TX;RX;SM;VZ;RF;ZX;RE;AU;3X;CG;DD;MF;LR;KE;MK;CB\r\n')
def test_middleprompt(self):
'''Test that we don't create an error when a prompt appears
in the middle of the line which can happen at start up.'''
self.adp.dataReceived('[0000000110000000----],0f\n!>\r\n')
self.adp.dataReceived(b '[0000000110000000----],0f\n!>\r\n')
@mock.patch('alarmdecoder.AlarmDecoder.open')
@mock.patch('twisted.internet.serialport.SerialPort')
@@ -176,14 +177,14 @@ class TestADProtocol(unittest.TestCase):
ad = self.ad
adp = self.adp
#print `self.tr.value()`
#print(repr(self.tr.value()))
self.assertEqual(ad.version_number, 'V2.2a.6')
msgmock = mock.MagicMock()
ad.on_message += msgmock
data = '[0000000111000100----],006,[f7000007100600202a020000000000],"FIRE 06 "\r\n'
data = b '[0000000111000100----],006,[f7000007100600202a020000000000],"FIRE 06 "\r\n'
msgdata = data[:-2]
if False: # pragma: no cover
# This'd be nice, but the Message object doesn't have a working equality operator
@@ -204,7 +205,7 @@ class TestADProtocol(unittest.TestCase):
self.assertEqual(msg.text, 'FIRE 06 ')
msgmock.reset_mock()
adp.dataReceived('[0000000110000000----],010,[f70000071010000028020000000000],"FAULT 10 "\r\n')
adp.dataReceived(b '[0000000110000000----],010,[f70000071010000028020000000000],"FAULT 10 "\r\n')
msgmock.assert_called_once()
msg = msgmock.call_args[1]['message']
@@ -214,7 +215,7 @@ class TestADProtocol(unittest.TestCase):
adp.on_write += writemock
ad.send('5')
ad.send(b '5')
self.assertEqual(self.tr.value(), '5')
writemock.assert_called_once_with(adp, data='5')
self.assertEqual(self.tr.value(), b '5')
writemock.assert_called_once_with(adp, data=b '5')