def test_cannot_decode_parameterized_dataclass_with_wrong_parameter() -> None:
    json = {"t1": 100, "t2": "hello"}
    expectation = DecodingError(TypeMismatch(("t2", )))
    assert typedjson.decode(GenericJson[int, int], json) == expectation
def test_cannot_decode_heterogeneous_list_with_incompatible() -> None:
    json = [1, "foo"]
    expectation = DecodingError(TypeMismatch(("0", )))
    assert typedjson.decode(List[Union[str, str]], json) == expectation
def test_cannot_decode_dataclass_with_lack_of_property() -> None:
    json = {"id": "test-user", "age": 28, "name": {"last": "Kose"}}

    expectation = DecodingError(TypeMismatch(("name", "first")))

    assert typedjson.decode(UserJson, json) == expectation
def test_cannot_decode_fixed_tuple_with_short_sequence() -> None:
    json = (0, 1, 2)
    expectation = DecodingError(TypeMismatch(()))
    assert typedjson.decode(Tuple[int, int, int, int], json) == expectation
def test_cannot_decode_homogeneous_list_with_incompatible() -> None:
    json = [1, 2, 3]
    expectation = DecodingError(TypeMismatch(("0", )))
    assert typedjson.decode(List[str], json) == expectation
def test_cannot_decode_none_as_tuple() -> None:
    json = None
    assert typedjson.decode(Tuple[str, ...],
                            json) == DecodingError(TypeMismatch(()))
def test_cannot_decode_none_as_list() -> None:
    json = None
    assert typedjson.decode(List[str], json) == DecodingError(TypeMismatch(()))
def test_cannote_decode_tuple_with_incompatible() -> None:
    json = (0, 1, 2, 3)
    expectation = DecodingError(TypeMismatch(("1", )))
    assert typedjson.decode(Tuple[int, str, int, int], json) == expectation
def test_cannot_decode_none() -> None:
    json = None
    assert typedjson.decode(str, json) == DecodingError(TypeMismatch(()))
Example #10
0
def test_cannot_decode_float_as_int() -> None:
    json = 1.234
    assert typedjson.decode(int, json) == DecodingError(TypeMismatch(()))
Example #11
0
def test_cannot_decode_with_wrong_type() -> None:
    json = True
    assert typedjson.decode(str, json) == DecodingError(TypeMismatch(()))
Example #12
0
def test_cannot_decode_variable_tuple_with_short_sequence() -> None:
    json: Tuple = tuple()
    expectation = DecodingError(TypeMismatch(()))
    assert typedjson.decode(Tuple[int, ...], json) == expectation