thriftrw / thriftrw-python

A Thrift encoding library for Python
MIT License
36 stars 10 forks source link

can't round-trip strings as binary #29

Closed blampe closed 9 years ago

blampe commented 9 years ago
@pytest.mark.parametrize('s, val, out', [
    (b'foo', b'foo', b'foo'),
    ('foo', b'foo', b'foo'),
    (u'foo', b'foo', b'foo'),
])
def test_text_round_trip_binary(s, val, out):
    if out is None:
        out = s

    wire_val = BinaryTypeSpec.to_wire(s)
    assert wire_val == BinaryValue(val)
    assert BinaryTypeSpec.from_wire(wire_val) == out
tests/spec/test_primitive.py:55: in test_text_round_trip_binary
    wire_val = BinaryTypeSpec.to_wire(s)
thriftrw/spec/primitive.py:67: in to_wire
    check.instanceof_surface(self, value)
thriftrw/spec/check.py:55: in instanceof_surface
    instanceof_class(type_spec, type_spec.surface, value)
thriftrw/spec/check.py:61: in instanceof_class
    'Cannot serialize %r into a "%s".' % (value, type_spec.name)
E   TypeError: Cannot serialize u'foo' into a "binary".

@junchaowu @breerly @kriskowal

blampe commented 9 years ago

Decided to not do this unicode coercion automatically.