예제 #1
0
def test(a, b):
    print("x" * 80)
    #for i, x in enumerate(a): print("%2d" % i,sorted(x.items()))
    #print("")
    #for i, x in enumerate(b): print("%2d" % i,sorted(x.items()))
    d = diff(a, b)
    #print("")
    #for x in d: print(x)
    #print("")
    p = patch(a, d)
    assert p is not None
    tmp = diff(p, b)
    assert (tmp == None) or (len(tmp) == 0)
    if isinstance(tmp, list) and (len(tmp) != 0):
        print("patch(a, diff(a,b))!=b")
        for c in tmp:
            print(c)
    p = revert(b, d)
    assert p is not None
    tmp = diff(p, a)
    if len(tmp) != 0:
        print("_" * 120)
        print("revert(b, diff(a,b))!=a")
        print("a2", p)
        print("diff")
        for x in sorted(tmp, key=lambda x: len(x['path'])):
            print(x)
    assert (tmp == [])
예제 #2
0
def test(a, b):
    print("x" * 80)
    print("a", a)
    print("")
    print("b", b)
    print("")
    print("_" * 120)
    d = diff(a, b)
    print("")
    for x in sorted(d, key=lambda x: len(x['path'])):
        print(x)
    print("")
    p = patch(a, d)
    assert p is not None
    tmp = diff(p, b)
    if len(tmp) != 0:
        print("_" * 120)
        print("patch(a, diff(a,b))!=b")
        print("b2", p)
        print("diff")
        for x in sorted(tmp, key=lambda x: len(x['path'])):
            print(x)
    assert (tmp == [])

    p = revert(b, d)
    assert p is not None
    tmp = diff(p, a)
    if len(tmp) != 0:
        print("_" * 120)
        print("revert(b, diff(a,b))!=a")
        print("a2", p)
        print("diff")
        for x in sorted(tmp, key=lambda x: len(x['path'])):
            print(x)
    assert (tmp == [])
예제 #3
0
파일: lists1.py 프로젝트: stef/objchanges
def test(a, b):
    print("x" * 80)
    #for i, x in enumerate(a): print("%2d" % i,sorted(x.items()))
    #print("")
    #for i, x in enumerate(b): print("%2d" % i,sorted(x.items()))
    #print("")
    #print("_"*120)
    d = diff(a, b)
    #print("")
    #for x in sorted(d,key=lambda x: len(x['path'])): print(x)
    #print("")
    p = patch(a, d)
    assert p is not None
    tmp = diff(p, b)
    if len(tmp) != 0:
        print("_" * 120)
        print("")
        print("patch(a, diff(a,b))!=b")
        print("b2")
        for i, x in enumerate(p):
            print("%2d" % i, sorted(x.items()))
        print("b")
        for i, x in enumerate(b):
            print("%2d" % i, sorted(x.items()))
        print("diff")
        for x in sorted(tmp, key=lambda x: len(x['path'])):
            print(x)
    assert (tmp == [])

    p = revert(b, d)
    assert p is not None
    tmp = diff(p, a)
    if len(tmp) != 0:
        print("_" * 120)
        print("revert(b, diff(a,b))!=a")
        print("a2", p)
        print("diff")
        for x in sorted(tmp, key=lambda x: len(x['path'])):
            print(x)
    assert (tmp == [])
예제 #4
0
old = {
    "procedure": {
        "subject": [
            "3.50.01.05 Research specific areas",
            "3.50.08 New technologies, biotechnology",
            "3.60.04 Nuclear energy, industry and safety",
            "8.70 Budget of the Union", "8.70.02 Financial regulations",
            "3.50.20 Scientific and technological cooperation and agreements"
        ]
    }
}
new = {
    "procedure": {
        "subject": [
            "3.50.20 Scientific and technological cooperation and agreements",
            "3.60.15 Cooperation and agreements for energy",
            "8.70 Budget of the Union"
        ]
    }
}
test(old, new)


def dump(a, b):
    for i, j in zip(a['procedure']['subject'], b['procedure']['subject']):
        print("%80s %80s" % (i, j))


dump(new, patch(old, diff(old, new)))
예제 #5
0
            if isinstance(item, dict):
                if not item: continue
                k = choice(tuple(item.keys()))
                del item[k]
                done = True
            elif isinstance(item, list):
                if len(item) == 0: continue
                i = randrange(len(item))
                del item[i]
                done = True
    return obj


old = {}
i = 0
while True:
    print("\r%d" % i, end='')
    #print(old)
    new = mutate(old)
    try:
        d = diff(old, new)
        assert diff(new, patch(old, d)) in [None, []]
    except:
        print("\nfail:\nold {!r}\nnew {!r}\ndiff {!r}".format(old, new, d))
        raise
        traceback.print_exc()
    i += 1
    if '-v' in sys.argv and i % 10000 == 0:
        print("\nold: {!r}\nnew {!r}".format(old, new))
    old = new
예제 #6
0
            ('1', 4, '2'), ('5', 0), ('1', 3), ('c', ), ('5', 1), ('5', ),
            ('1 ', 3, 'c'), ('1', 2), ()}
new = {
    'c': {},
    '1': [[42], [{}, {}, []], {}, {
        '2': 23,
        'c': 'qvA'
    }, 42],
    '2': {
        '5': {}
    },
    '5': ['3yd', []],
    '23': '8Vy',
    'a': 42
}
newpaths = {('2', '5'), ('2', '3'), ('1', 1), ('1', ), ('2', ), ('1', 0, 1),
            ('1', 0, 1, 0), ('1', 0), ('1', 0, 2), ('1', 4), ('a', ),
            ('1', 4, '2'), ('5', 0), ('1', 3), ('c', ), ('5', 1), ('5', ),
            ('1 ', 3, 'c'), ('1', 2), ()}
#diff=[{'type': 'added', 'data': {}, 'path': ['2', '5']}, {'type': 'added', 'data': [], 'path': ['5', 1]}, {'type': 'deleted', 'data': {}, 'path': ['5', 1]}, {'type': 'changed', 'data': ('Oqu', '8Vy'), 'path': ['23']}, {'type': 'deleted', 'data': [{}, {}], 'path': ['1', 0]}, {'type': 'added', 'data': 5, 'path': ['1', 1]}, {'type': 'added', 'data': [], 'path': ['1', 1, 2]}, {'type': 'added', 'data': [42], 'path': ['1', 0]}, {'type': 'added', 'data': {'2': 23, 'c': 'qvA'}, 'path': ['1', 3]}, {'type': 'deleted', 'data': 5, 'path': ['1', 1]}, {'type': 'deleted', 'data': [], 'path': ['1', 4]}, {'type': 'deleted', 'data': [], 'path': ['c', 'a']}, {'type': 'changed', 'data': ('cRL', 42), 'path': ['a']}]
# Traceback (most recent call last):
#   File "./fuzz.py", line 118, in <module>
#     assert diff(new, patch(old, d)) in [None, []]
#   File "/home/s/tasks/objchanges/objchanges.py", line 197, in patch
#     obj[change['path'][-1]]=deepcopy(change['data'])
# TypeError: 'int' object does not support item assignment

d = diff(old, new)
new2 = patch(old, d)
assert diff(new, new2) in [None, []]