def test_bug_accent(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") data = os.path.abspath(os.path.dirname(__file__)) fold = os.path.join(data, "data", "bug") assert os.path.exists(fold) to = os.path.join(data, "temp_bug") if os.path.exists(to): remove_folder(to) os.mkdir(to) assert os.path.exists(to) synchronize_folder(fold, to, hash_size=0, repo1=False, repo2=False, size_different=True, no_deletion=False, filter=None, filter_copy=None, avoid_copy=False, operations=None, file_date=None, log1=False) if sys.version_info[0] == 2: return assert os.path.exists( os.path.join( to, "bugged", "Présentation.pdf.txt"))
def test_synchro2(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") fold = os.path.abspath(os.path.split(__file__)[0]) data = os.path.join(fold, "data") seco = os.path.join(fold, "data", "temp_seco") troi = os.path.join(fold, "temp_troi") sec2 = os.path.join(troi, "temp_seco") stay = os.path.join(sec2, "notfile.txt") nocp = os.path.join(seco, "file.txt") def filter_copy(file): return "temp_seco" not in file fLOG(filter_copy(stay), stay) assert not filter_copy(stay) if os.path.exists(troi): remove_folder(troi) if not os.path.exists(seco): os.mkdir(seco) if not os.path.exists(troi): os.mkdir(troi) if not os.path.exists(sec2): os.mkdir(sec2) with open(nocp, "w") as f: f.write("should not be here") with open(stay, "w") as f: f.write("should stay") if sys.version_info[0] == 2: return synchronize_folder(data, troi, hash_size=0, repo1=True, filter_copy=filter_copy) assert os.path.exists(os.path.join(troi, "sub", "filetwo.txt")) assert os.path.exists(stay) assert not os.path.exists(stay.replace("notfile.txt", "file.txt"))
def test_remove_folder(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") thispath = os.path.abspath(os.path.split(__file__)[0]) cache = os.path.join(thispath, "temp_remove") if not os.path.exists(cache): os.mkdir(cache) remone = os.path.join(cache, os.path.split(__file__)[-1]) fLOG("existing file", remone) if os.path.exists(remone): os.remove(remone) try: import pysvn as skip__ except ImportError: return action = foldermod.synchronize_folder( thispath, cache, hash_size=0, repo1=True) ac = foldermod.remove_folder(cache, True) assert len(ac) > 0 for a in ac: assert not os.path.exists(a[0]) act = [_[1].name for _ in action] ac = [_[0].split("\\temp_remove\\")[-1] for _ in ac] for a in act: if a not in ac: fLOG("a", a) fLOG(ac[0], ac) raise Exception("a not in ac a=%s, ac=%s" % (a, str(ac))) assert a in ac
def test_synchro_hash(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if sys.version_info[0] == 2: return fold = os.path.abspath(os.path.split(__file__)[0]) data = os.path.join(fold, "data") seco = os.path.join(fold, "data", "temp_seco2") troi = os.path.join(fold, "temp_troi2") sec2 = os.path.join(troi, "temp_seco2") temp = os.path.join(fold, "temp_date") if not os.path.exists(temp): os.mkdir(temp) stay = os.path.join(sec2, "notfile.txt") nocp = os.path.join(seco, "file.txt") def filter_copy(file): return "temp_seco" not in file fLOG(filter_copy(stay), stay) assert not filter_copy(stay) if os.path.exists(troi): remove_folder(troi) if not os.path.exists(seco): os.mkdir(seco) if not os.path.exists(troi): os.mkdir(troi) if not os.path.exists(sec2): os.mkdir(sec2) with open(nocp, "w") as f: f.write("should not be here") with open(stay, "w") as f: f.write("should stay") file_date = os.path.join(temp, "file_date.txt") if os.path.exists(file_date): os.remove(file_date) a = synchronize_folder( data, troi, hash_size=0, repo1=True, filter_copy=filter_copy, file_date=file_date, log1=True ) assert os.path.exists(file_date) assert os.path.exists(os.path.join(troi, "sub", "filetwo.txt")) assert os.path.exists(stay) assert not os.path.exists(stay.replace("notfile.txt", "file.txt")) b = synchronize_folder(data, troi, hash_size=0, repo1=True, filter_copy=filter_copy, file_date=file_date) if len(a) not in [2, 3]: raise Exception("2 or 3 expected: " + "\n".join([str(_) for _ in a])) assert a[0][0] == ">+" == a[1][0] assert len(b) == 0 troi2 = os.path.join(fold, "temp_troi3") if not os.path.exists(troi2): os.mkdir(troi2) file_date = os.path.join(temp, "file_date_rem.txt") if os.path.exists(file_date): os.remove(file_date) c = synchronize_folder(troi, troi2, hash_size=0, repo1=False, filter_copy=filter_copy, file_date=file_date) onefile = os.path.join(troi, "onefile.txt") os.remove(onefile) with open(file_date, "r") as f: all_b = f.readlines() c = synchronize_folder(troi, troi2, hash_size=0, repo1=False, filter_copy=filter_copy, file_date=file_date) with open(file_date, "r") as f: all_c = f.readlines() fLOG(c) assert len(c) > 0 onefile2 = os.path.join(troi2, "onefile.txt") assert not os.path.exists(onefile2) assert len(all_b) == len(all_c) + 1 if __name__ != "__main__": remove_folder(troi) remove_folder(troi2)