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