Пример #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'))))
Пример #2
0
    def loads(self, s):
        if s == '':
            return ''
        return str_to_obj(s)


# a = 123
# def f():
#     print(a)
#
# print(JsonParser().dumps(f))
Пример #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()
Пример #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
Пример #5
0
 def load(self, fp):
     doc = fp.read()
     if doc == '':
         return ''
     return str_to_obj(doc)
Пример #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]
    }]
Пример #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
Пример #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)
Пример #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()