Beispiel #1
0
    def test_split(self):
        with pytest.raises(ValueError):
            list(Record.split(BYTES, address=-1))

        with pytest.raises(ValueError):
            list(Record.split(BYTES, address=(1 << 32)))

        with pytest.raises(ValueError):
            list(Record.split(BYTES, address=((1 << 32) - 128)))

        with pytest.raises(ValueError):
            list(Record.split(BYTES, columns=256))

        ans_out = list(Record.split(HEXBYTES, address=0x12345678))
        ans_ref = [
            Record(0, Tag.EXTENDED_LINEAR_ADDRESS, b'\x124'),
            Record(0x12345678, Tag.DATA, b'\x00\x01\x02\x03\x04\x05\x06\x07'),
            Record(0x12345680, Tag.DATA, b'\x08\t\n\x0b\x0c\r\x0e\x0f'),
            Record(0, Tag.EXTENDED_LINEAR_ADDRESS, b'\x00\x00'),
            Record(0, Tag.START_LINEAR_ADDRESS, b'\x124Vx'),
            Record(0, Tag.END_OF_FILE, b''),
        ]
        assert ans_out == ans_ref

        ans_out = list(
            Record.split(HEXBYTES, address=0x0000FFF8, start=0x0000FFF8))
        ans_ref = [
            Record(0xFFF8, Tag.DATA, b'\x00\x01\x02\x03\x04\x05\x06\x07'),
            Record(0, Tag.EXTENDED_LINEAR_ADDRESS, b'\x00\x01'),
            Record(0x10000, Tag.DATA, b'\x08\t\n\x0b\x0c\r\x0e\x0f'),
            Record(0, Tag.EXTENDED_LINEAR_ADDRESS, b'\x00\x00'),
            Record(0, Tag.START_LINEAR_ADDRESS, b'\x00\x00\xff\xf8'),
            Record(0, Tag.END_OF_FILE, b'')
        ]
        assert ans_out == ans_ref

        ans_out = list(Record.split(HEXBYTES, address=0x0000FFF8, align=False))
        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
Beispiel #2
0
    def test_build_standalone(self):
        ans_out = list(Record.build_standalone([]))
        ans_ref = [
            Record(0, Tag.EXTENDED_LINEAR_ADDRESS, b'\x00\x00'),
            Record(0, Tag.START_LINEAR_ADDRESS, b'\x00\x00\x00\x00'),
            Record(0, Tag.END_OF_FILE, b''),
        ]
        assert ans_out == ans_ref

        ans_out = list(Record.build_standalone([], start=0))
        ans_ref = [
            Record(0, Tag.EXTENDED_LINEAR_ADDRESS, b'\x00\x00'),
            Record(0, Tag.START_LINEAR_ADDRESS, b'\x00\x00\x00\x00'),
            Record(0, Tag.END_OF_FILE, b''),
        ]
        assert ans_out == ans_ref

        data_records = [Record.build_data(0x1234, HEXBYTES)]
        ans_out = list(Record.build_standalone(data_records))
        ans_ref = [
            Record(0x1234, Tag.DATA, HEXBYTES),
            Record(0, Tag.EXTENDED_LINEAR_ADDRESS, b'\x00\x00'),
            Record(0, Tag.START_LINEAR_ADDRESS, b'\x00\x00\x12\x34'),
            Record(0, Tag.END_OF_FILE, b''),
        ]
        assert ans_out == ans_ref
Beispiel #3
0
 def test_readdress(self):
     ans_out = [
         Record.build_extended_segment_address(0x76540000),
         Record.build_data(0x00001000, b'Hello, World!'),
     ]
     Record.readdress(ans_out)
     ans_ref = [
         Record(0x00007650, Tag.EXTENDED_SEGMENT_ADDRESS, b'\x07\x65'),
         Record(0x00008650, Tag.DATA, b'Hello, World!'),
     ]
     assert ans_out == ans_ref
Beispiel #4
0
 def test_readdress_doctest(self):
     ans_out = [
         Record.build_extended_linear_address(0x76540000),
         Record.build_data(0x00003210, b'Hello, World!'),
     ]
     Record.readdress(ans_out)
     ans_ref = [
         Record(0x76540000, Tag.EXTENDED_LINEAR_ADDRESS, b'vT'),
         Record(0x76543210, Tag.DATA, b'Hello, World!'),
     ]
     assert ans_out == ans_ref
Beispiel #5
0
    def test___init__(self):
        with pytest.raises(ValueError):
            Record.build_data(-1, BYTES)

        with pytest.raises(ValueError):
            Record.build_data(1 << 32, BYTES)

        with pytest.raises(ValueError):
            Record.build_data((1 << 32) - 128, BYTES)
Beispiel #6
0
 def test_check(self):
     record = Record.build_data(0x1234, b'Hello, World!')
     record.count += 1
     record.update_checksum()
     with pytest.raises(ValueError):
         record.check()
Beispiel #7
0
 def test_build_data_doctest(self):
     ans_out = str(Record.build_data(0x1234, b'Hello, World!'))
     ans_ref = ':0D12340048656C6C6F2C20576F726C642144'
     assert ans_out == ans_ref