def test_diffcache_comparison(): initial_dict = {"filename": "would be a diff object"} initial_dirflags = {"filename": True} cache1 = diff.DiffCache(initialdict=initial_dict, initialdirflags=initial_dirflags) cache2 = diff.DiffCache(initialdict=initial_dict, initialdirflags=initial_dirflags) assert cache1 == cache2
def test_diffcache_remove_diff_2(): # test the resulting dictionary of .remove_diff() initial_diff = {"filename": "would be a diff object"} initial_dirflags = {"filename": False} probe_object = diff.DiffCache(initialdict=initial_diff, initialdirflags=initial_dirflags) probe_object.remove_diff("filename") assert probe_object.diffdict == {} assert probe_object.dirflags == {}
def test_diffcache_remove_diff_1(): # test the return of .remove_diff() initial_diff = {"filename": "would be a diff object"} initial_dirflags = {"filename": False} probe_object = diff.DiffCache(initialdict=initial_diff, initialdirflags=initial_dirflags) removed_diff, removed_flags = probe_object.remove_diff("filename") assert removed_diff == "would be a diff object" assert removed_flags is False
def test_collect1(self): storage = abspath("./tests/testdata/full_storage") archive = abspath("./tests/testdata/full_archive") # create main DiffCache object and add doc1.txt record expected_cache = diff.DiffCache() expected_cache.add_diff(abspath(storage + "/doc1.txt"), diff.Diff("*", getmtime( abspath(storage + "/doc1.txt") )), False) # create DiffCache for subdir/subdir subsub_initialdict = {abspath(storage + "/subdir/subdir/doc4.txt"): diff.Diff("*", getmtime( abspath(storage + "/subdir/subdir/doc4.txt") ))} subsub_dirflags = {abspath(storage + "/subdir/subdir/doc4.txt"): False} subsub_diffcache = diff.DiffCache(initialdict=subsub_initialdict, initialdirflags=subsub_dirflags) # create DiffCache for subdir sub_initialdict = {abspath(storage + "/subdir/doc2.txt"): diff.Diff("*", getmtime( abspath(storage + "/subdir/doc2.txt"))), abspath(storage + "/subdir/doc3.txt"): diff.Diff("*", getmtime( abspath(storage + "/subdir/doc3.txt"))), abspath(storage + "/subdir/subdir"): subsub_diffcache} sub_initialdirflags = {abspath(storage + "/subdir/doc2.txt"): False, abspath(storage + "/subdir/doc3.txt"): False, abspath(storage + "/subdir/subdir"): True} sub_diffcache = diff.DiffCache(initialdict=sub_initialdict, initialdirflags=sub_initialdirflags) # add sub_diffcache to expected_cache expected_cache.add_diff(abspath(storage + "/subdir"), sub_diffcache, True) diff_cache = diff.collect(storage, archive, DIFF_DATE) assert diff_cache == expected_cache
def test_diffcache_add_diff(): initial_dict = {"filename": "would be a diff object"} initial_dirflags = {"filename": False} additional_diff = ["filename2", "would be a diff object2"] expected_diff = {"filename": "would be a diff object", "filename2": "would be a diff object2"} expected_dirflags = {"filename": False, "filename2": True} probe_object = diff.DiffCache(initialdict=initial_dict, initialdirflags=initial_dirflags) probe_object.add_diff(additional_diff[0], additional_diff[1], True) assert probe_object.diffdict == expected_diff assert probe_object.dirflags == expected_dirflags
def test_diffcache_constructor_empty(): probe_object = diff.DiffCache() assert probe_object.diffdict == {} assert probe_object.dirflags == {}
def test_diffcache_constructor_initialdirflags(): initial_dirflags = {"filename": True} probe_object = diff.DiffCache(initialdirflags=initial_dirflags) assert probe_object.dirflags == initial_dirflags
def test_diffcache_constructor_initialdict(): initial_dict = {"filename": "would be a diff object"} probe_object = diff.DiffCache(initialdict=initial_dict) assert probe_object.diffdict == initial_dict