From a6542f0b63601c0fe406798a87380331d71950eb Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sun, 9 Sep 2018 16:23:09 +0200 Subject: [PATCH] edit decoder tests --- boswatch/decoder/decoder.py | 2 +- test/test_decoder.py | 87 +++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 49 deletions(-) diff --git a/boswatch/decoder/decoder.py b/boswatch/decoder/decoder.py index dab8f33..a0558f2 100644 --- a/boswatch/decoder/decoder.py +++ b/boswatch/decoder/decoder.py @@ -37,4 +37,4 @@ def decode(data): return ZveiDecoder.decode(data) else: logging.error("no decoder found for: %s", data) - return False + return None diff --git a/test/test_decoder.py b/test/test_decoder.py index 3309318..c8bfdfc 100644 --- a/test/test_decoder.py +++ b/test/test_decoder.py @@ -27,78 +27,69 @@ class Test_Decoder: def test_decoderNoData(self): """!Test a empty string""" - assert decoder.getDecoder("").decode("") is None + assert decoder.decode("") is None def test_decoderZveiValid(self): """!Test valid ZVEI""" - dec = decoder.getDecoder("ZVEI") - assert not dec.decode("ZVEI1: 12345") is None - assert not dec.decode("ZVEI1: 12838") is None - assert not dec.decode("ZVEI1: 34675") is None + assert not decoder.decode("ZVEI1: 12345") is None + assert not decoder.decode("ZVEI1: 12838") is None + assert not decoder.decode("ZVEI1: 34675") is None def test_decoderZveiDoubleTone(self): """!Test doubleTone included ZVEI""" - dec = decoder.getDecoder("ZVEI") - assert not dec.decode("ZVEI1: 6E789") is None - assert not dec.decode("ZVEI1: 975E7") is None - assert not dec.decode("ZVEI1: 2E87E") is None + assert not decoder.decode("ZVEI1: 6E789") is None + assert not decoder.decode("ZVEI1: 975E7") is None + assert not decoder.decode("ZVEI1: 2E87E") is None def test_decoderZveiInvalid(self): """Test invalid ZVEI""" - dec = decoder.getDecoder("ZVEI") - assert dec.decode("ZVEI1: 1245A") is None - assert dec.decode("ZVEI1: 1245") is None - assert dec.decode("ZVEI1: 135") is None - assert dec.decode("ZVEI1: 54") is None - assert dec.decode("ZVEI1: 54") is None + assert decoder.decode("ZVEI1: 1245A") is None + assert decoder.decode("ZVEI1: 1245") is None + assert decoder.decode("ZVEI1: 135") is None + assert decoder.decode("ZVEI1: 54") is None + assert decoder.decode("ZVEI1: 54") is None def test_decoderPocsagValid(self): """!Test valid POCSAG""" - dec = decoder.getDecoder("POCSAG") - assert not dec.decode("POCSAG512: Address: 1000000 Function: 0") is None - assert not dec.decode("POCSAG512: Address: 1000001 Function: 1") is None - assert not dec.decode("POCSAG1200: Address: 1000002 Function: 2") is None - assert not dec.decode("POCSAG2400: Address: 1000003 Function: 3") is None + assert not decoder.decode("POCSAG512: Address: 1000000 Function: 0") is None + assert not decoder.decode("POCSAG512: Address: 1000001 Function: 1") is None + assert not decoder.decode("POCSAG1200: Address: 1000002 Function: 2") is None + assert not decoder.decode("POCSAG2400: Address: 1000003 Function: 3") is None def test_decoderPocsagText(self): """!Test POCSAG with text""" - dec = decoder.getDecoder("POCSAG") - assert not dec.decode("POCSAG512: Address: 1000000 Function: 0 Alpha: test") is None - assert not dec.decode("POCSAG512: Address: 1000001 Function: 1 Alpha: test") is None - assert not dec.decode("POCSAG1200: Address: 1000002 Function: 2 Alpha: test") is None - assert not dec.decode("POCSAG2400: Address: 1000003 Function: 3 Alpha: test") is None + assert not decoder.decode("POCSAG512: Address: 1000000 Function: 0 Alpha: test") is None + assert not decoder.decode("POCSAG512: Address: 1000001 Function: 1 Alpha: test") is None + assert not decoder.decode("POCSAG1200: Address: 1000002 Function: 2 Alpha: test") is None + assert not decoder.decode("POCSAG2400: Address: 1000003 Function: 3 Alpha: test") is None def test_decoderPocsagShortRic(self): """!Test short POCSAG""" - dec = decoder.getDecoder("POCSAG") - assert not dec.decode("POCSAG512: Address: 3 Function: 0 Alpha: test") is None - assert not dec.decode("POCSAG512: Address: 33 Function: 0 Alpha: test") is None - assert not dec.decode("POCSAG1200: Address: 333 Function: 0 Alpha: test") is None - assert not dec.decode("POCSAG1200: Address: 3333 Function: 0 Alpha: test") is None - assert not dec.decode("POCSAG2400: Address: 33333 Function: 0 Alpha: test") is None - assert not dec.decode("POCSAG2400: Address: 333333 Function: 0 Alpha: test") is None - assert not dec.decode("POCSAG2400: Address: 3333333 Function: 0 Alpha: test") is None + assert not decoder.decode("POCSAG512: Address: 3 Function: 0 Alpha: test") is None + assert not decoder.decode("POCSAG512: Address: 33 Function: 0 Alpha: test") is None + assert not decoder.decode("POCSAG1200: Address: 333 Function: 0 Alpha: test") is None + assert not decoder.decode("POCSAG1200: Address: 3333 Function: 0 Alpha: test") is None + assert not decoder.decode("POCSAG2400: Address: 33333 Function: 0 Alpha: test") is None + assert not decoder.decode("POCSAG2400: Address: 333333 Function: 0 Alpha: test") is None + assert not decoder.decode("POCSAG2400: Address: 3333333 Function: 0 Alpha: test") is None def test_decoderPocsagInvalid(self): """!Test invalid POCSAG""" - dec = decoder.getDecoder("POCSAG") - assert dec.decode("POCSAG512: Address: 333333F Function: 0 Alpha: invalid") is None - assert dec.decode("POCSAG512: Address: 333333F Function: 1 Alpha: invalid") is None - assert dec.decode("POCSAG512: Address: 3333333 Function: 4 Alpha: invalid") is None + assert decoder.decode("POCSAG512: Address: 333333F Function: 0 Alpha: invalid") is None + assert decoder.decode("POCSAG512: Address: 333333F Function: 1 Alpha: invalid") is None + assert decoder.decode("POCSAG512: Address: 3333333 Function: 4 Alpha: invalid") is None def test_decoderFmsValid(self): """!Test valid FMS""" - dec = decoder.getDecoder("FMS") - assert not dec.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=I (ohneNA,ohneSIGNAL)) CRC correct""") is None - assert not dec.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=I (ohneNA,ohneSIGNAL)) CRC correct""") is None - assert not dec.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=II (ohneNA,mit SIGNAL)) CRC correct""") is None - assert not dec.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC correct""") is None - assert not dec.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC correct""") is None + assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=I (ohneNA,ohneSIGNAL)) CRC correct""") is None + assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=I (ohneNA,ohneSIGNAL)) CRC correct""") is None + assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=II (ohneNA,mit SIGNAL)) CRC correct""") is None + assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC correct""") is None + assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC correct""") is None def test_decoderFmsInvalid(self): """!Test invalid FMS""" - dec = decoder.getDecoder("FMS") - assert dec.decode("""FMS: 14170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC correct""") is None - assert dec.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Sta 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC correct""") is None - assert dec.decode("""FMS: 14170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC incorrect""") is None - assert dec.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Sta 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC incorrect""") is None + assert decoder.decode("""FMS: 14170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC correct""") is None + assert decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Sta 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC correct""") is None + assert decoder.decode("""FMS: 14170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC incorrect""") is None + assert decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Sta 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC incorrect""") is None