示例#1
0
def test_coerce_mapping_subscripted(annotation, value):
    annotation = resolve_supertype(annotation)
    key_arg, value_arg = annotation.__args__
    coerced = coerce(value, annotation)
    assert isinstance(coerced, annotation.__origin__)
    assert all(isinstance(x, key_arg) for x in coerced.keys())
    assert all(isinstance(x, value_arg) for x in coerced.values())
示例#2
0
def test_default_none():
    coerced = coerce({}, DefaultNone)
    assert coerced.none is None
示例#3
0
def test_coerce_newtype(annotation, value):
    coerced = coerce(value, annotation)
    assert isinstance(coerced, annotation.__supertype__)
示例#4
0
def test_coerce_simple(annotation, value):
    coerced = coerce(value, annotation)
    assert isinstance(coerced, annotation)
示例#5
0
def test_no_coercer():
    assert isinstance(coerce("foo", lambda x: 1), str)
示例#6
0
def test_coerce_nested_sequence():
    coerced = coerce({"datum": [{"foo": "bar"}]}, NestedSeq)
    assert isinstance(coerced, NestedSeq)
    assert all(isinstance(x, Data) for x in coerced.datum)
示例#7
0
def test_coerce_collections_subscripted(annotation, value):
    arg = annotation.__args__[0]
    coerced = coerce(value, annotation)
    assert isinstance(coerced, annotation.__origin__) and all(
        isinstance(x, arg) for x in coerced)
示例#8
0
def test_coerce_supscripted(annotation, value, expected):
    assert coerce(value, annotation) == expected
示例#9
0
def test_coerce_nested_sequence():
    coerced = coerce({'datum': [{'foo': 'bar'}]}, NestedSeq)
    assert isinstance(coerced, NestedSeq)
    assert all(isinstance(x, Data) for x in coerced.datum)