Example #1
0
def test_dumps_list_of_name() -> None:
    names = [
        NameJson(first="jiji", last=None),
        NameJson(first="gin", last="mitsuse"),
        NameJson(first="konoha", last="mitsuse"),
    ]

    expectation = "\n".join((
        "[",
        "  {",
        '    "first": "jiji",',
        '    "last": null',
        "  },",
        "  {",
        '    "first": "gin",',
        '    "last": "mitsuse"',
        "  },",
        "  {",
        '    "first": "konoha",',
        '    "last": "mitsuse"',
        "  }",
        "]",
    ))

    assert typedjson.dumps(names, indent=2) == expectation
Example #2
0
def test_dumps_newtype() -> None:
    expectation = '"foo"'
    assert typedjson.dumps(A("foo"), indent=2) == expectation
Example #3
0
def test_dumps_none() -> None:
    expectation = "null"
    assert typedjson.dumps(None, indent=2) == expectation
Example #4
0
def test_dumps_bool() -> None:
    expectation = "true"
    assert typedjson.dumps(True, indent=2) == expectation
Example #5
0
def test_dumps_str() -> None:
    expectation = '"hello"'
    assert typedjson.dumps("hello", indent=2) == expectation
Example #6
0
def test_dumps_float() -> None:
    expectation = "1.0"
    assert typedjson.dumps(1.0, indent=2) == expectation
Example #7
0
def test_dumps_int() -> None:
    expectation = "100"
    assert typedjson.dumps(100, indent=2) == expectation
Example #8
0
def test_dumps_seq() -> None:
    assert typedjson.dumps((data, ), indent=2) == expectation_seq
Example #9
0
def test_dumps() -> None:
    assert typedjson.dumps(data, indent=2) == expectation