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]
def test_untyped_set(): json = dumps(set([date(year=2020, month=1, day=2)])) assert json == '["2020-01-02"]'
def test_untyped_tuple(): json = dumps((date(year=2020, month=1, day=2), 2)) assert json == '["2020-01-02", 2]'
def test_untyped_dict(): json = dumps({'key1': date(year=2020, month=1, day=2), 'key2': 'bla'}) assert json == '{"key1": "2020-01-02", "key2": "bla"}'
def test_untyped_list(): json = dumps([date(year=2020, month=1, day=2), 2]) assert json == '["2020-01-02", 2]'
def check_json_error(typ, data, json_str): with raises(JsonError): dumps(data, typ) with raises(JsonError): loads(typ, json_str)