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) assert os.path.exists( os.path.join(to, "bugged", "Présentation.pdf.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_synchronize_nosvn(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") thispath = os.path.abspath(os.path.split(__file__)[0]) if len(thispath) == 0: thispath = "./../ut_loghelper" cache = os.path.join(thispath, "temp_synchro_nosvn") if not os.path.exists(cache): os.mkdir(cache) remone = os.path.join(cache, "test_log.py") fLOG("existing file", remone) if os.path.exists(remone): os.remove(remone) action = foldermod.synchronize_folder(os.path.join( thispath, "..", "ut_loghelper"), cache, hash_size=0, repo1=False, filter=lambda v: "temp" not in v) assert os.path.exists(cache) assert len(os.listdir(cache)) > 0 assert os.path.exists(os.path.join(cache, "data")) assert len(os.listdir(os.path.join(cache, "data"))) > 0 assert len(action) > 0
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") 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_synchronize(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") thispath = os.path.abspath(os.path.split(__file__)[0]) cache = os.path.join(thispath, "temp_synchro") if not os.path.exists(cache): os.mkdir(cache) remone = os.path.join(cache, "test_log.py") fLOG("existing file", remone) if os.path.exists(remone): os.remove(remone) try: import pysvn as skip_ except ImportError: return all = [] action = foldermod.synchronize_folder( os.path.join(thispath, "..", "ut_loghelper"), cache, hash_size=0, repo1=True, operations=lambda a, b, c: all.append(a)) assert len(all) > 0 action = foldermod.synchronize_folder(os.path.join( thispath, "..", "ut_loghelper"), cache, hash_size=0, repo1=True) assert os.path.exists(cache) assert len(os.listdir(cache)) > 0 assert os.path.exists(os.path.join(cache, "data")) assert len(os.listdir(os.path.join(cache, "data"))) > 0 assert len(action) > 0
def test_synchro_hash(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_seco2") troi = get_temp_folder(__file__, "temp_troi2") sec2 = get_temp_folder(__file__, "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) self.assertExists(file_date) self.assertExists(os.path.join(troi, "sub", "filetwo.txt")) self.assertExists(stay) self.assertNotExists(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 [6, 7, 8, 9]: raise Exception("2 or 3 expected but got {}:\n{}".format( len(a), "\n".join([str(_) for _ in a]))) self.assertEqual(a[0][0], ">+") self.assertEqual(a[0][0], a[1][0]) self.assertEqual(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)
def test_full_documentation(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_doc") file = os.path.join(temp, "..", "..", "..") fLOG(os.path.normpath(os.path.abspath(file))) self.assertExists(os.path.exists(file)) sysp = os.path.normpath(os.path.join( file, "_doc", "sphinxdoc", "source")) self.assertExists(os.path.exists(sysp)) fLOG('sysp=', sysp) sys.path.insert(0, sysp) del sys.path[0] synchronize_folder(sysp, temp, filter=lambda c: "__pycache__" not in c and "pyquickhelper" not in c) shutil.copy(os.path.join(file, "README.rst"), temp) # copy the files project_var_name = "pyquickhelper" issues = [] store_obj = {} utils_sphinx_doc.prepare_file_for_sphinx_help_generation( store_obj, file, temp, silent=True, subfolders=[("src/" + project_var_name, project_var_name), ], rootrep=("ut_helpgen.temp_doc.%s." % (project_var_name,), ""), optional_dirs=[], mapped_function=[(".*[.]tohelp$", None)], issues=issues, module_name=project_var_name) fLOG("end of prepare_file_for_sphinx_help_generation") files = [ #os.path.join(temp, "index_ext-tohelp.rst"), os.path.join(temp, "index_function.rst"), os.path.join(temp, "glossary.rst"), os.path.join(temp, "index_class.rst"), os.path.join(temp, "index_module.rst"), os.path.join(temp, "index_property.rst"), os.path.join(temp, "index_method.rst"), os.path.join(temp, "all_report.rst"), ] for f in files: if not os.path.exists(f): raise FileNotFoundError(f + "\nabspath: " + os.path.abspath(f)) if "report" in f: with open(f, "r", encoding="utf8") as ff: content = ff.read() self.assertIn(".py", content) if os.path.exists(os.path.join(temp, "all_FAQ.rst")): with open(os.path.join(temp, "all_FAQ.rst"), "r") as f: contentf = f.read() self.assertIn("How to activate the logs?", contentf) self.assertNotIn("_le-", contentf) self.assertNotIn("_lf-", contentf) self.assertNotIn("__!LI!NE!__", contentf) with open(files[0], "r", encoding="utf8") as f: f.read() for f in ["fix_incomplete_references"]: func = [ _ for _ in issues if _[0] == f and "utils_sphinx_doc.py" not in _[1]] if len(func) > 0: fLOG(func) mes = "\n".join([_[1] for _ in func]) stk = [] for k, v in store_obj.items(): if isinstance(v, list): for o in v: stk.append("storedl %s=%s " % (k, o.rst_link())) else: stk.append("stored %s=%s " % (k, v.rst_link())) mes += "\nstored:\n" + "\n".join(sorted(stk)) name = func[0][1].split("'")[-2] with open(name, "r", encoding="utf-8") as f: content = f.read() mes += "\n-------------FILE------------\n" + content raise AssertionError( "issues detected for function '{0}' - {1}\n{2}".format(f, func, mes)) exclude = os.path.join(temp, "pyquickhelper", "helpgen", "utils_sphinx_doc.py") with open(exclude, "r") as f: content = f.read() self.assertNotIn("### # -- HELP END EXCLUDE --", content) self.assertNotIn( "### class useless_class_UnicodeStringIOThreadSafe(str):", content)
def test_synchro_hash(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_seco2") troi = get_temp_folder(__file__, "temp_troi2") sec2 = get_temp_folder(__file__, "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) self.assertExists(file_date) self.assertExists(os.path.join(troi, "sub", "filetwo.txt")) self.assertExists(stay) self.assertNotExists(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 [6, 7, 8]: raise Exception( "2 or 3 expected: " + "\n".join([str(_) for _ in a])) self.assertEqual(a[0][0], ">+") self.assertEqual(a[0][0], a[1][0]) self.assertEqual(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)