def test_init_local(self): if os.path.exists("test"): shutil.rmtree("test") os.mkdir("test") os.mkdir("test" + os.path.sep + "test2") file_temp = file("test" + os.path.sep + "test2" + os.path.sep + "test2_a.py", "w") file_temp.write("test2_a") file_temp.close() file_temp = file("test" + os.path.sep + "a.txt", "w") file_temp.write("test_a") file_temp.close() file_temp = file("test" + os.path.sep + "b.py", "w") file_temp.write("test_b") file_temp.close() path.local_path = "." + os.path.sep + "test" sync.init_local() hash_list_actual = serialize.deserialize(path.local_path + os.path.sep + ".sync") hash_list_expect = synchash.FileHashList() hash_list_expect = synchash.fill_sync_hash_list(hash_list_expect) for index in range(hash_algorithm.sync_hash_length): if hash_list_actual.hash_list[index] is not None and hash_list_expect.hash_list[index] is not None: node_actual = hash_list_actual.hash_list[index] node_expect = hash_list_expect.hash_list[index] while node_actual is not None and node_expect is not None: self.assertEqual(node_expect.get_path(), node_actual.get_path()) self.assertEqual(node_expect.get_name_hashcode(), node_actual.get_name_hashcode()) self.assertEqual(node_expect.get_content_hashcode(), node_actual.get_content_hashcode()) self.assertEqual(node_expect.get_next_node(), node_actual.get_next_node()) node_expect = node_expect.get_next_node() node_actual = node_actual.get_next_node()
def test_incrementally_push_darkgel(self): if os.path.exists("local_sync"): shutil.rmtree("local_sync") if os.path.exists("udisk_sync"): shutil.rmtree("udisk_sync") if os.path.exists("remote_sync"): shutil.rmtree("remote_sync") os.mkdir("local_sync") os.mkdir("udisk_sync") os.mkdir("remote_sync") # 本地文件 file_temp = file("local_sync" + os.path.sep + "local_a.py", "w") file_temp.write("local_a") file_temp.close() os.mkdir("local_sync" + os.path.sep + "a") file_temp = file("local_sync" + os.path.sep + "a" + os.path.sep + "local_aa.py", "w") file_temp.write("local_aa") file_temp.close() path.local_path = os.path.abspath(os.curdir) + os.path.sep + "local_sync" path.udisk_path = os.path.abspath(os.curdir) + os.path.sep + "udisk_sync" # 初始化本地同步目录 sync.init_local() # 初始化U盘同步目录 sync.init_udisk() # 将local全量同步到udisk上 sync.fully_push(path.local_path, path.udisk_path) # 将U盘上的全量同步到remote上 path.local_path = os.path.abspath(os.curdir) + os.path.sep + "remote_sync" path.udisk_path = os.path.abspath(os.curdir) + os.path.sep + "udisk_sync" sync.fully_pull(path.udisk_path, path.local_path) # local上新增了文件 file_temp = file("local_sync" + os.path.sep + "local_new.py", "w") file_temp.write("local_new") file_temp.close() # local增量push到udisk path.local_path = os.path.abspath(os.curdir) + os.path.sep + "local_sync" path.udisk_path = os.path.abspath(os.curdir) + os.path.sep + "udisk_sync" sync.incrementally_push() # udisk增量pull到remote path.local_path = os.path.abspath(os.curdir) + os.path.sep + "remote_sync" path.udisk_path = os.path.abspath(os.curdir) + os.path.sep + "udisk_sync" sync.incrementally_pull()
def test_incrementally_pull(self): if os.path.exists("test"): shutil.rmtree("test") if os.path.exists("remote"): shutil.rmtree("remote") os.mkdir("test") os.mkdir("remote") os.mkdir("remote" + os.path.sep + "test") # 本地文件 os.mkdir("test" + os.path.sep + "test_local") file_temp = file("test" + os.path.sep + "test_local" + os.path.sep + "local_a.py", "w") file_temp.write("local_a") file_temp.close() file_temp = file("test" + os.path.sep + "test_local" + os.path.sep + "local_b.py", "w") file_temp.write("local_b") file_temp.close() file_temp = file("test" + os.path.sep + "test_a.py", "w") file_temp.write("test_a") path.local_path = "." + os.path.sep + "test" file_temp.close() # 初始化 sync.init_local() # U盘文件 os.mkdir("remote" + os.path.sep + "test" + os.path.sep + "test_local") os.mkdir("remote" + os.path.sep + "test" + os.path.sep + "test_local2") file_temp = file("remote" + os.path.sep + "test" + os.path.sep + "test_local" + os.path.sep + "local_a2.py", "w") file_temp.write("local_a") file_temp.close() file_temp = file("remote" + os.path.sep + "test" + os.path.sep + "test_local" + os.path.sep + "local_b.py", "w") file_temp.write("local_bbbb") file_temp.close() file_temp = file("remote" + os.path.sep + "test" + os.path.sep + "test_local2" + os.path.sep + "local_b.py", "w") file_temp.write("local_bbbb") file_temp.close() file_temp = file("remote" + os.path.sep + "test" + os.path.sep + "test_a.py", "w") file_temp.write("test_a") file_temp.close() path.local_path = "." + os.path.sep + "remote" + os.path.sep + "test" sync.init_local() path.local_path = "." + os.path.sep + "test" path.udisk_path = "." + os.path.sep + "remote" + os.path.sep + "test" sync.incrementally_pull()
def test_init(self): if os.path.exists("E:" + os.path.sep + "sync_local" + os.path.sep + "test" + os.path.sep + ".sync"): shutil.rmtree("E:" + os.path.sep + "sync_local" + os.path.sep + "test" + os.path.sep + ".sync") if os.path.exists("E:" + os.path.sep + "sync_udisk" + os.path.sep + "test"): shutil.rmtree("E:" + os.path.sep + "sync_udisk" + os.path.sep + "test") if os.path.exists("E:" + os.path.sep + "sync_remote" + os.path.sep + "test"): shutil.rmtree("E:" + os.path.sep + "sync_remote" + os.path.sep + "test") os.mkdir("E:" + os.path.sep + "sync_udisk" + os.path.sep + "test") os.mkdir("E:" + os.path.sep + "sync_remote" + os.path.sep + "test") path.local_path = "E:" + os.path.sep + "sync_local" + os.path.sep + "test" path.udisk_path = "E:" + os.path.sep + "sync_udisk" + os.path.sep + "test" sync.init_local() sync.init_udisk() sync.fully_push(path.local_path, path.udisk_path) path.local_path = "E:" + os.path.sep + "sync_remote" + os.path.sep + "test" sync.fully_pull(path.udisk_path, path.local_path)
def test_run_time(): test_local_path = path.test_local_path_root + os.path.sep + path.test_relative_path test_udisk_path = path.test_udisk_path_root + os.path.sep + path.test_relative_path test_remote_path = path.test_remote_path_root + os.path.sep + path.test_relative_path if os.path.exists(test_local_path + os.path.sep + ".sync"): shutil.rmtree(test_local_path + os.path.sep + ".sync") if os.path.exists(test_local_path + os.path.sep + "test"): shutil.rmtree(test_local_path + os.path.sep + "test") if os.path.exists(test_udisk_path): shutil.rmtree(test_udisk_path) if os.path.exists(test_remote_path): shutil.rmtree(test_remote_path) os.mkdir(test_udisk_path) os.mkdir(test_remote_path) # 1.本地新增测试需要的文件夹、文件 os.mkdir(test_local_path + os.path.sep + "test") os.mkdir(test_local_path + os.path.sep + "test" + os.path.sep + "test2") os.mkdir(test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3") file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "update_local_test_1.txt", "w") file_temp.write("update_local_test_1.txt") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "delete_local_test_1.txt", "w") file_temp.write("delete_local_test_1.txt") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "update_local_test_2.txt", "w") file_temp.write("update_local_test_2.txt") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "delete_local_test_2.txt", "w") file_temp.write("delete_local_test_2.txt") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3" + os.path.sep + "update_local_test_3.txt", "w") file_temp.write("update_local_test_3.txt") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3" + os.path.sep + "delete_local_test_3.txt", "w") file_temp.write("delete_local_test_3.txt") file_temp.close() path.local_path = test_local_path path.udisk_path = test_udisk_path # 2.初始化 sync.init_local() sync.init_udisk() # 3.1.全量push sync.fully_push(path.local_path, path.udisk_path) # 3.2.全量pull path.local_path = test_remote_path sync.fully_pull(path.udisk_path, path.local_path) # 4.本地新增文件 file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "add_local_test_1.txt", "w") file_temp.write("add_local_test_1.txt") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "add_local_test_2.txt", "w") file_temp.write("add_local_test_2.txt") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3" + os.path.sep + "add_local_test_3.txt", "w") file_temp.write("add_local_test_3.txt") file_temp.close() # 5.本地修改文件 file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "update_local_test_1.txt", "w") file_temp.write("update_local_test_1.txt local_update") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "update_local_test_2.txt", "w") file_temp.write("update_local_test_2.txt local_update") file_temp.close() file_temp = file( test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3" + os.path.sep + "update_local_test_3.txt", "w") file_temp.write("update_local_test_3.txt local_update") file_temp.close() # 6.本地删除文件 os.remove(test_local_path + os.path.sep + "test" + os.path.sep + "delete_local_test_1.txt") os.remove(test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "delete_local_test_2.txt") os.remove(test_local_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3" + os.path.sep + "delete_local_test_3.txt") # 7.远程新增文件 file_temp = file( test_remote_path + os.path.sep + "test" + os.path.sep + "add_remote_test_1.txt", "w") file_temp.write("add_remote_test_1.txt") file_temp.close() file_temp = file( test_remote_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "add_remote_test_2.txt", "w") file_temp.write("add_remote_test_2.txt") file_temp.close() file_temp = file( test_remote_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3" + os.path.sep + "add_remote_test_3.txt", "w") file_temp.write("add_remote_test_3.txt") file_temp.close() # 8.远程修改文件 file_temp = file( test_remote_path + os.path.sep + "test" + os.path.sep + "update_local_test_1.txt", "w") file_temp.write("update_local_test_1.txt remote_update") file_temp.close() file_temp = file( test_remote_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "update_local_test_2.txt", "w") file_temp.write("update_local_test_2.txt remote_update") file_temp.close() file_temp = file( test_remote_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3" + os.path.sep + "update_local_test_3.txt", "w") file_temp.write("update_local_test_3.txt remote_update") file_temp.close() # 9.远程删除文件 os.remove(test_remote_path + os.path.sep + "test" + os.path.sep + "delete_local_test_1.txt") os.remove(test_remote_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "delete_local_test_2.txt") os.remove(test_remote_path + os.path.sep + "test" + os.path.sep + "test2" + os.path.sep + "test3" + os.path.sep + "delete_local_test_3.txt") # 10.本地增量push、远程增量pull path.local_path = test_local_path path.udisk_path = test_udisk_path sync.incrementally_push() path.local_path = test_remote_path sync.incrementally_pull()