Exemplo n.º 1
0
    def test_is_data_doctest(self):
        record = BinaryRecord(0, None, b'Hello, World!')
        assert record.is_data()

        record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!')
        assert record.is_data()

        record = MotorolaRecord(0, MotorolaTag.HEADER, b'Hello, World!')
        assert not record.is_data()

        record = IntelRecord(0, IntelTag.DATA, b'Hello, World!')
        assert record.is_data()

        record = IntelRecord(0, IntelTag.END_OF_FILE, b'')
        assert not record.is_data()
Exemplo n.º 2
0
    def test_compute_checksum_doctest(self):
        record = BinaryRecord(0, None, b'Hello, World!')
        assert str(record) == '48656C6C6F2C20576F726C6421'
        assert hex(record.compute_checksum()) == '0x69'

        record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!')
        assert str(record) == 'S110000048656C6C6F2C20576F726C642186'
        assert hex(record.compute_checksum()) == '0x86'

        record = IntelRecord(0, IntelTag.DATA, b'Hello, World!')
        assert str(record) == ':0D00000048656C6C6F2C20576F726C64218A'
        assert hex(record.compute_checksum()) == '0x8a'
Exemplo n.º 3
0
    def test_compute_count_doctest(self):
        record = BinaryRecord(0, None, b'Hello, World!')
        assert str(record) == '48656C6C6F2C20576F726C6421'
        assert record.compute_count() == 13

        record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!')
        assert str(record) == 'S110000048656C6C6F2C20576F726C642186'
        assert record.compute_count() == 16

        record = IntelRecord(0, IntelTag.DATA, b'Hello, World!')
        assert str(record) == ':0D00000048656C6C6F2C20576F726C64218A'
        assert record.compute_count() == 13
Exemplo n.º 4
0
    def test___str___doctest(self):
        ans_out = str(BinaryRecord(0x1234, None, b'Hello, World!'))
        ans_ref = '48656C6C6F2C20576F726C6421'
        assert ans_out == ans_ref

        ans_out = str(
            MotorolaRecord(0x1234, MotorolaTag.DATA_16, b'Hello, World!'))
        ans_ref = 'S110123448656C6C6F2C20576F726C642140'
        assert ans_out == ans_ref

        ans_out = str(IntelRecord(0x1234, IntelTag.DATA, b'Hello, World!'))
        ans_ref = ':0D12340048656C6C6F2C20576F726C642144'
        assert ans_out == ans_ref
Exemplo n.º 5
0
    def test__get_checksum(self):
        record = BinaryRecord(0, None, b'Hello, World!')
        assert hex(record._get_checksum()) == '0x69'
        record.checksum = None
        assert hex(record._get_checksum()) == '0x69'

        record = MotorolaRecord(0, MotorolaTag.DATA_16, b'Hello, World!')
        assert hex(record._get_checksum()) == '0x86'
        record.checksum = None
        assert hex(record._get_checksum()) == '0x86'

        record = IntelRecord(0, IntelTag.DATA, b'Hello, World!')
        assert hex(record._get_checksum()) == '0x8a'
        record.checksum = None
        assert hex(record._get_checksum()) == '0x8a'
Exemplo n.º 6
0
    def test___init___doctest(self):
        r = BinaryRecord(0x1234, None, b'Hello, World!')
        ans_out = normalize_whitespace(repr(r))
        ans_ref = normalize_whitespace('''
        Record(address=0x00001234, tag=None, count=13,
               data=b'Hello, World!', checksum=0x69)
        ''')
        assert ans_out == ans_ref

        r = MotorolaRecord(0x1234, MotorolaTag.DATA_16, b'Hello, World!')
        ans_out = normalize_whitespace(repr(r))
        ans_ref = normalize_whitespace('''
        Record(address=0x00001234, tag=<Tag.DATA_16: 1>,
               count=16, data=b'Hello, World!', checksum=0x40)
        ''')
        assert ans_out == ans_ref

        r = IntelRecord(0x1234, IntelTag.DATA, b'Hello, World!')
        ans_out = normalize_whitespace(repr(r))
        ans_ref = normalize_whitespace('''
        Record(address=0x00001234, tag=<Tag.DATA: 0>, count=13,
               data=b'Hello, World!', checksum=0x44)
        ''')
        assert ans_out == ans_ref
Exemplo n.º 7
0
 def test___hash__(self):
     hash(BinaryRecord(0x1234, None, b'Hello, World!'))
     hash(MotorolaRecord(0x1234, MotorolaTag.DATA_16, b'Hello, World!'))
     hash(IntelRecord(0x1234, IntelTag.DATA, b'Hello, World!'))