Example #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())
Example #2
0
def test_default_none():
    coerced = coerce({}, DefaultNone)
    assert coerced.none is None
Example #3
0
def test_coerce_newtype(annotation, value):
    coerced = coerce(value, annotation)
    assert isinstance(coerced, annotation.__supertype__)
Example #4
0
def test_coerce_simple(annotation, value):
    coerced = coerce(value, annotation)
    assert isinstance(coerced, annotation)
Example #5
0
def test_no_coercer():
    assert isinstance(coerce("foo", lambda x: 1), str)
Example #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)
Example #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)
Example #8
0
def test_coerce_supscripted(annotation, value, expected):
    assert coerce(value, annotation) == expected
Example #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)