示例#1
0
def test_factory_nametuple():
    json_d = '{"__type__": "__namedtuple__", "__module__": "test_serializers", "__name__": "MyStruct", ' \
             '"param": "bb", "args": null}'
    native = datecompatible_loads(json_d)  # type: MyStruct
    assert native['param'] == 'bb'
    assert native.param == 'bb'
    assert len(native) == 2
示例#2
0
def test_full_chained_decode(fixture):
    encoded = datecompatible_dumps(fixture.native)
    native = datecompatible_loads(encoded)
    assert native == fixture.native
示例#3
0
def test_decode_leaf(fixture):
    native = datecompatible_loads(fixture.encoded)
    print(fixture)
    assert native == fixture.native
示例#4
0
def test_isoformat_to_date():
    d = '{"__type__": "__datetime__", "utcisodate": "1988-03-07T11:05:00+00:00"}'
    loaded = datecompatible_loads(d)
    assert loaded == datetime.datetime(1988, 3, 7, 11, 5, tzinfo=pytz.utc)
    assert loaded.tzinfo is not None
示例#5
0
def test_broken_nametuple():
    json_d = ' {"__type__": "__namedtuple__", "__module__": "test_serializers", "__name__": 1, "param": "bb"}'
    with pytest.raises(ValueError):
        native_fallback = datecompatible_loads(json_d)  # type: dict