Browse Source

update to Python 3...

The pinned version of alarmdecoder is because of this commit:
02312961a2

In my test data, from a real device conencted to a real system, the new
library doesn't work...  Likely there was a firmware update that changed
this behavior, but the code doesn't handle the older firmware..  This
may change w/ new devices, but this makes all the tests pass now...
main
John-Mark Gurney 3 years ago
parent
commit
5b1c7eae0b
3 changed files with 19 additions and 16 deletions
  1. +4
    -2
      Makefile
  2. +14
    -13
      adtwist.py
  3. +1
    -1
      requirements.txt

+ 4
- 2
Makefile View File

@@ -1,8 +1,10 @@
PYTHON?=python3.9

test:
. ./t/bin/activate && \
echo adtwist.py | entr sh -c 'python -m coverage run -m unittest adtwist && coverage report -m --omit=t/\*'
echo adtwist.py | entr sh -c 'python -m coverage run -m unittest --failfast adtwist && coverage report -m --omit=t/\*'

setup:
virtualenv t && \
$(PYTHON) -m venv t && \
. ./t/bin/activate && \
pip install -r requirements.txt

+ 14
- 13
adtwist.py View File

@@ -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')

+ 1
- 1
requirements.txt View File

@@ -1,4 +1,4 @@
alarmdecoder
-e git+https://github.com/nutechsoftware/alarmdecoder.git@72a9d417ecc254301db044e1408b292fcf22a71d#egg=alarmdecoder
coverage
mock
twisted

Loading…
Cancel
Save