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