def test_import_path_loc(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): from exsig import clex ipath = import_path(clex) self.assertEqual(ipath, 'exsig')
def test_autosignature_html(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name = import_object("exdocassert.onefunction", "function") newstring = [ "AAAAAAAAAAAAAAAA", ".. autosignature:: exdocassert.onefunction", "BBBBBBBBBBBBBBBB", ".. autofunction:: exdocassert.onefunction", "CCCCCCCCCCCCCCCC" ] newstring = "\n\n".join(newstring) htmls = rst2html(newstring, layout="sphinx_body") self.assertIn("CCCCCCCCCCCCCCCC", htmls) from docutils.parsers.rst.directives import _directives self.assertTrue("autosignature" in _directives) html = htmls.split("BBBBBBBBBBBBBBBB") self.assertIn("onefunction", html[0]) self.assertIn("onefunction", html[1]) self.assertIn("<strong>a</strong>", html[1]) self.assertNotIn("<strong>a</strong>", html[0]) self.assertNotIn(":param a:", html[0]) self.assertNotIn("`", html[0]) self.assertNotIn("if a and b have different types", html[0]) self.assertIn("Return the addition of", html[0])
def test_autosignature_class_onemethod(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data, 0): newstring = ["AAAAAAAAAAAAAAAA", "", ".. autosignature:: exsig.clex", " :members: onemethod", "", "CCCCCCCCCCCCCCCC"] newstring = "\n".join(newstring) htmls = rst2html(newstring, layout="sphinx_body") self.assertIn("CCCCCCCCCCCCCCCC", htmls) html = htmls.split("CCCCCCCCCCCCCCCC") if "onemethod" not in html[0]: raise Exception(html[0]) if "<strong>a</strong>" in html[0]: raise Exception(html[0]) if ":param a:" in html[0]: raise Exception(html[0]) if "`" in html[0]: raise Exception(html[0]) if "if a and b have different types" in html[0]: raise Exception(html[0]) if "Return the addition of" not in html[0]: raise Exception(html[0])
def test_import_object(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name = import_object("exdocassert.onefunction", "function") self.assertTrue(obj is not None) self.assertTrue(obj(4, 5), 9)
def test_autosignature_class_onemethod2(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): newstring = ["AAAAAAAAAAAAAAAA", "", ".. autosignature:: exdocassert2.onefunction", "", "CCCCCCCCCCCCCCCC"] newstring = "\n".join(newstring) htmls = rst2html(newstring, layout="sphinx_body") self.assertIn("CCCCCCCCCCCCCCCC", htmls) html = htmls.split("CCCCCCCCCCCCCCCC") if "onefunction" not in html[0]: raise Exception(html[0]) if "<strong>a</strong>" in html[0]: raise Exception(html[0]) if ":param a:" in html[0]: raise Exception(html[0]) if "`" in html[0]: raise Exception(html[0]) if "if a and b have different types" in html[0]: raise Exception(html[0]) if "Return the addition of" not in html[0]: raise Exception(html[0]) if "Second line should be aligned." not in html[0]: raise Exception(html[0]) if "<p>Return the addition of" not in html[0]: raise Exception(html[0]) if "should be aligned.</p>" not in html[0]: raise Exception(html[0])
def test_autosignature_class_static_method(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj = import_object("exsig.clex.static_method", "staticmethod") self.assertTrue(obj is not None) newstring = [ "AAAAAAAAAAAAAAAA", "", ".. autosignature:: exsig.clex.static_method", "", "CCCCCCCCCCCCCCCC" ] newstring = "\n".join(newstring) htmls = rst2html(newstring, layout="sphinx_body") self.assertIn("CCCCCCCCCCCCCCCC", htmls) html = htmls.split("CCCCCCCCCCCCCCCC") if "static_method" not in html[0]: raise Exception(html[0]) if "<strong>a</strong>" in html[0]: raise Exception(html[0]) if ":param a:" in html[0]: raise Exception(html[0]) if "`" in html[0]: raise Exception(html[0]) if "if a and b have different types" in html[0]: raise Exception(html[0]) if "Return the static addition of" not in html[0]: raise Exception(html[0]) if "<p>Return the static addition of" not in html[0]: raise Exception(html[0])
def test_autosignature_class_onemethod2(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): newstring = [ "AAAAAAAAAAAAAAAA", "", ".. autosignature:: exdocassert2.onefunction", "", "CCCCCCCCCCCCCCCC" ] newstring = "\n".join(newstring) htmls = rst2html(newstring, layout="sphinx_body") self.assertIn("CCCCCCCCCCCCCCCC", htmls) html = htmls.split("CCCCCCCCCCCCCCCC") if "onefunction" not in html[0]: raise Exception(html[0]) if "<strong>a</strong>" in html[0]: raise Exception(html[0]) if ":param a:" in html[0]: raise Exception(html[0]) if "`" in html[0]: raise Exception(html[0]) if "if a and b have different types" in html[0]: raise Exception(html[0]) if "Return the addition of" not in html[0]: raise Exception(html[0]) if "Second line should be aligned." not in html[0]: raise Exception(html[0]) if "<p>Return the addition of" not in html[0]: raise Exception(html[0]) if "should be aligned.</p>" not in html[0]: raise Exception(html[0])
def test_autosignature_class_static_method(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj = import_object("exsig.clex.static_method", "staticmethod") self.assertTrue(obj is not None) newstring = ["AAAAAAAAAAAAAAAA", "", ".. autosignature:: exsig.clex.static_method", "", "CCCCCCCCCCCCCCCC"] newstring = "\n".join(newstring) htmls = rst2html(newstring, layout="sphinx_body") self.assertIn("CCCCCCCCCCCCCCCC", htmls) html = htmls.split("CCCCCCCCCCCCCCCC") if "static_method" not in html[0]: raise Exception(html[0]) if "<strong>a</strong>" in html[0]: raise Exception(html[0]) if ":param a:" in html[0]: raise Exception(html[0]) if "`" in html[0]: raise Exception(html[0]) if "if a and b have different types" in html[0]: raise Exception(html[0]) if "Return the static addition of" not in html[0]: raise Exception(html[0]) if "<p>Return the static addition of" not in html[0]: raise Exception(html[0])
def test_autosignature_class(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): newstring = [ "AAAAAAAAAAAAAAAA", "", ".. autosignature:: exsig.clex", " :members:", "", "CCCCCCCCCCCCCCCC" ] newstring = "\n".join(newstring) htmls = rst2html(newstring, layout="sphinx_body") self.assertIn("CCCCCCCCCCCCCCCC", htmls) html = htmls.split("CCCCCCCCCCCCCCCC") if "onemethod" not in html[0]: raise Exception(html[0]) if "<strong>a</strong>" in html[0]: raise Exception(html[0]) if ":param a:" in html[0]: raise Exception(html[0]) if "`" in html[0]: raise Exception(html[0]) if "if a and b have different types" in html[0]: raise Exception(html[0]) if "Return the addition of" not in html[0]: raise Exception(html[0])
def test_import_any_object(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name, kind = import_any_object("exsig.clex") self.assertTrue(obj is not None) # self.assertTrue(obj.(4, 5), 9) self.assertEqual(name, "clex") self.assertEqual(kind, "class")
def test_import_any_object_benchmark(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): name = "pyquickhelper.benchhelper.grid_benchmark.GridBenchMark.bench_experiment" import_object(name, "method") obj, name, kind = import_any_object(name) self.assertTrue(obj is not None) # self.assertTrue(obj.(4, 5), 9) self.assertEqual(name, "bench_experiment") self.assertEqual(kind, "method")
def test_import_object(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name = import_object("exdocassert.onefunction", "function") self.assertTrue(obj is not None) self.assertTrue(obj(4, 5), 9)
def test_docassert_html_method(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") class MyStream: def __init__(self): self.rows = [] def write(self, text): fLOG( "[warning*] {0} - '{1}'".format(len(self), text.strip("\n\r "))) self.rows.append(text) def getvalue(self): return "\n".join(self.rows) def __len__(self): return len(self.rows) logger1 = getLogger("MockSphinxApp") logger2 = getLogger("docassert") log_capture_string = MyStream() # StringIO() ch = logging.StreamHandler(log_capture_string) ch.setLevel(logging.DEBUG) logger1.logger.addHandler(ch) logger2.logger.addHandler(ch) logger2.warning("try") this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name = import_object("exsig.clex.onemethod", "method") newstring = ".. automethod:: exsig.clex.onemethod" html = rst2html(newstring) self.assertTrue(html is not None) fLOG(len(log_capture_string)) lines = log_capture_string.getvalue().split("\n") if len(lines) == 0: raise Exception("no warning") nb = 0 for line in lines: if "'onemethod' has no parameter 'c'" in line: nb += 1 if nb == 0: raise Exception("not the right warning") for line in lines: if "'onemethod' has undocumented parameters 'b, self'" in line: raise Exception(line)
def test_autosignature_class_onemethod2_debug(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): newstring = [ "AAAAAAAAAAAAAAAA", "", ".. autosignature:: exdocassert2.onefunction", " :debug:", " :syspath: aaa;bbbb", "", "CCCCCCCCCCCCCCCC" ] newstring = "\n".join(newstring) htmls = rst2html(newstring, writer="rst") self.assertIn('[debug]', htmls) self.assertIn('[import_any_object]', htmls)
def test_import_any_object_static(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): name = "pyquickhelper.filehelper.transfer_api.TransferAPI_FileInfo.read_json" try: import_object(name, "method") self.assertTrue(False) except TypeError as e: pass import_object(name, "staticmethod") obj, name, kind = import_any_object(name) self.assertTrue(obj is not None) # self.assertTrue(obj.(4, 5), 9) self.assertEqual(name, "read_json") self.assertEqual(kind, "staticmethod")
def test_autosignature_empty_variable(self): newstring = [ "AAAAAAAAAAAAAAAA", ".. autosignature:: variable.empty_variable", "CCCCCCCCCCCCCCCC" ] newstring = "\n\n".join(newstring) this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): res, logs = self.assertLogging( lambda: rst2html(newstring, writer='rst', layout="sphinx"), 'autosignature', log_sphinx=True) self.assertIn("CCCCCCCCCCCCCCCC", res) self.assertIn("unable to import 'variable.empty_variable'", logs) self.assertIn("TypeError", logs)
def test_docassert_html(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") logger1 = getLogger("MockSphinxApp") logger2 = getLogger("docassert") log_capture_string = StringIO() ch = logging.StreamHandler(log_capture_string) ch.setLevel(logging.DEBUG) logger1.logger.addHandler(ch) logger2.logger.addHandler(ch) this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name = import_object("exdocassert.onefunction", "function") docstring = obj.__doc__ with warnings.catch_warnings(record=True) as ws: html = rst2html(docstring) if "if a and b have different" not in html: raise Exception(html) newstring = ".. autofunction:: exdocassert.onefunction" with warnings.catch_warnings(record=True) as ws: html = rst2html(newstring) for i, w in enumerate(ws): fLOG(i, ":", w) if "if a and b have different" not in html: html = rst2html(newstring, fLOG=fLOG) fLOG("number of warnings", len(ws)) for i, w in enumerate(ws): fLOG(i, ":", str(w).replace("\\n", "\n")) raise Exception(html) from docutils.parsers.rst.directives import _directives self.assertTrue("autofunction" in _directives) lines = log_capture_string.getvalue().split("\n") if len(lines) > 0: for line in lines: if "'onefunction' has no parameter 'TypeError'" in line: raise Exception( "This warning should not happen.\n{0}".format("\n".join(lines))) self.assertTrue("<strong>a</strong>" in html)
def test_autosignature_class_onemethod2_debug(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): newstring = ["AAAAAAAAAAAAAAAA", "", ".. autosignature:: exdocassert2.onefunction", " :debug:", " :syspath: aaa;bbbb", "", "CCCCCCCCCCCCCCCC"] newstring = "\n".join(newstring) htmls = rst2html(newstring, writer="rst") self.assertIn('[debug]', htmls) self.assertIn('[import_any_object]', htmls)
def test_autosignature_cplusplus(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): from cpyquickhelper.numbers.cbenchmark import vector_dot_product16 # pylint: disable=E0611,E0401 self.assertIn("Computes a dot product in C++", vector_dot_product16.__doc__) newstring = ["AAAAAAAAAAAAAAAA", "", ".. autosignature:: cpyquickhelper.numbers.cbenchmark.vector_dot_product16", "", "CCCCCCCCCCCCCCCC"] newstring = "\n".join(newstring) text = rst2html(newstring, writer="rst") self.assertIn( "cpyquickhelper.numbers.cbenchmark.vector_dot_product16", text) self.assertIn("Computes a dot product in C++ with vectors", text)
def test_autosignature_cplusplus(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): from cpyquickhelper.numbers.cbenchmark import vector_dot_product16 # pylint: disable=E0611,E0401 self.assertIn("Computes a dot product in C++", vector_dot_product16.__doc__) newstring = [ "AAAAAAAAAAAAAAAA", "", ".. autosignature:: cpyquickhelper.numbers.cbenchmark.vector_dot_product16", "", "CCCCCCCCCCCCCCCC" ] newstring = "\n".join(newstring) text = rst2html(newstring, writer="rst") self.assertIn( "cpyquickhelper.numbers.cbenchmark.vector_dot_product16", text) self.assertIn("Computes a dot product in C++ with vectors", text)
def test_autosignature_html(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name = import_object("exdocassert.onefunction", "function") newstring = ["AAAAAAAAAAAAAAAA", ".. autosignature:: exdocassert.onefunction", "BBBBBBBBBBBBBBBB", ".. autofunction:: exdocassert.onefunction", "CCCCCCCCCCCCCCCC"] newstring = "\n\n".join(newstring) htmls = rst2html(newstring, layout="sphinx_body") self.assertIn("CCCCCCCCCCCCCCCC", htmls) from docutils.parsers.rst.directives import _directives self.assertTrue("autosignature" in _directives) html = htmls.split("BBBBBBBBBBBBBBBB") if "onefunction" not in html[0]: raise Exception(html[0]) if "onefunction" not in html[1]: raise Exception(html[1]) if "<strong>a</strong>" not in html[1]: raise Exception(html[1]) if "<strong>a</strong>" in html[0]: raise Exception(html[0]) if ":param a:" in html[0]: raise Exception(html[0]) if "`" in html[0]: raise Exception(html[0]) if "if a and b have different types" in html[0]: raise Exception(html[0]) if "Return the addition of" not in html[0]: raise Exception(html[0])
def test_full_unit_test(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if __name__ != "__main__" or not os.path.exists( "temp2_full_unit_test_history"): temp_ = get_temp_folder(__file__, "temp2_full_unit_test_history") temp = os.path.join(temp_, "python3_module_template") if not os.path.exists(temp): os.mkdir(temp) git_clone(temp, "github.com", "sdpython", "python3_module_template") wait = 0 while not os.path.exists( os.path.join(temp, "python3_module_template")) and wait < 5: fLOG("wait", wait) time.sleep(1000) wait += 1 else: temp = os.path.abspath( os.path.join("temp2_full_unit_test", "python3_module_template")) root = temp with sys_path_append(os.path.join(root)): setup = os.path.join(root, "setup.py") pyq = os.path.join(os.path.dirname(pyquickhelper.__file__), "..") def skip_function(name, code, duration): return "test_example" not in name pyq_folder = os.path.normpath( os.path.abspath( os.path.join(os.path.dirname(pyq_location), '..'))) stdout = StringIO() stderr = StringIO() fLOG("setup", setup) thispath = os.path.abspath(os.path.dirname(__file__)) thispath = os.path.normpath( os.path.join(thispath, "..", "..", "src")) import jyquickhelper fLOG("unit tests", root) for command in ["build_history"]: fLOG("#######################################################") fLOG("#######################################################") fLOG(command) fLOG("#######################################################") rem = False PYTHONPATH = os.environ.get("PYTHONPATH", "") sep = ";" if sys.platform.startswith("win") else ":" new_val = PYTHONPATH + sep + thispath os.environ["PYTHONPATH"] = new_val.strip(sep) log_lines = [] def logging_custom(*args, **kwargs): log_lines.append(args) lcmd = command.split() if ' ' in command else [command] stdout2 = StringIO() stderr2 = StringIO() r = process_standard_options_for_setup( lcmd, setup, "python3_module_template", port=8067, requirements=["pyquickhelper"], blog_list=None, fLOG=logging_custom, additional_ut_path=[pyq, (root, True)], skip_function=skip_function, coverage_options={"disable_coverage": True}, stdout=stdout2, stderr=stderr2, use_run_cmd=True) vout = stdout2.getvalue() stdout.write(vout) verr = stderr2.getvalue() stderr.write(verr) if rem: del sys.path[sys.path.index(thispath)] os.environ["PYTHONPATH"] = PYTHONPATH fLOG("#######################################################") fLOG("#######################################################") sout = stdout.getvalue() fLOG("--OUT--\n", sout) fLOG("--ERR--\n", stderr.getvalue()) if len(sout) == 0: fLOG("Empty output. thispath='{}'".format(thispath))
def test_full_unit_test(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if __name__ != "__main__" or not os.path.exists("temp2_full_unit_test_history"): temp_ = get_temp_folder(__file__, "temp2_full_unit_test_history") temp = os.path.join(temp_, "python3_module_template") if not os.path.exists(temp): os.mkdir(temp) git_clone(temp, "github.com", "sdpython", "python3_module_template") wait = 0 while not os.path.exists(os.path.join(temp, "python3_module_template")) and wait < 5: fLOG("wait", wait) time.sleep(1000) wait += 1 else: temp = os.path.abspath(os.path.join( "temp2_full_unit_test", "python3_module_template")) root = temp with sys_path_append(os.path.join(root)): setup = os.path.join(root, "setup.py") pyq = os.path.join(os.path.dirname(pyquickhelper.__file__), "..") def skip_function(name, code, duration): return "test_example" not in name pyq_folder = os.path.normpath(os.path.abspath( os.path.join(os.path.dirname(pyq_location), '..'))) stdout = StringIO() stderr = StringIO() fLOG("setup", setup) thispath = os.path.abspath(os.path.dirname(__file__)) thispath = os.path.normpath( os.path.join(thispath, "..", "..", "src")) import jyquickhelper fLOG("unit tests", root) for command in ["build_history"]: fLOG("#######################################################") fLOG("#######################################################") fLOG(command) fLOG("#######################################################") rem = False PYTHONPATH = os.environ.get("PYTHONPATH", "") sep = ";" if sys.platform.startswith("win") else ":" new_val = PYTHONPATH + sep + thispath os.environ["PYTHONPATH"] = new_val.strip(sep) log_lines = [] def logging_custom(*l, **p): log_lines.append(l) lcmd = command.split() if ' ' in command else [command] stdout2 = StringIO() stderr2 = StringIO() r = process_standard_options_for_setup( lcmd, setup, "python3_module_template", port=8067, requirements=["pyquickhelper"], blog_list=None, fLOG=logging_custom, additional_ut_path=[ pyq, (root, True)], skip_function=skip_function, coverage_options={ "disable_coverage": True}, hook_print=False, stdout=stdout2, stderr=stderr2, use_run_cmd=True) vout = stdout2.getvalue() stdout.write(vout) verr = stderr2.getvalue() stderr.write(verr) if rem: del sys.path[sys.path.index(thispath)] os.environ["PYTHONPATH"] = PYTHONPATH fLOG("#######################################################") fLOG("#######################################################") sout = stdout.getvalue() fLOG("--OUT--\n", sout) fLOG("--ERR--\n", stderr.getvalue()) if len(sout) == 0: fLOG("Empty output. thispath='{}'".format(thispath))
def test_full_documentation_module_template_rst(self): """ This test might fail in sphinx-gallery due to a very long filename. Please look into the following commit: https://github.com/sdpython/sphinx-gallery/commit/ 3ae9f13250cf25c75e1b17b2fade98b7a9940b0d. """ fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor() in ('travis', 'appveyor'): # travis fails due to the following: # sitep = [_ for _ in site.getsitepackages() if "packages" in _] # AttributeError: 'module' object has no attribute # 'getsitepackages' # It fails for python 2.7 (encoding issue). return temp = get_temp_folder(__file__, "temp_full_documentation_module_template_rst", clean=__name__ != "__main__") clog = CustomLog(temp) this_pyq = os.path.normpath( os.path.abspath( os.path.join(os.path.dirname(pyquickhelper.__file__), ".."))) class MyStream: def __init__(self): self.rows = [] def write(self, text): clog("[warning*] {0} - '{1}'".format(len(self), text.strip("\n\r "))) self.rows.append(text) def getvalue(self): return "\n".join(self.rows) def __len__(self): return len(self.rows) rem = os.path.join(temp, "python3_module_template-master", "_doc", "sphinxdoc", "build") if os.path.exists(rem): remove_folder(rem) url = "https://github.com/sdpython/python3_module_template/archive/master.zip" fLOG("[ut] download", url) download(url, temp, fLOG=fLOG, flatten=False) self.assertTrue(not os.path.exists(os.path.join(temp, "src"))) root = os.path.join(temp, "python3_module_template-master") with sys_path_append(os.path.join(root, "src")): # Checks that the unit test might fails. coucou = os.path.join( temp, "python3_module_template-master", "_doc", "sphinxdoc", "source", "gallery", "python3_module_template.subproject2.exclude_from_code_coverage.NotImplementedClass.__init__.examples" ) if not os.path.exists(coucou): fLOG("[ut] creating file '{0}'".format(coucou)) clog("[ut] creating file '{0}'".format(coucou)) dirname = os.path.dirname(coucou) os.makedirs(dirname) try: # replicating what sphinx_gallery does open(coucou, "w").close() except Exception as e: warnings.warn("Unable to create '{0}' due to '{1}'".format( coucou, e)) else: fLOG("[ut] file exists '{0}'".format(coucou)) clog("[ut] file exists '{0}'".format(coucou)) # documentation fLOG("generate documentation", root) var = "python3_module_template" # we modify conf.py to let it find pyquickhelper pyq = os.path.abspath(os.path.dirname(pyquickhelper.__file__)) confpy = os.path.join(root, "_doc", "sphinxdoc", "source", "conf.py") if not os.path.exists(confpy): raise FileNotFoundError("Unable to find '{0}' and\n{1}".format( confpy, os.listdir(temp))) with open(confpy, "r", encoding="utf8") as f: lines = f.read().split("\n") fi = len(lines) - 1 for i, line in enumerate(lines): if line.startswith("sys."): fi = i break addition = "sys.path.append(r'{0}')".format(pyq) lines[fi] = "{0}\n{1}".format(addition, lines[fi]) with open(confpy, "w", encoding="utf8") as f: f.write("\n".join(lines)) # test for i in range(0, 3): fLOG("\n") fLOG("\n") fLOG("\n") fLOG("#################################################", i) fLOG("#################################################", i) fLOG("#################################################", i) # we add access to pyquickhelper p = os.path.abspath(os.path.dirname(pyquickhelper.__file__)) p = os.path.join(p, 'src') fLOG("PYTHONPATH=", p) os.environ["PYTHONPATH"] = p if p not in sys.path: pos = len(sys.path) sys.path.append(p) else: pos = -1 if "conf" in sys.modules: del sys.modules["conf"] fLOG( "[test_full_documentation] **********************************" ) fLOG("[test_full_documentation] begin", list(roles._roles.keys())) fLOG( "[test_full_documentation] **********************************" ) direct_call = i % 2 == 0 layout = ['rst'] logger1 = getLogger("docassert") logger2 = getLogger("tocdelay") log_capture_string = MyStream() # StringIO() ch = logging.StreamHandler(log_capture_string) ch.setLevel(logging.DEBUG) logger1.logger.addHandler(ch) logger2.logger.addHandler(ch) with warnings.catch_warnings(record=True) as ww: warnings.simplefilter("always") # Change clog for print if it fails on circleli generate_help_sphinx( var, module_name=var, root=root, layout=layout, extra_ext=["tohelp"], from_repo=False, direct_call=direct_call, parallel=1, fLOG=clog, extra_paths=[this_pyq], nbformats=['html', 'ipynb', 'rst', 'slides']) for w in ww: if isinstance(w, dict): rows = ["----"] + [ "{0}={1}".format(k, v) for k, v in sorted(w.items()) ] sw = "\n".join(rows) elif isinstance(w, warnings.WarningMessage): rows = [ "-----", str(type(w)), w.filename, str(w.lineno), str(w.message) ] sw = "\n".join(rows) else: sw = str(w) if "WARNING:" in sw and "ERROR/" in sw: raise Exception( "A warning is not expected:\n{0}".format(sw)) fLOG( "[test_full_documentation] **********************************" ) fLOG("[test_full_documentation] END") fLOG( "[test_full_documentation] **********************************" ) lines = log_capture_string.getvalue().split("\n") for line in lines: if not line.strip(): continue if "[docassert]" in line: raise Exception(line) if "[tocdelay]" in line: fLOG(" ", line) if '[tocdelay] ERROR' in line: raise Exception(line) # we clean if "pyquickhelper" in sys.modules: del sys.modules["pyquickhelper"] os.environ["PYTHONPATH"] = "" if pos >= 0: del sys.path[pos] # blog index blog = os.path.join(root, "_doc", "sphinxdoc", "build", "rst", "blog", "blogindex.rst") with open(blog, "r", encoding="utf-8") as f: content = f.read() self.assertIn("2015", content) self.assertIn('<2016/2016-06-11_blogpost_with_label>', content) spl = content.split("2016-06") if len(spl) <= 2: raise Exception("Two expected:\n" + content) # checkings files = [ os.path.join(root, "_doc", "sphinxdoc", "build", "rst", "index.rst"), os.path.join(root, "_doc", "sphinxdoc", "build", "rst", "all_notebooks.rst"), ] for f in files: if not os.path.exists(f): raise FileNotFoundError( "Not found '{0}'\n---\n{1}".format( f, "\n".join(lines))) self.assertTrue(not os.path.exists(os.path.join(temp, "_doc"))) rss = os.path.join(root, "_doc", "sphinxdoc", "source", "blog", "rss.xml") with open(rss, "r", encoding="utf8") as f: content_rss = f.read() self.assertTrue("__BLOG_ROOT__" not in content_rss) # this should be replaced when uploading the stream onto the website # the website is unknown when producing the documentation # it should be resolved when uploading (the documentation could be # uploaded at different places) # checks some links were processed fhtml = os.path.join(temp, "python3_module_template-master", "_doc", "sphinxdoc", "source", "all_notebooks.rst") with open(fhtml, "r", encoding="utf8") as f: content = f.read() self.assertTrue('notebooks/custom_notebooks' in content) # checks slideshow was added fhtml = os.path.join(temp, "python3_module_template-master", "build", "notebooks", "bslides", "custom_notebooks.ipynb") with open(fhtml, "r", encoding="utf8") as f: content = f.read() self.assertTrue('"slide"' in content) # reveal.js + images rev = [ os.path.join(root, "_doc", "sphinxdoc", "source", "phdoc_static", "reveal.js") ] for r in rev: if not os.path.exists(r): raise FileNotFoundError(r)
def test_full_unit_test(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if __name__ != "__main__" or not os.path.exists("temp2_full_unit_test"): temp_ = get_temp_folder(__file__, "temp2_full_unit_test") temp = os.path.join(temp_, "python3_module_template") if not os.path.exists(temp): os.mkdir(temp) git_clone(temp, "github.com", "sdpython", "python3_module_template") wait = 0 while not os.path.exists(os.path.join(temp, "python3_module_template")) and wait < 5: fLOG("wait", wait) time.sleep(1000) wait += 1 else: temp = os.path.abspath(os.path.join( "temp2_full_unit_test", "python3_module_template")) root = temp with sys_path_append(os.path.join(root, "src")): setup = os.path.join(root, "setup.py") pyq = os.path.join(os.path.dirname(pyquickhelper.__file__), "..") def skip_function(name, code, duration): return "test_example" not in name pyq_folder = os.path.normpath(os.path.abspath( os.path.join(os.path.dirname(pyq_location), '..'))) blog_list = """ <?xml version="1.0" encoding="UTF-8"?> <opml version="1.0"> <head> <title>blog</title> </head> <body> <outline text="python3_module_template" title="python3_module_template" type="rss" xmlUrl="http://www.xavierdupre.fr/app/pyquickhelper/python3_module_template/_downloads/rss.xml" htmlUrl="http://www.xavierdupre.fr/app/pyquickhelper/python3_module_template/blog/main_0000.html" /> </body> </opml> """ stdout = StringIO() stderr = StringIO() fLOG("setup", setup) thispath = os.path.abspath(os.path.dirname(__file__)) thispath = os.path.normpath( os.path.join(thispath, "..", "..", "src")) import jyquickhelper fLOG("unit tests", root) for command in ["version", "write_version", "clean_pyd", "setup_hook", "build_script", "copy27", "run_pylint .*((myex)|(example_ext)).*[.]py$ " "-iC0103 -iR0201 -iC0123 -iC0111 -iW0611 -iE0401 -iE0611 -iE0401", "unittests -e .*code_style.*", "unittests -g .*((ext)|(code_style)|(run_notebooks)).*", "unittests_LONG", "unittests_SKIP", "build_sphinx"]: if command == "build_sphinx" and is_travis_or_appveyor() in ('travis', 'appveyor'): # InkScape not installed for AppVeyor or travis. continue if command == "build_sphinx" and is_travis_or_appveyor() in ('azurepip', ): # AttributeError: type object 'Callable' has no attribute '_abc_registry' continue fLOG("#######################################################") fLOG("#######################################################") fLOG(command) fLOG("#######################################################") rem = False PYTHONPATH = os.environ.get("PYTHONPATH", "") sep = ";" if sys.platform.startswith("win") else ":" new_val = PYTHONPATH + sep + thispath new_val_src = new_val + sep + 'src' if os.path.exists(new_val_src): new_val = new_val_src os.environ["PYTHONPATH"] = new_val.strip(sep) if command == "build_sphinx": if thispath not in sys.path: sys.path.append(thispath) fLOG("UT add", thispath) rem = True log_lines = [] def logging_custom(*l, **p): log_lines.append(l) lcmd = command.split() if ' ' in command else [command] stdout2 = StringIO() stderr2 = StringIO() pos_remove = None if command == "unittests -e .*code_style.*": if pyq_folder not in sys.path: pos_remove = len(sys.path) sys.path.append(pyq_folder) fLOG("ADD='{0}'".format(pyq_folder)) try: r = process_standard_options_for_setup( lcmd, setup, "python3_module_template", port=8067, requirements=["pyquickhelper"], blog_list=blog_list, fLOG=logging_custom, additional_ut_path=[ pyq, (root, True)], skip_function=skip_function, coverage_options={ "disable_coverage": True}, hook_print=False, stdout=stdout2, stderr=stderr2, use_run_cmd=True) goon = True except TestWrappedException as e: if "test_coverage_combine.py" in str(e): goon = False else: raise e except NotImplementedError: # Maybe not implemented on linux or windows. goon = False if goon: if command == "unittests -e .*code_style.*" and pos_remove: if sys.path[pos_remove] != pyq_folder: raise Exception( "sys.path has changed at position {0}".format(pos_remove)) del sys.path[pos_remove] fLOG("REMOVE='{0}'".format(pyq_folder)) elif pos_remove: del sys.path[pos_remove] vout = stdout2.getvalue() stdout.write(vout) verr = stderr2.getvalue() stderr.write(verr) if "unittests" in command: if not r: raise Exception("{0}-{1}".format(r, command)) for line in log_lines: fLOG(" ", line) if len(log_lines) == 0: raise Exception( "command1={0}\n--OUT--\n{1}\n--ERR--\n{2}".format(command, vout, verr)) if "-e" in command and "running test 1, ut_module/test_convert_notebooks.py" in vout: raise Exception(vout) if "-e" in command and "_ext" not in vout and "code_style" not in command: raise Exception( "command3={0}\n--OUT--\n{1}".format(command, vout)) if "LONG" in command and "running test 1, ut_module/test_convert_notebooks.py" in vout: raise Exception(vout) if rem: del sys.path[sys.path.index(thispath)] os.environ["PYTHONPATH"] = PYTHONPATH fLOG("#######################################################") fLOG("#######################################################") fLOG("OUT:\n", stdout.getvalue()) fLOG("ERR:\n", stderr.getvalue()) out = os.path.join(temp, "_unittests", "unittests.out") if not os.path.exists(out): raise Exception("not found: " + out)
def test_sys_path_append0(self): self.assertNotIn("ZooZoo", sys.path) with sys_path_append("ZooZoo", 0): self.assertIn("ZooZoo", sys.path) self.assertNotIn("ZooZoo", sys.path)
def run_all_tests(location, folder=None, verbose=True): """ Runs all unit tests or unit tests specific to one library. The tests produce a series of files dumped into ``folder`` which can be later used to tests a backend (or a runtime). """ if folder is None: raise ValueError("folder cannot be None") os.environ["ONNXTESTDUMP"] = folder os.environ["ONNXTESTDUMPERROR"] = "1" os.environ["ONNXTESTBENCHMARK"] = "1" if verbose: print("[benchmark] look into '{0}'".format(location)) print("[benchmark] dump into '{0}'".format(folder)) subs = [location] loader = unittest.TestLoader() suites = [] for sub in subs: fold = os.path.join(this, sub) if not os.path.exists(fold): raise FileNotFoundError("Unable to find '{0}'".format(fold)) with sys_path_append(fold): names = [_ for _ in os.listdir(fold) if _.startswith("test")] for name in names: if "test_utils" in name: continue if "dump" in name.lower(): continue name = os.path.splitext(name)[0] ts = loader.loadTestsFromName(name) suites.append(ts) with warnings.catch_warnings(): warnings.filterwarnings(category=DeprecationWarning, action="ignore") warnings.filterwarnings(category=FutureWarning, action="ignore") st = StringIO() runner = unittest.TextTestRunner(st, verbosity=0) name = "" for tsi, ts in enumerate(suites): for k in ts: try: for t in k: name = t.__class__.__name__ break except TypeError as e: warnings.warn( "[ERROR] Unable to run test '{}' - {}.".format( ts, str(e).replace("\n", " "))) if verbose: print("[benchmark] {}/{}: '{}'".format(tsi + 1, len(suites), name)) with contextlib.redirect_stderr(st): with contextlib.redirect_stdout(st): runner.run(ts) from test_utils.tests_helper import make_report_backend df = make_report_backend(folder, as_df=True) return df
def test_full_unit_test(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if __name__ != "__main__" or not os.path.exists( "temp2_full_unit_test"): temp_ = get_temp_folder(__file__, "temp2_full_unit_test") temp = os.path.join(temp_, "python3_module_template") if not os.path.exists(temp): os.mkdir(temp) git_clone(temp, "github.com", "sdpython", "python3_module_template") wait = 0 while not os.path.exists( os.path.join(temp, "python3_module_template")) and wait < 5: fLOG("wait", wait) time.sleep(1000) wait += 1 else: temp = os.path.abspath( os.path.join("temp2_full_unit_test", "python3_module_template")) root = temp with sys_path_append(os.path.join(root, "src")): setup = os.path.join(root, "setup.py") pyq = os.path.join(os.path.dirname(pyquickhelper.__file__), "..") def skip_function(name, code, duration): return "test_example" not in name pyq_folder = os.path.normpath( os.path.abspath( os.path.join(os.path.dirname(pyq_location), '..'))) blog_list = """ <?xml version="1.0" encoding="UTF-8"?> <opml version="1.0"> <head> <title>blog</title> </head> <body> <outline text="python3_module_template" title="python3_module_template" type="rss" xmlUrl="http://www.xavierdupre.fr/app/pyquickhelper/python3_module_template/_downloads/rss.xml" htmlUrl="http://www.xavierdupre.fr/app/pyquickhelper/python3_module_template/blog/main_0000.html" /> </body> </opml> """ stdout = StringIO() stderr = StringIO() fLOG("setup", setup) thispath = os.path.abspath(os.path.dirname(__file__)) thispath = os.path.normpath( os.path.join(thispath, "..", "..", "src")) import jyquickhelper fLOG("unit tests", root) for command in [ "version", "write_version", "clean_pyd", "setup_hook", "build_script", "copy27", "run_pylint .*((myex)|(example_ext)).*[.]py$ " "-iC0103 -iR0201 -iC0123 -iC0111 -iW0611 -iE0401 -iE0611 -iE0401", "unittests -e .*code_style.*", "unittests -g .*((ext)|(code_style)|(run_notebooks)).*", "unittests_LONG", "unittests_SKIP", "build_sphinx" ]: if command == "build_sphinx" and is_travis_or_appveyor() in ( 'travis', 'appveyor'): # InkScape not installed for AppVeyor or travis. continue if command == "build_sphinx" and is_travis_or_appveyor() in ( 'azurepip', ): # AttributeError: type object 'Callable' has no attribute '_abc_registry' continue fLOG("#######################################################") fLOG("#######################################################") fLOG(command) fLOG("#######################################################") rem = False PYTHONPATH = os.environ.get("PYTHONPATH", "") sep = ";" if sys.platform.startswith("win") else ":" new_val = PYTHONPATH + sep + thispath new_val_src = new_val + sep + 'src' if os.path.exists(new_val_src): new_val = new_val_src os.environ["PYTHONPATH"] = new_val.strip(sep) if command == "build_sphinx": if thispath not in sys.path: sys.path.append(thispath) fLOG("UT add", thispath) rem = True log_lines = [] def logging_custom(*args, **kwargs): log_lines.append(args) lcmd = command.split() if ' ' in command else [command] stdout2 = StringIO() stderr2 = StringIO() pos_remove = None if command == "unittests -e .*code_style.*": if pyq_folder not in sys.path: pos_remove = len(sys.path) sys.path.append(pyq_folder) fLOG("ADD='{0}'".format(pyq_folder)) try: r = process_standard_options_for_setup( lcmd, setup, "python3_module_template", port=8067, requirements=["pyquickhelper"], blog_list=blog_list, fLOG=logging_custom, additional_ut_path=[pyq, (root, True)], skip_function=skip_function, coverage_options={"disable_coverage": True}, hook_print=False, stdout=stdout2, stderr=stderr2, use_run_cmd=True) goon = True except PEP8Exception as e: lines = str(e).split('\n')[1:] lines = [ line for line in lines if "should be placed before" not in line ] content = "\n".join(lines).strip("\n\r\t ") if len(content) > 0: raise AssertionError( "Remaining style issues.\n{}".format( content)) from e except TestWrappedException as e: if "test_coverage_combine.py" in str(e): goon = False else: raise e except NotImplementedError: # Maybe not implemented on linux or windows. goon = False if goon: if command == "unittests -e .*code_style.*" and pos_remove: if sys.path[pos_remove] != pyq_folder: raise Exception( "sys.path has changed at position {0}".format( pos_remove)) del sys.path[pos_remove] fLOG("REMOVE='{0}'".format(pyq_folder)) elif pos_remove: del sys.path[pos_remove] vout = stdout2.getvalue() stdout.write(vout) verr = stderr2.getvalue() stderr.write(verr) if "unittests" in command: if not r: raise Exception("{0}-{1}".format(r, command)) for line in log_lines: fLOG(" ", line) if len(log_lines) == 0: raise Exception( "command1={0}\n--OUT--\n{1}\n--ERR--\n{2}".format( command, vout, verr)) if "-e" in command and "running test 1, ut_module/test_convert_notebooks.py" in vout: raise Exception(vout) if "-e" in command and "_ext" not in vout and "code_style" not in command: raise Exception("command3={0}\n--OUT--\n{1}".format( command, vout)) if "LONG" in command and "running test 1, ut_module/test_convert_notebooks.py" in vout: raise Exception(vout) if rem: del sys.path[sys.path.index(thispath)] os.environ["PYTHONPATH"] = PYTHONPATH fLOG("#######################################################") fLOG("#######################################################") fLOG("OUT:\n", stdout.getvalue()) fLOG("ERR:\n", stderr.getvalue()) out = os.path.join(temp, "_unittests", "unittests.out") if not os.path.exists(out): raise Exception("not found: " + out)
def test_full_documentation_module_template(self): """ This test might fail in sphinx-gallery due to a very long filename. Please look into the following commit: https://github.com/sdpython/sphinx-gallery/commit/3ae9f13250cf25c75e1b17b2fade98b7a9940b0d. """ fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor() in ('travis', 'appveyor'): # travis fails due to the following: # sitep = [_ for _ in site.getsitepackages() if "packages" in _] # AttributeError: 'module' object has no attribute # 'getsitepackages' # It fails for python 2.7 (encoding issue). return temp = get_temp_folder(__file__, "temp_full_documentation_module_template", clean=__name__ != "__main__") clog = CustomLog(temp) this_pyq = os.path.normpath(os.path.abspath( os.path.join(os.path.dirname(pyquickhelper.__file__), ".."))) class MyStream: def __init__(self): self.rows = [] def write(self, text): clog( "[warning*] {0} - '{1}'".format(len(self), text.strip("\n\r "))) self.rows.append(text) def getvalue(self): return "\n".join(self.rows) def __len__(self): return len(self.rows) rem = os.path.join( temp, "python3_module_template-master", "_doc", "sphinxdoc", "build") if os.path.exists(rem): remove_folder(rem) url = "https://github.com/sdpython/python3_module_template/archive/master.zip" fLOG("[ut] download", url) download(url, temp, fLOG=fLOG, flatten=False) self.assertTrue(not os.path.exists(os.path.join(temp, "src"))) root = os.path.join(temp, "python3_module_template-master") with sys_path_append(os.path.join(root, "src")): # Checks that the unit test might fails. coucou = os.path.join(temp, "python3_module_template-master", "_doc", "sphinxdoc", "source", "gallery", "python3_module_template.subproject2.exclude_from_code_coverage.NotImplementedClass.__init__.examples") if not os.path.exists(coucou): fLOG("[ut] creating file '{0}'".format(coucou)) clog("[ut] creating file '{0}'".format(coucou)) dirname = os.path.dirname(coucou) os.makedirs(dirname) try: # replicating what sphinx_gallery does open(coucou, "w").close() except Exception as e: warnings.warn( "Unable to create '{0}' due to '{1}'".format(coucou, e)) else: fLOG("[ut] file exists '{0}'".format(coucou)) clog("[ut] file exists '{0}'".format(coucou)) # documentation fLOG("generate documentation", root) var = "python3_module_template" # we modify conf.py to let it find pyquickhelper pyq = os.path.abspath(os.path.dirname(pyquickhelper.__file__)) confpy = os.path.join( root, "_doc", "sphinxdoc", "source", "conf.py") if not os.path.exists(confpy): raise FileNotFoundError( "Unable to find '{0}' and\n{1}".format(confpy, os.listdir(temp))) with open(confpy, "r", encoding="utf8") as f: lines = f.read().split("\n") fi = len(lines) - 1 for i, line in enumerate(lines): if line.startswith("sys."): fi = i break addition = "sys.path.append(r'{0}')".format(pyq) lines[fi] = "{0}\n{1}".format(addition, lines[fi]) with open(confpy, "w", encoding="utf8") as f: f.write("\n".join(lines)) # test for i in range(0, 3): fLOG("\n") fLOG("\n") fLOG("\n") fLOG("#################################################", i) fLOG("#################################################", i) fLOG("#################################################", i) # we add access to pyquickhelper p = os.path.abspath(os.path.dirname(pyquickhelper.__file__)) p = os.path.join(p, 'src') fLOG("PYTHONPATH=", p) os.environ["PYTHONPATH"] = p if p not in sys.path: pos = len(sys.path) sys.path.append(p) else: pos = -1 if "conf" in sys.modules: del sys.modules["conf"] fLOG("[test_full_documentation] **********************************") fLOG("[test_full_documentation] begin", list(roles._roles.keys())) fLOG("[test_full_documentation] **********************************") direct_call = i % 2 == 0 layout = ["pdf", "html"] logger1 = getLogger("docassert") logger2 = getLogger("tocdelay") logger3 = getLogger("downloadlink") log_capture_string = MyStream() # StringIO() ch = logging.StreamHandler(log_capture_string) ch.setLevel(logging.DEBUG) logger1.logger.addHandler(ch) logger2.logger.addHandler(ch) logger3.logger.addHandler(ch) with warnings.catch_warnings(record=True) as ww: warnings.simplefilter("always") generate_help_sphinx(var, module_name=var, root=root, layout=layout, extra_ext=["tohelp"], from_repo=False, direct_call=direct_call, parallel=1, fLOG=clog, extra_paths=[this_pyq]) for w in ww: if isinstance(w, dict): rows = [ "----"] + ["{0}={1}".format(k, v) for k, v in sorted(w.items())] sw = "\n".join(rows) elif isinstance(w, warnings.WarningMessage): rows = [ "-----", str(type(w)), w.filename, str(w.lineno), str(w.message)] sw = "\n".join(rows) else: sw = str(w) if "WARNING:" in sw and "ERROR/" in sw: raise Exception( "A warning is not expected:\n{0}".format(sw)) fLOG("[test_full_documentation] **********************************") fLOG("[test_full_documentation] END") fLOG("[test_full_documentation] **********************************") lines = log_capture_string.getvalue().split("\n") for line in lines: if not line.strip(): continue if "[docassert]" in line: raise Exception(line) if "[tocdelay]" in line: fLOG(" ", line) if '[tocdelay] ERROR' in line: raise Exception(line) if '[downloadlink]' in line: fLOG(line) # we clean if "pyquickhelper" in sys.modules: del sys.modules["pyquickhelper"] os.environ["PYTHONPATH"] = "" if pos >= 0: del sys.path[pos] # blog index blog = os.path.join(root, "_doc", "sphinxdoc", "build", "html", "blog", "blogindex.html") with open(blog, "r", encoding="utf-8") as f: content = f.read() self.assertIn("2015", content) self.assertIn( '"2016/2016-06-11_blogpost_with_label.html"', content) spl = content.split("2016-06") if len(spl) <= 2: raise Exception("Two expected:\n" + content) # checkings files = [os.path.join(root, "_doc", "sphinxdoc", "build", "html", "index.html"), os.path.join(root, "_doc", "sphinxdoc", "build", "html", "all_indexes.html"), os.path.join(root, "_doc", "sphinxdoc", "build", "html", "all_notebooks.html"), ] for f in files: if not os.path.exists(f): raise FileNotFoundError( "Not found '{0}'\n---\n{1}".format(f, "\n".join(lines))) self.assertTrue(not os.path.exists(os.path.join(temp, "_doc"))) rss = os.path.join( root, "_doc", "sphinxdoc", "source", "blog", "rss.xml") with open(rss, "r", encoding="utf8") as f: content_rss = f.read() self.assertTrue("__BLOG_ROOT__" not in content_rss) # this should be replaced when uploading the stream onto the website # the website is unknown when producing the documentation # it should be resolved when uploading (the documentation could be # uploaded at different places) # checks some links were processed fhtml = os.path.join(temp, "python3_module_template-master", "_doc", "sphinxdoc", "build", "html", "index.html") with open(fhtml, "r", encoding="utf8") as f: content = f.read() if '<td><p><a class="reference internal" href="index_ext-tohelp.html#ext-tohelp"><span class="std std-ref">ext-tohelp</span></a></p></td>' not in content: raise Exception(content) # checks some links were processed fhtml = os.path.join(temp, "python3_module_template-master", "_doc", "sphinxdoc", "build", "html", "all_notebooks.html") with open(fhtml, "r", encoding="utf8") as f: content = f.read() if '<img alt="_images/custom_notebooks.thumb.png" src="_images/custom_notebooks.thumb.png" />' not in content: raise Exception(content) # checks slideshow was added fhtml = os.path.join(temp, "python3_module_template-master", "build", "notebooks", "bslides", "custom_notebooks.ipynb") with open(fhtml, "r", encoding="utf8") as f: content = f.read() self.assertTrue('"slide"' in content) # reveal.js + images rev = [os.path.join(root, "_doc", "sphinxdoc", "source", "phdoc_static", "reveal.js"), os.path.join(root, "_doc", "sphinxdoc", "build", "html", "_downloads", "reveal.js"), os.path.join(root, "_doc", "sphinxdoc", "build", "html", "notebooks", "reveal.js"), os.path.join(root, "_doc", "sphinxdoc", "build", "html", "notebooks", "Python_logo_and_wordmark.png"), os.path.join(root, "_doc", "sphinxdoc", "build", "html", "notebooks", "custom_notebooks.slides.html"), os.path.join(root, "_doc", "sphinxdoc", "build", "html", "notebooks", "custom_notebooks.html"), os.path.join(root, "_doc", "sphinxdoc", "build", "html", "_downloads", "rss.xml")] for r in rev: if not os.path.exists(r): logs = os.path.join(temp, "log_custom_000.txt") with open(logs, "r", encoding='utf-8') as f: content = f.read() found = os.listdir(os.path.dirname(r)) found2 = os.listdir(os.path.dirname( r.replace("build", "source").replace("/html", ""))) raise FileNotFoundError( "Unable to find '{0}' in\n{1}\n----\n{2}\n---LOGS--\n{3}".format( r, "\n".join(sorted(found)), "\n".join(sorted(found2)), content)) history = os.path.join( root, "_doc", "sphinxdoc", "build", "html", "HISTORY.html") if not os.path.exists(history): raise FileNotFoundError(history) with open(history, "r", encoding="utf-8") as f: content = f.read() tofind = 'python3_module_template' if tofind not in content: raise Exception( "Unable to find '{0}' in\n{1}".format(tofind, content)) # final check logs = os.path.join(temp, "log_custom_000.txt") with open(logs, "r", encoding='utf-8') as f: content = f.read() if "[downloadlink] node" not in content: raise Exception(content) if "[downloadlink] HTML" not in content: raise Exception(content) if "[downloadlink] copy" not in content: raise Exception(content)