def test___lt___doctest(self): record1 = BinaryRecord(0x1234, None, b'') record2 = BinaryRecord(0x4321, None, b'') assert (record1 < record2) record1 = BinaryRecord(0x4321, None, b'') record2 = BinaryRecord(0x1234, None, b'') assert not (record1 < record2)
def test_overlaps_doctest(self): record1 = BinaryRecord(0, None, b'abc') record2 = BinaryRecord(1, None, b'def') assert record1.overlaps(record2) record1 = BinaryRecord(0, None, b'abc') record2 = BinaryRecord(3, None, b'def') assert not record1.overlaps(record2)
def test_overlaps(self): record1 = BinaryRecord(0, None, b'abc') record1.address = None record2 = BinaryRecord(3, None, b'def') assert not record1.overlaps(record2) record1 = BinaryRecord(0, None, b'abc') record2 = BinaryRecord(3, None, b'def') record2.address = None assert not record1.overlaps(record2)
def test_check_sequence(self): record1 = BinaryRecord(0, None, b'abc') record2 = BinaryRecord(3, None, b'def') records = [record1, record2] BinaryRecord.check_sequence(records) record2.address = 1 record2.update_checksum() with pytest.raises(ValueError): BinaryRecord.check_sequence(records) record1.address = 3 record2.address = 0 record1.update_checksum() record2.update_checksum() with pytest.raises(ValueError): BinaryRecord.check_sequence(records)
def test_compute_checksum_doctest(self): record = BinaryRecord(0, None, b'Hello, World!') assert str(record) == '48656C6C6F2C20576F726C6421' assert hex(record.compute_checksum()) == '0x69' record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!') assert str(record) == 'S110000048656C6C6F2C20576F726C642186' assert hex(record.compute_checksum()) == '0x86' record = IntelRecord(0, IntelTag.DATA, b'Hello, World!') assert str(record) == ':0D00000048656C6C6F2C20576F726C64218A' assert hex(record.compute_checksum()) == '0x8a'
def test_compute_count_doctest(self): record = BinaryRecord(0, None, b'Hello, World!') assert str(record) == '48656C6C6F2C20576F726C6421' assert record.compute_count() == 13 record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!') assert str(record) == 'S110000048656C6C6F2C20576F726C642186' assert record.compute_count() == 16 record = IntelRecord(0, IntelTag.DATA, b'Hello, World!') assert str(record) == ':0D00000048656C6C6F2C20576F726C64218A' assert record.compute_count() == 13
def test___str___doctest(self): ans_out = str(BinaryRecord(0x1234, None, b'Hello, World!')) ans_ref = '48656C6C6F2C20576F726C6421' assert ans_out == ans_ref ans_out = str( MotorolaRecord(0x1234, MotorolaTag.DATA_16, b'Hello, World!')) ans_ref = 'S110123448656C6C6F2C20576F726C642140' assert ans_out == ans_ref ans_out = str(IntelRecord(0x1234, IntelTag.DATA, b'Hello, World!')) ans_ref = ':0D12340048656C6C6F2C20576F726C642144' assert ans_out == ans_ref
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'
def test_is_data_doctest(self): record = BinaryRecord(0, None, b'Hello, World!') assert record.is_data() record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!') assert record.is_data() record = MotorolaRecord(0, MotorolaTag.HEADER, b'Hello, World!') assert not record.is_data() record = IntelRecord(0, IntelTag.DATA, b'Hello, World!') assert record.is_data() record = IntelRecord(0, IntelTag.END_OF_FILE, b'') assert not record.is_data()
def test___init___doctest(self): r = BinaryRecord(0x1234, None, b'Hello, World!') ans_out = normalize_whitespace(repr(r)) ans_ref = normalize_whitespace(''' Record(address=0x00001234, tag=None, count=13, data=b'Hello, World!', checksum=0x69) ''') assert ans_out == ans_ref r = MotorolaRecord(0x1234, MotorolaTag.DATA_16, b'Hello, World!') ans_out = normalize_whitespace(repr(r)) ans_ref = normalize_whitespace(''' Record(address=0x00001234, tag=<Tag.DATA_16: 1>, count=16, data=b'Hello, World!', checksum=0x40) ''') assert ans_out == ans_ref r = IntelRecord(0x1234, IntelTag.DATA, b'Hello, World!') ans_out = normalize_whitespace(repr(r)) ans_ref = normalize_whitespace(''' Record(address=0x00001234, tag=<Tag.DATA: 0>, count=13, data=b'Hello, World!', checksum=0x44) ''') assert ans_out == ans_ref
def test___hash__(self): hash(BinaryRecord(0x1234, None, b'Hello, World!')) hash(MotorolaRecord(0x1234, MotorolaTag.DATA_16, b'Hello, World!')) hash(IntelRecord(0x1234, IntelTag.DATA, b'Hello, World!'))