예제 #1
0
def test_int_custom():
    assert dumps([3, 4, 5], encoders=[encode_int_custom]) == '["3", "4", "5"]'
    assert loads(List[int], '["3", "4", "5"]', decoders=[decode_int_custom]) == [3, 4, 5]
예제 #2
0
def test_untyped_set():
    json = dumps(set([date(year=2020, month=1, day=2)]))
    assert json == '["2020-01-02"]'
예제 #3
0
def test_untyped_tuple():
    json = dumps((date(year=2020, month=1, day=2), 2))
    assert json == '["2020-01-02", 2]'
예제 #4
0
def test_untyped_dict():
    json = dumps({'key1': date(year=2020, month=1, day=2), 'key2': 'bla'})
    assert json == '{"key1": "2020-01-02", "key2": "bla"}'
예제 #5
0
def test_untyped_list():
    json = dumps([date(year=2020, month=1, day=2), 2])
    assert json == '["2020-01-02", 2]'
예제 #6
0
def check_json_error(typ, data, json_str):
    with raises(JsonError):
        dumps(data, typ)
    with raises(JsonError):
        loads(typ, json_str)