Beispiel #1
0
 def test_save_records(self, tmppath, datapath):
     path_out = tmppath / 'bytes.hex'
     path_ref = datapath / 'bytes.hex'
     records = list(Record.split(BYTES))
     Record.save_records(str(path_out), records)
     ans_out = read_text(path_out)
     ans_ref = read_text(path_ref)
     assert ans_out == ans_ref
Beispiel #2
0
def test_convert_records_doctest():
    motorola = list(MotorolaRecord.split(BYTES))
    intel = list(IntelRecord.split(BYTES))
    converted = convert_records(motorola, output_type=IntelRecord)
    assert converted == intel

    motorola = list(MotorolaRecord.split(BYTES))
    intel = list(IntelRecord.split(BYTES))
    converted = convert_records(intel, output_type=MotorolaRecord)
    assert converted == motorola
Beispiel #3
0
def test_convert_records():
    motorola1 = list(MotorolaRecord.split(BYTES))
    motorola2 = list(MotorolaRecord.split(BYTES))
    converted = convert_records(motorola1, input_type=MotorolaRecord)
    assert converted == motorola2

    intel1 = list(IntelRecord.split(BYTES))
    intel2 = list(IntelRecord.split(BYTES))
    converted = convert_records(intel1, output_type=IntelRecord)
    assert converted == intel2
Beispiel #4
0
def test_merge_records_doctest():
    data1 = bytes(range(0, 32))
    data2 = bytes(range(96, 128))
    blocks1 = list(chop_blocks(data1, 16, start=0))
    blocks2 = list(chop_blocks(data2, 16, start=96))
    records1 = blocks_to_records(blocks1, MotorolaRecord)
    records2 = blocks_to_records(blocks2, IntelRecord)
    IntelRecord.readdress(records2)
    data_records1 = get_data_records(records1)
    data_records2 = get_data_records(records2)
    merged_records = merge_records([data_records1, data_records2])
    merged_blocks = records_to_blocks(merged_records)
    ans_ref = merge(blocks1 + blocks2)
    ans_out = merged_blocks
    assert ans_ref == ans_out
Beispiel #5
0
def test_save_records_doctest(tmppath):
    path = str(tmppath / 'bytes.hex')
    records = list(IntelRecord.split(BYTES))
    save_records(path, records)
    ans_out = load_records(path)
    ans_ref = records
    assert ans_out == ans_ref
Beispiel #6
0
def test_convert_file_doctest(tmppath):
    path_mot = str(tmppath / 'bytes.mot')
    path_hex = str(tmppath / 'bytes.hex')
    motorola = list(MotorolaRecord.split(BYTES))
    intel = list(IntelRecord.split(BYTES))
    save_records(path_mot, motorola)
    convert_file(path_mot, path_hex)
    ans_out = load_records(path_hex)
    ans_ref = intel
    assert ans_out == ans_ref
Beispiel #7
0
def test_save_records(tmppath):
    path = str(tmppath / 'bytes.hex')
    records = list(IntelRecord.split(BYTES))
    save_records(path, records, IntelRecord)
    ans_out = load_records(path)
    ans_ref = records
    assert ans_out == ans_ref

    records = []
    save_records(path, records, IntelRecord)
    ans_out = load_records(path)
    ans_ref = records
    assert ans_out == ans_ref

    path = str(tmppath / 'bytes.mot')
    intel = list(IntelRecord.split(BYTES))
    motorola = list(MotorolaRecord.split(BYTES))
    save_records(path, intel, MotorolaRecord)
    ans_out = load_records(path)
    ans_ref = motorola
    assert ans_out == ans_ref
Beispiel #8
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 #9
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 #10
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 #11
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
Beispiel #12
0
    def test_build_extended_segment_address(self):
        with pytest.raises(ValueError):
            Record.build_extended_segment_address(-1)

        with pytest.raises(ValueError):
            Record.build_extended_segment_address(1 << 32)
Beispiel #13
0
 def test_build_start_segment_address_doctest(self):
     ans_out = str(Record.build_start_segment_address(0x12345678))
     ans_ref = ':0400000312345678E5'
     assert ans_out == ans_ref
Beispiel #14
0
 def test_build_end_of_file_doctest(self):
     ans_out = str(Record.build_end_of_file())
     ans_ref = ':00000001FF'
     assert ans_out == ans_ref
Beispiel #15
0
 def test_build_extended_linear_address_doctest(self):
     ans_out = str(Record.build_extended_linear_address(0x12345678))
     ans_ref = ':020000041234B4'
     assert ans_out == ans_ref
Beispiel #16
0
 def test_build_start_linear_address_doctest(self):
     ans_out = str(Record.build_start_linear_address(0x12345678))
     ans_ref = ':0400000512345678E3'
     assert ans_out == ans_ref
Beispiel #17
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 #18
0
    def test_build_start_linear_address(self):
        with pytest.raises(ValueError):
            Record.build_start_linear_address(-1)

        with pytest.raises(ValueError):
            Record.build_start_linear_address(1 << 32)
Beispiel #19
0
    def test_parse_record(self):
        with pytest.raises(ValueError):
            Record.parse_record('Hello, World!')

        with pytest.raises(ValueError):
            Record.parse_record(':01000001FF')
Beispiel #20
0
 def test_load_records(self, datapath):
     path_ref = datapath / 'bytes.hex'
     ans_out = list(Record.load_records(str(path_ref)))
     ans_ref = list(Record.split(BYTES))
     assert ans_out == ans_ref
Beispiel #21
0
 def test_build_extended_segment_address_doctest(self):
     ans_out = str(Record.build_extended_segment_address(0x12345678))
     ans_ref = ':020000020123D8'
     assert ans_out == ans_ref
Beispiel #22
0
 def test_terminate_doctest(self):
     ans_out = list(map(str, Record.terminate(0x12345678)))
     ans_ref = [':020000040000FA', ':0400000512345678E3', ':00000001FF']
     assert ans_out == ans_ref
Beispiel #23
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 #24
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