def test_to_json_with_obj_without_id(): class Obj(object): pass d = {'i': Obj()} with pytest.raises(TypeError): to_json(d)
def test_to_json_with_numpy(): class FakeNumpyFloat(object): def item(self): return 0.666 d = {'float': FakeNumpyFloat()} assert to_json(d) == '{"float": 0.666}'
def test_to_json(): d = { 'i': 42, 's': 'string', 'dt': datetime.datetime.now(), 'id': uuid.uuid4() } assert isinstance(to_json(d), basestring)
def test_from_json(): d = { 'i': 42, 's': 'string', 'dt': datetime.datetime.now(), 'id': uuid.uuid4() } assert isinstance(from_json(to_json(d)), dict)
def test_to_json_with_obj_with_id(): class Obj(object): id = '42' d = {'i': Obj()} assert isinstance(to_json(d), basestring)