예제 #1
0
def test_map_from_wire_duplicate_keys():
    mspec = spec.MapTypeSpec(spec.I16TypeSpec, spec.I32TypeSpec)
    result = mspec.from_wire(
        vmap(
            ttype.I16,
            ttype.I32,
            (vi16(0), vi32(1)),
            (vi16(2), vi32(3)),
            (vi16(4), vi32(5)),
            (vi16(0), vi32(6)),
        ))

    assert {0: 6, 2: 3, 4: 5} == result
예제 #2
0
    assert output == t_spec.from_wire(value)


@pytest.mark.parametrize('t_spec, value', [
    (spec.BoolTypeSpec, vbyte(1)),
    (spec.ByteTypeSpec, vbool(True)),
    (spec.ListTypeSpec(spec.I32TypeSpec), vset(ttype.I32, vi32(42))),
])
def test_ttype_mismatch(t_spec, value):
    with pytest.raises(ValueError):
        t_spec.from_wire(value)


@pytest.mark.parametrize(
    't_spec, pairs, obj',
    [(spec.MapTypeSpec(spec.TextTypeSpec, spec.I32TypeSpec), [], {}),
     (spec.MapTypeSpec(spec.TextTypeSpec, spec.I32TypeSpec), [
         (vbinary(b'a'), vi32(1)),
         (vbinary(b'b'), vi32(2)),
         (vbinary(b'c'), vi32(3)),
         (vbinary(b'\xe2\x98\x83'), vi32(4)),
     ], {
         u'a': 1,
         u'b': 2,
         u'c': 3,
         u'☃': 4,
     })])
def test_map_wire_conversion(t_spec, pairs, obj):
    ktype = t_spec.kspec.ttype_code
    vtype = t_spec.vspec.ttype_code