Esempio n. 1
0
def test_dictionary(value, width, pairs, bs):
    assert rw.dictionary(*pairs).read(bio(bs)) == value
    assert rw.dictionary(*pairs).write(
        value, BytesIO()
    ).getvalue() == bytearray(bs)

    assert rw.dictionary(*pairs).width() == width
Esempio n. 2
0
def test_dictionary_read_error():
    some_rw = InstanceDouble('tchannel.rw.ReadWriter')
    allow(some_rw).read.and_raise(ReadError('great sadness'))

    dict_rw = rw.dictionary(('foo', some_rw))
    with pytest.raises(ReadError):
        dict_rw.read(BytesIO())
Esempio n. 3
0
def test_dictionary_ignore_fields():
    d_rw = rw.dictionary(
        ('x', rw.number(1)),
        (rw.skip, rw.constant(rw.number(2), 42)),
    )

    assert d_rw.read(bio([1, 0, 2])) == {'x': 1}
    assert d_rw.write(
        {'x': 1, rw.skip: 2, 'y': 3}, BytesIO()
    ).getvalue() == bytearray([1, 0, 42])

    assert d_rw.width() == 3