예제 #1
0
    def test_build_count_doctest(self):
        ans_out = str(Record.build_count(0x1234))
        ans_ref = 'S5031234B6'
        assert ans_out == ans_ref

        ans_out = str(Record.build_count(0x123456))
        ans_ref = 'S6041234565F'
        assert ans_out == ans_ref
예제 #2
0
    def test_check(self):
        record = Record.build_data(0, b'')
        for tag in range(len(Tag), 256):
            record.tag = tag
            record.update_checksum()
            with pytest.raises(ValueError):
                record.check()

        record = Record.build_data(0, b'Hello, World!')
        record.check()
        record.tag = len(Tag)
        with pytest.raises(ValueError):
            record.check()

        record = Record.build_header(b'')
        record.address = 1
        record.update_checksum()
        with pytest.raises(ValueError, match='address error'):
            record.check()

        record = Record.build_count(0x1234)
        record.address = 1
        record.update_checksum()
        with pytest.raises(ValueError, match='address error'):
            record.check()

        record = Record.build_count(0x123456)
        record.address = 1
        record.update_checksum()
        with pytest.raises(ValueError, match='address error'):
            record.check()

        record = Record.build_data(0, bytearray(252))
        record.data.append(1)
        record.update_count()
        record.update_checksum()
        with pytest.raises(ValueError, match='count overflow'):
            record.check()

        record = Record.build_data(0, b'Hello, World!')
        record.count += 1
        record.update_checksum()
        with pytest.raises(ValueError, match='count error'):
            record.check()
예제 #3
0
    def test_check(self):
        record = Record.build_data(0, b'')
        for tag in range(len(Tag), 256):
            record.tag = tag
            record.update_checksum()
            with pytest.raises(ValueError):
                record.check()

        record = Record.build_data(0, b'Hello, World!')
        record.check()
        record.tag = len(Tag)
        with pytest.raises(ValueError):
            record.check()

        record = Record.build_header(b'')
        record.address = 1
        record.update_checksum()
        with pytest.raises(ValueError):
            record.check()

        record = Record.build_count(0x1234)
        record.address = 1
        record.update_checksum()
        with pytest.raises(ValueError):
            record.check()

        record = Record.build_count(0x123456)
        record.address = 1
        record.update_checksum()
        with pytest.raises(ValueError):
            record.check()

        record = Record.build_data(0, b'Hello, World!')
        record.count += 1
        record.update_checksum()
        with pytest.raises(ValueError):
            record.check()