def test___repr__(self): r = Record(0x1234, None, b'Hello, World!', Ellipsis) ans_out = normalize_whitespace(repr(r)) ans_ref = normalize_whitespace(''' Record(address=0x1234, tag=None, count=13, data=b'Hello, World!', checksum=0x0469) ''') assert ans_out == ans_ref r = Record(0x1234, None, None, None) ans_out = normalize_whitespace(repr(r)) ans_ref = normalize_whitespace(''' Record(address=0x1234, tag=None, count=0, data=None, checksum=None) ''') assert ans_out == ans_ref r = Record(None, None, b'Hello, World!', None) ans_out = normalize_whitespace(repr(r)) ans_ref = normalize_whitespace(''' Record(address=None, tag=None, count=13, data=b'Hello, World!', checksum=None) ''') assert ans_out == ans_ref r = Record(None, None, None, Ellipsis) ans_out = normalize_whitespace(repr(r)) ans_ref = normalize_whitespace(''' Record(address=None, tag=None, count=0, data=None, checksum=0x0000) ''') assert ans_out == ans_ref
def test_build_standalone(self): ans_out = list(Record.build_standalone([])) ans_ref = [Record(None, None, None, 0)] assert ans_out == ans_ref data_records = [Record.build_data(0x1234, b'Hello, World!')] ans_out = list(Record.build_standalone(data_records)) ans_ref = [ Record(0x1234, None, b'Hello, World!'), Record(None, None, None, 0x0469), ] assert ans_out == ans_ref
def test_split(self): with pytest.raises(ValueError): list(Record.split(BYTES, address=-1)) with pytest.raises(ValueError): list(Record.split(BYTES, address=(1 << 16))) with pytest.raises(ValueError): list(Record.split(BYTES, address=((1 << 16) - 128))) with pytest.raises(ValueError): list(Record.split(BYTES, columns=256)) ans_out = list(Record.split(HEXBYTES)) ans_ref = [ Record(0, None, None, None), Record(None, None, HEXBYTES, None), Record(None, None, None, sum(HEXBYTES)), ] assert ans_out == ans_ref ans_out = list(Record.split(HEXBYTES, standalone=False)) ans_ref = [ Record(0, None, HEXBYTES, None), ] assert ans_out == ans_ref ans_out = list(Record.split(HEXBYTES, standalone=False, address=7, columns=5, align=3)) ans_ref = [ Record.build_data(7, HEXBYTES[:4]), Record.build_data(11, HEXBYTES[4:9]), Record.build_data(16, HEXBYTES[9:14]), Record.build_data(21, HEXBYTES[14:]), ] assert ans_out == ans_ref
def test_check_sequence(self): records = [ Record(0x1234, None, b'Hello, World!'), ] Record.check_sequence(records)