Beispiel #1
0
    def test_notebook_gallery(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if sys.version_info[0] == 2:
            return

        temp = get_temp_folder(__file__, "temp_gallery")
        fold = os.path.normpath(os.path.join(
            temp, "..", "data_gallery", "notebooks"))
        assert os.path.exists(fold)

        file = os.path.join(temp, "all_notebooks.rst")
        build_notebooks_gallery(fold, file, fLOG=fLOG)
        if not os.path.exists(file):
            raise FileNotFoundError(file)

        with open(file, "r", encoding="utf8") as f:
            text = f.read()

        if "GitHub/pyquickhelper" in text.replace("\\", "/"):
            raise Exception(text)
        spl = text.split("notebooks/td2a_eco_competition_modeles_logistiques")
        if len(spl) != 3:
            raise Exception(text)
Beispiel #2
0
    def a_te_st_notebook(self, iteration):

        if sys.version_info[0] == 2:
            return

        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(
            os.path.join(
                path,
                "..",
                "..",
                "_doc",
                "notebooks"))
        nb = os.path.join(fold, "example_pyquickhelper.ipynb")
        assert os.path.exists(nb)

        temp = get_temp_folder(__file__, "temp_nb_%d" % iteration)

        if sys.platform.startswith("win"):
            p1 = r"C:\Program Files\MiKTeX 2.9\miktex\bin\x64"
            p2 = r"%USERPROFILE%\AppData\Local\Pandoc"
        else:
            p1 = "."
            p2 = "."

        formats = ["slides", "ipynb", "html", "python", "rst", "present"]
        exp = ["example_pyquickhelper.html",
               "example_pyquickhelper.ipynb",
               "example_pyquickhelper.py",
               "example_pyquickhelper.rst",
               "example_pyquickhelper.ipynb",
               "example_pyquickhelper.slides.html",
               "example_pyquickhelper.slides2p.html",
               ]

        if sys.platform.startswith("win"):
            formats.append("latex")
            formats.append("pdf")
            exp.append("example_pyquickhelper.tex")
            exp.append("example_pyquickhelper.pdf")

        if is_travis_or_appveyor() is not None:
            # it requires pandoc
            return

        res = process_notebooks(
            nb, temp, temp, latex_path=p1, pandoc_path=p2, formats=formats)
        for _ in res:
            fLOG(_)
            assert os.path.exists(_[0])

        fou = [os.path.split(_[0])[-1] for _ in res]
        fou = [_ for _ in fou if "png" not in _]
        fou = list(sorted(set(fou)))
        exp = list(sorted(set(exp)))
        if len(fou) < len(exp):
            raise Exception("length {0} != {1}\n{2}\n---\n{3}".format(len(fou), len(exp),
                                                                      "\n".join(fou), "\n".join(exp)))
        for i, j in zip(exp, fou):
            if i != j:
                raise Exception(
                    "{0} != {1}\nfou=\n{2}\nexp=\n{3}".format(
                        i, j, str(fou), str(exp)))

        file = os.path.join(temp, "all_notebooks.rst")
        build_notebooks_gallery(
            [_[0] for _ in res if _[0].endswith(".ipynb")], file)
        assert os.path.exists(file)

        with open(os.path.join(temp, "example_pyquickhelper.rst"), "r", encoding="utf8") as f:
            text = f.read()
        assert "from pyquickhelper.loghelper import fLOG\n    fLOG(OutputPrint=False)  # by default" in text
        if ".. raw:: html" not in text:
            raise Exception(text)