コード例 #1
0
 def testAddModDelDiff(self):
     a = {'some': ['dict'],
          'with': 'some',
          'key':{'s': 'that',
                 'are': ['nes', 'ted']}}
     b = dict(a)
     b['extra'] = 'cool stuff'
     b['with'] = 'new stuff'
     del b['some']
     ddo_a = DictDiff.create(a, b)
     add_str = ddo_a.additions_expr(par='obj')
     self.assertEqual(add_str, ["obj['extra'] = 'cool stuff'"])
     self.assertEqual(["del obj['some']"], ddo_a.deletions_expr(par='obj'))
     self.assertEqual(["obj['with'] = 'new stuff'"], ddo_a.modification_expr(par='obj'))
     ddo_d = DictDiff.create(b, a)
     self.assertEqual(ddo_d.deletions_expr(par='obj'), ["del obj['extra']"])
     self.assertEqual(["obj['some'] = ['dict']"], ddo_d.additions_expr(par='obj'))
     self.assertEqual(["obj['with'] = 'some'"], ddo_d.modification_expr(par='obj'))
     c_a = copy.deepcopy(a)
     self.assertEqual(a, c_a)
     c_b = copy.deepcopy(b)
     self.assertEqual(b, c_b)
     ddo_a.patch(c_a)
     self.assertEqual(b, c_a)
     ddo_d.patch(c_b)
     self.assertEqual(a, c_b)
コード例 #2
0
 def testSecondLevelAddModDelDiff(self):
     a = {'some': ['dict'],
          'with': 'some',
          'key':{'s': 'that',
                 'are': ['nes', 'ted']}}
     b = copy.deepcopy(a)
     b['key']['a'] = 'cool stuff'
     b['key']['s'] = 'this'
     del b['key']['are']
     ddo_a = DictDiff.create(a, b)
     self.assertEqual(ddo_a.additions_expr(par='obj'), [])
     self.assertEqual([], ddo_a.deletions_expr(par='obj'))
     self.assertEqual(["obj['key']['a'] = 'cool stuff'",
                       "del obj['key']['are']",
                       "obj['key']['s'] = 'this'",
                      ], ddo_a.modification_expr(par='obj'))
     ddo_d = DictDiff.create(b, a)
     self.assertEqual(ddo_d.deletions_expr(par='obj'), [])
     self.assertEqual([], ddo_d.additions_expr(par='obj'))
     self.assertEqual(["obj['key']['are'] = ['nes', 'ted']",
                       "del obj['key']['a']",
                       "obj['key']['s'] = 'that'",
                      ], ddo_d.modification_expr(par='obj'))
     c_a = copy.deepcopy(a)
     self.assertEqual(a, c_a)
     c_b = copy.deepcopy(b)
     self.assertEqual(b, c_b)
     ddo_a.patch(c_a)
     self.assertEqual(b, c_a)
     ddo_d.patch(c_b)
     self.assertEqual(a, c_b)
コード例 #3
0
ファイル: test_struct_diff.py プロジェクト: mtholder/peyotl
 def testAddModDelDiff(self):
     a = {'some': ['dict'],
          'with': 'some',
          'key': {'s': 'that',
                  'are': ['nes', 'ted']}}
     b = dict(a)
     b['extra'] = 'cool stuff'
     b['with'] = 'new stuff'
     del b['some']
     ddo_a = DictDiff.create(a, b)
     add_str = ddo_a.additions_expr(par='obj')
     self.assertEqual(add_str, ["obj['extra'] = 'cool stuff'"])
     self.assertEqual(["del obj['some']"], ddo_a.deletions_expr(par='obj'))
     self.assertEqual(["obj['with'] = 'new stuff'"], ddo_a.modification_expr(par='obj'))
     ddo_d = DictDiff.create(b, a)
     self.assertEqual(ddo_d.deletions_expr(par='obj'), ["del obj['extra']"])
     self.assertEqual(["obj['some'] = ['dict']"], ddo_d.additions_expr(par='obj'))
     self.assertEqual(["obj['with'] = 'some'"], ddo_d.modification_expr(par='obj'))
     c_a = copy.deepcopy(a)
     self.assertEqual(a, c_a)
     c_b = copy.deepcopy(b)
     self.assertEqual(b, c_b)
     ddo_a.patch(c_a)
     self.assertEqual(b, c_a)
     ddo_d.patch(c_b)
     self.assertEqual(a, c_b)
コード例 #4
0
 def testListAddModDelDiff(self):
     a = {'some': ['dict', 'bool'],
          'with': 'some',
          'key':{'s': 'that',
                 'are': ['nes', 'ted']}}
     b = copy.deepcopy(a)
     b['some'][0] = 'list'
     b['some'].append('last')
     ddo_a = DictDiff.create(a, b)
     self.assertEqual(ddo_a.additions_expr(par='obj'), [])
     self.assertEqual([], ddo_a.deletions_expr(par='obj'))
     self.assertEqual(["obj['some'][0] = 'list'",
                       "obj['some'].insert(2, 'last')"
                      ], ddo_a.modification_expr(par='obj'))
     ddo_d = DictDiff.create(b, a)
     self.assertEqual(ddo_d.deletions_expr(par='obj'), [])
     self.assertEqual([], ddo_d.additions_expr(par='obj'))
     self.assertEqual(["obj['some'][0] = 'dict'",
                       "obj['some'].pop(2)"
                      ], ddo_d.modification_expr(par='obj'))
     c_a = copy.deepcopy(a)
     self.assertEqual(a, c_a)
     c_b = copy.deepcopy(b)
     self.assertEqual(b, c_b)
     ddo_a.patch(c_a)
     self.assertEqual(b, c_a)
     ddo_d.patch(c_b)
     self.assertEqual(a, c_b)
コード例 #5
0
ファイル: test_struct_diff.py プロジェクト: mtholder/peyotl
 def testSecondLevelAddModDelDiff(self):
     a = {'some': ['dict'],
          'with': 'some',
          'key': {'s': 'that',
                  'are': ['nes', 'ted']}}
     b = copy.deepcopy(a)
     b['key']['a'] = 'cool stuff'
     b['key']['s'] = 'this'
     del b['key']['are']
     ddo_a = DictDiff.create(a, b)
     self.assertEqual(ddo_a.additions_expr(par='obj'), [])
     self.assertEqual([], ddo_a.deletions_expr(par='obj'))
     self.assertEqual(["obj['key']['a'] = 'cool stuff'",
                       "del obj['key']['are']",
                       "obj['key']['s'] = 'this'",
                       ], ddo_a.modification_expr(par='obj'))
     ddo_d = DictDiff.create(b, a)
     self.assertEqual(ddo_d.deletions_expr(par='obj'), [])
     self.assertEqual([], ddo_d.additions_expr(par='obj'))
     self.assertEqual(["obj['key']['are'] = ['nes', 'ted']",
                       "del obj['key']['a']",
                       "obj['key']['s'] = 'that'",
                       ], ddo_d.modification_expr(par='obj'))
     c_a = copy.deepcopy(a)
     self.assertEqual(a, c_a)
     c_b = copy.deepcopy(b)
     self.assertEqual(b, c_b)
     ddo_a.patch(c_a)
     self.assertEqual(b, c_a)
     ddo_d.patch(c_b)
     self.assertEqual(a, c_b)
コード例 #6
0
ファイル: test_struct_diff.py プロジェクト: mtholder/peyotl
 def testListAddModDelDiff(self):
     a = {'some': ['dict', 'bool'],
          'with': 'some',
          'key': {'s': 'that',
                  'are': ['nes', 'ted']}}
     b = copy.deepcopy(a)
     b['some'][0] = 'list'
     b['some'].append('last')
     ddo_a = DictDiff.create(a, b)
     self.assertEqual(ddo_a.additions_expr(par='obj'), [])
     self.assertEqual([], ddo_a.deletions_expr(par='obj'))
     self.assertEqual(["obj['some'][0] = 'list'",
                       "obj['some'].insert(2, 'last')"
                       ], ddo_a.modification_expr(par='obj'))
     ddo_d = DictDiff.create(b, a)
     self.assertEqual(ddo_d.deletions_expr(par='obj'), [])
     self.assertEqual([], ddo_d.additions_expr(par='obj'))
     self.assertEqual(["obj['some'][0] = 'dict'",
                       "obj['some'].pop(2)"
                       ], ddo_d.modification_expr(par='obj'))
     c_a = copy.deepcopy(a)
     self.assertEqual(a, c_a)
     c_b = copy.deepcopy(b)
     self.assertEqual(b, c_b)
     ddo_a.patch(c_a)
     self.assertEqual(b, c_a)
     ddo_d.patch(c_b)
     self.assertEqual(a, c_b)
コード例 #7
0
 def testEqualDiff(self):
     a = {'some': ['dict'],
          'with': 'some',
          'key':{'s': 'that',
                 'are': ['nes', 'ted']}}
     b = dict(a)
     self.assertEqual(None, DictDiff.create(a, b))
コード例 #8
0
ファイル: test_struct_diff.py プロジェクト: mtholder/peyotl
 def testEqualDiff(self):
     a = {'some': ['dict'],
          'with': 'some',
          'key': {'s': 'that',
                  'are': ['nes', 'ted']}}
     b = dict(a)
     self.assertEqual(None, DictDiff.create(a, b))
コード例 #9
0
def equal_blob_check(unit_test, diff_file_tag, first, second):
    from peyotl.test.support import pathmap
    if first != second:
        dd = DictDiff.create(first, second)
        ofn = pathmap.next_unique_scratch_filepath(diff_file_tag + '.obtained_rt')
        efn = pathmap.next_unique_scratch_filepath(diff_file_tag + '.expected_rt')
        write_as_json(first, ofn)
        write_as_json(second, efn)
        er = dd.edits_expr()
        _LOG.info('\ndict diff: {d}'.format(d='\n'.join(er)))
        if first != second:
            m_fmt = "TreeBase conversion failed see files {o} and {e}"
            m = m_fmt.format(o=ofn, e=efn)
            unit_test.assertEqual("", m)
コード例 #10
0
    rc = 1
if rc == 1:
    warn("tree added, but not not showing up in trees_in_synth response.")

# Remove our addition to return the testing corpus to its previous state.
try:
    SUBMIT_URI = DOMAIN + '/v4/exclude_tree_in_synth'
    r = test_http_json_method(SUBMIT_URI,
                              'POST',
                              data=change_synth_data,
                              expected_status=200,
                              return_bool_data=True)
    assert r[0]
except:
    msg = "ERROR: study_id, tree_id pair ({}, {}) was added to the default synth collection, but removal failed!"
    msg = msg.format(study_id, tree_id)
    sys.stderr.write(msg)
    sys.exit(1)

restored_study_to_tree_list = fetch_current_synth_study2tree_mapping()

if tree_id in restored_study_to_tree_list.get(study_id, []):
    warn("Tree excluded from synth, but still showing up in trees_in_synth response")
    rc = 1
elif restored_study_to_tree_list != orig_study_to_tree_list:
    from peyotl.struct_diff import  DictDiff
    dd = DictDiff.create(orig_study_to_tree_list, restored_study_to_tree_list)
    msg = "Trees showing up in trees_in_synth response changed after restore:\n{}".format(dd.__dict__)
    warn(msg)
sys.exit(rc)
コード例 #11
0
# Remove our addition to return the testing corpus to its previous state.
try:
    SUBMIT_URI = DOMAIN + '/v4/exclude_tree_in_synth'
    r = test_http_json_method(SUBMIT_URI,
                              'POST',
                              data=change_synth_data,
                              expected_status=200,
                              return_bool_data=True)
    assert r[0]
except:
    msg = "ERROR: study_id, tree_id pair ({}, {}) was added to the default synth collection, but removal failed!"
    msg = msg.format(study_id, tree_id)
    sys.stderr.write(msg)
    sys.exit(1)

restored_study_to_tree_list = fetch_current_synth_study2tree_mapping()

if tree_id in restored_study_to_tree_list.get(study_id, []):
    warn(
        "Tree excluded from synth, but still showing up in trees_in_synth response"
    )
    rc = 1
elif restored_study_to_tree_list != orig_study_to_tree_list:
    from peyotl.struct_diff import DictDiff
    dd = DictDiff.create(orig_study_to_tree_list, restored_study_to_tree_list)
    msg = "Trees showing up in trees_in_synth response changed after restore:\n{}".format(
        dd.__dict__)
    warn(msg)
sys.exit(rc)