コード例 #1
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
コード例 #2
0
def test_blocks_to_records_doctest():
    data = bytes(range(256))
    blocks = list(chop_blocks(data, 16))
    records = blocks_to_records(blocks, MotorolaRecord)
    ans_ref = merge(blocks)
    ans_out = records_to_blocks(records)
    assert ans_ref == ans_out
コード例 #3
0
    def test_build_standalone(self):
        data = bytes(range(256))
        blocks = list(chop_blocks(data, 16))
        records = blocks_to_records(blocks, BinaryRecord)
        data_records = get_data_records(records)
        data_records2 = list(BinaryRecord.build_standalone(records))
        assert data_records == data_records2

        with pytest.raises(ValueError, match='unexpected positional arg'):
            next(BinaryRecord.build_standalone((), Ellipsis))

        with pytest.raises(ValueError, match='unexpected keyword arg'):
            next(BinaryRecord.build_standalone((), _=Ellipsis))
コード例 #4
0
def test_get_max_data_length_doctest():
    data = bytes(range(256))
    blocks = list(chop_blocks(data, 16))
    records = blocks_to_records(blocks, MotorolaRecord)
    data_records = get_data_records(records)
    assert get_max_data_length(data_records) == 16
コード例 #5
0
def test_get_data_records_doctest():
    data = bytes(range(256))
    blocks = list(chop_blocks(data, 16))
    records = blocks_to_records(blocks, MotorolaRecord)
    assert all(r.is_data() for r in get_data_records(records))