def test___eq___doctest(self): record1 = BinaryRecord.build_data(0, b'Hello, World!') record2 = BinaryRecord.build_data(0, b'Hello, World!') assert record1 == record2 record1 = BinaryRecord.build_data(0, b'Hello, World!') record2 = BinaryRecord.build_data(1, b'Hello, World!') assert record1 != record2 record1 = BinaryRecord.build_data(0, b'Hello, World!') record2 = BinaryRecord.build_data(0, b'hello, world!') assert record1 != record2 record1 = MotorolaRecord.build_header(b'Hello, World!') record2 = MotorolaRecord.build_data(0, b'hello, world!') assert record1 != record2
def test_check(self): record = Record.build_data(0, b'') for tag in range(len(Tag), 256): record.tag = tag record.update_checksum() with pytest.raises(ValueError): record.check() record = Record.build_data(0, b'Hello, World!') record.check() record.tag = len(Tag) with pytest.raises(ValueError): record.check() record = Record.build_header(b'') record.address = 1 record.update_checksum() with pytest.raises(ValueError, match='address error'): record.check() record = Record.build_count(0x1234) record.address = 1 record.update_checksum() with pytest.raises(ValueError, match='address error'): record.check() record = Record.build_count(0x123456) record.address = 1 record.update_checksum() with pytest.raises(ValueError, match='address error'): record.check() record = Record.build_data(0, bytearray(252)) record.data.append(1) record.update_count() record.update_checksum() with pytest.raises(ValueError, match='count overflow'): record.check() record = Record.build_data(0, b'Hello, World!') record.count += 1 record.update_checksum() with pytest.raises(ValueError, match='count error'): record.check()
def test_check(self): record = Record.build_data(0, b'') for tag in range(len(Tag), 256): record.tag = tag record.update_checksum() with pytest.raises(ValueError): record.check() record = Record.build_data(0, b'Hello, World!') record.check() record.tag = len(Tag) with pytest.raises(ValueError): record.check() record = Record.build_header(b'') record.address = 1 record.update_checksum() with pytest.raises(ValueError): record.check() record = Record.build_count(0x1234) record.address = 1 record.update_checksum() with pytest.raises(ValueError): record.check() record = Record.build_count(0x123456) record.address = 1 record.update_checksum() with pytest.raises(ValueError): record.check() record = Record.build_data(0, b'Hello, World!') record.count += 1 record.update_checksum() with pytest.raises(ValueError): record.check()
def test_build_header_doctest(self): ans_out = str(Record.build_header(b'Hello, World!')) ans_ref = 'S010000048656C6C6F2C20576F726C642186' assert ans_out == ans_ref