Exemplo n.º 1
0
    def test_chars_padding_added(self):
        u = Fields()
        u.add(CH(6, 'string'))
        u.string = '1234'

        data = u.pack()
        assert data == bytearray.fromhex('31 32 33 34 00 00')
Exemplo n.º 2
0
    def test_chars_too_long(self):
        u = Fields()
        u.add(CH(6, 'string'))
        u.string = '1234567'  # One byte too long

        with pytest.raises(ValueError):
            u.pack()
Exemplo n.º 3
0
    def test_basic_pack(self):
        u = Fields()
        u.add(CH(4, 'string'))
        u.string = '1234'

        data = u.pack()
        assert data == bytearray.fromhex("31 32 33 34")