예제 #1
0
    def test__get_checksum(self):
        record = BinaryRecord(0, None, b'Hello, World!')
        assert hex(record._get_checksum()) == '0x69'
        record.checksum = None
        assert hex(record._get_checksum()) == '0x69'

        record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!')
        assert hex(record._get_checksum()) == '0x86'
        record.checksum = None
        assert hex(record._get_checksum()) == '0x86'

        record = IntelRecord(0, IntelTag.DATA, b'Hello, World!')
        assert hex(record._get_checksum()) == '0x8a'
        record.checksum = None
        assert hex(record._get_checksum()) == '0x8a'
예제 #2
0
    def test_update_checksum(self):
        record = BinaryRecord(0, None, b'Hello, World!')
        record.checksum = None
        record.update_checksum()
        assert str(record) == '48656C6C6F2C20576F726C6421'
        assert hex(record.checksum or -1) == '0x69'

        record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!')
        record.checksum = None
        record.update_checksum()
        assert str(record) == 'S110000048656C6C6F2C20576F726C642186'
        assert hex(record.checksum or -1) == '0x86'

        record = IntelRecord(0, IntelTag.DATA, b'Hello, World!')
        record.checksum = None
        record.update_checksum()
        assert str(record) == ':0D00000048656C6C6F2C20576F726C64218A'
        assert hex(record.checksum or -1) == '0x8a'
예제 #3
0
    def test_check(self):
        with pytest.raises(ValueError):
            Record(-1, None, b'Hello, World!').check()

        record = Record(0, None, b'')
        record.data = None
        with pytest.raises(ValueError):
            record.check()

        record = Record(0, None, b'Hello, World!')
        record.checksum = None
        record.check()

        record = Record(0, None, b'Hello, World!')
        record.checksum = -1
        with pytest.raises(ValueError):
            record.check()

        record = Record(0, None, b'Hello, World!')
        record.checksum = 256
        with pytest.raises(ValueError):
            record.check()

        record = Record(0, None, b'')
        record.checksum ^= 0xFF
        with pytest.raises(ValueError):
            record.check()

        record = Record(0, None, b'')
        record.tag = -1
        with pytest.raises(ValueError):
            record.check()

        record = Record(0, None, b'')
        record.count = -1
        with pytest.raises(ValueError):
            record.check()