Esempio n. 1
0
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'))))
Esempio n. 2
0
    def loads(self, s):
        if s == '':
            return ''
        return str_to_obj(s)


# a = 123
# def f():
#     print(a)
#
# print(JsonParser().dumps(f))
Esempio n. 3
0
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()
Esempio n. 4
0
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
Esempio n. 5
0
 def load(self, fp):
     doc = fp.read()
     if doc == '':
         return ''
     return str_to_obj(doc)
Esempio n. 6
0
def test_kk():
    assert str_to_obj(obj_to_str(['foo', {
        'bar': ('baz', None, 1.0, 2)
    }])) == ['foo', {
        'bar': ['baz', None, 1.0, 2]
    }]
Esempio n. 7
0
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
Esempio n. 8
0
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)
Esempio n. 9
0
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()