Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
def test_cannot_decode_homogeneous_list_with_incompatible() -> None:
    json = [1, 2, 3]
    expectation = DecodingError(TypeMismatch(("0", )))
    assert typedjson.decode(List[str], json) == expectation
Ejemplo n.º 6
0
def test_cannot_decode_none_as_tuple() -> None:
    json = None
    assert typedjson.decode(Tuple[str, ...],
                            json) == DecodingError(TypeMismatch(()))
Ejemplo n.º 7
0
def test_cannot_decode_none_as_list() -> None:
    json = None
    assert typedjson.decode(List[str], json) == DecodingError(TypeMismatch(()))
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
def test_cannot_decode_none() -> None:
    json = None
    assert typedjson.decode(str, json) == DecodingError(TypeMismatch(()))
Ejemplo n.º 10
0
def test_cannot_decode_float_as_int() -> None:
    json = 1.234
    assert typedjson.decode(int, json) == DecodingError(TypeMismatch(()))
Ejemplo n.º 11
0
def test_cannot_decode_with_wrong_type() -> None:
    json = True
    assert typedjson.decode(str, json) == DecodingError(TypeMismatch(()))
Ejemplo n.º 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