Ejemplo n.º 1
0
    def test_update_count(self):
        record = BinaryRecord(0, None, b'Hello, World!')
        record.count = None
        record.update_count()
        assert str(record) == '48656C6C6F2C20576F726C6421'
        assert record.count == 13

        record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!')
        record.count = None
        record.update_count()
        assert str(record) == 'S110000048656C6C6F2C20576F726C642186'
        assert record.count == 16

        record = IntelRecord(0, IntelTag.DATA, b'Hello, World!')
        record.count = None
        record.update_count()
        assert str(record) == ':0D00000048656C6C6F2C20576F726C64218A'
        assert record.count == 13
Ejemplo n.º 2
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()