def test_simple_type(): items = (0, -1, 545453486545, '', -float('inf'), float('inf'), -121.46, -4654e-10, False, True, 'fg', 'None', "1.65", -65, 1e10) for item in items: assert str_to_obj(obj_to_str(item)) == item assert str_to_obj(obj_to_str('\n')) == '\n' assert math.isnan(str_to_obj(obj_to_str(float('nan'))))
def loads(self, s): if s == '': return '' return str_to_obj(s) # a = 123 # def f(): # print(a) # # print(JsonParser().dumps(f))
def test_func(): def f1(): return 1 + 3 a = 4 def f2(): return a + b f3 = lambda: a + b to_remove = (' ', '\n', '\t') functions = (f1, f2, f3) for func in functions: assert str_to_obj(obj_to_str(func))() == func()
def test_dict(): items = [{}, { 'a': { 'b': { 'c': 1 } } }, dict(g=1), { '': 1 }, { '': { 'g': { 'a': -1 }, 'b': -14e-10 }, 'c': '' }, { '1': 1 }] for item in items: assert str_to_obj(obj_to_str(item)) == item
def load(self, fp): doc = fp.read() if doc == '': return '' return str_to_obj(doc)
def test_kk(): assert str_to_obj(obj_to_str(['foo', { 'bar': ('baz', None, 1.0, 2) }])) == ['foo', { 'bar': ['baz', None, 1.0, 2] }]
def test_array(): items = ([], [[[]]], list(), [4], [[[True], -2], '3'], [1, [2.54, [3e-10]]], [[''], ""]) for item in items: assert str_to_obj(obj_to_str(item)) == item
def test_object(): classes = (class1, class2, class3, abc) for cls in classes: cls_object = cls() assert obj_to_dict(str_to_obj( obj_to_str(cls))) == obj_to_dict(cls_object)
def test_class(): classes = (class1, class2, class3) attr = [] for cls in classes: assert obj_to_dict(str_to_obj(obj_to_str(cls))) == obj_to_dict(cls) str_to_obj(obj_to_str(class2)).a.f()