Exemple #1
0
 def test_build_data_doctest(self):
     record = Record.build_data(0x1234, b'Hello, World!')
     ans_out = normalize_whitespace(repr(record))
     ans_ref = normalize_whitespace('''
     Record(address=0x00001234, tag=None, count=13,
            data=b'Hello, World!', checksum=0x69)
     ''')
     assert ans_out == ans_ref
Exemple #2
0
 def test_save_records(self, tmppath, datapath):
     path_out = tmppath / 'hexbytes.bin'
     path_ref = datapath / 'hexbytes.bin'
     records = [Record.build_data(0, HEXBYTES)]
     Record.save_records(str(path_out), records)
     ans_out = read_text(path_out)
     ans_ref = read_text(path_ref)
     assert ans_out == ans_ref
Exemple #3
0
    def test_split(self):
        with pytest.raises(ValueError):
            list(Record.split(b'', -1))

        with pytest.raises(ValueError):
            list(Record.split(b'', 1 << 32))

        with pytest.raises(ValueError):
            list(Record.split(b'abc', (1 << 32) - 1))

        ans_out = list(Record.split(BYTES))
        ans_ref = [Record.build_data(0, BYTES)]
        assert ans_out == ans_ref

        ans_out = list(Record.split(BYTES, columns=8))
        ans_ref = [
            Record.build_data(offset, BYTES[offset:(offset + 8)])
            for offset in range(0, 256, 8)
        ]
        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
Exemple #4
0
    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
Exemple #5
0
 def test_is_data(self):
     assert Record.build_data(0, b'').is_data()
Exemple #6
0
 def test_load_records(self, datapath):
     path_ref = datapath / 'hexbytes.bin'
     ans_out = list(Record.load_records(str(path_ref)))
     ans_ref = [Record.build_data(0, HEXBYTES)]
     assert ans_out == ans_ref