def test_notebook_rst_audio(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        formats = [
            "rst",
        ]
        temp = get_temp_folder(__file__, "temp_nb_bug_rst_audio")
        nbs = [os.path.join(temp, '..', 'data', 'exemple_div.ipynb')]
        clog = CustomLog(temp)
        clog("test_notebook_rst_audio")

        clog("process_notebooks: begin")
        process_notebooks(nbs, temp, temp, formats=formats, fLOG=clog)
        clog("process_notebooks: end")

        name = os.path.join(temp, "exemple_div.rst")
        clog("final checking", name)
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        clog("final read", name)
        exp = ".. raw:: html"
        if exp not in content:
            raise Exception(content)
        clog("done")
    def test_notebook_video(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        formats = ["pdf", "rst"]
        temp = get_temp_folder(__file__, "temp_nb_bug_video")
        nbs = [os.path.join(temp, '..', 'data', 'video_notebook.ipynb')]
        clog = CustomLog(temp)
        clog("test_notebook_rst_audio")

        clog("process_notebooks: begin")
        process_notebooks(nbs, temp, temp, formats=formats, fLOG=clog)
        clog("process_notebooks: end")

        name = os.path.join(temp, "video_notebook.tex")
        clog("final checking", name)
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        clog("final read", name)
        exp = "<moviepy.video.io.html\\_tools.HTML2 object>"
        if exp not in content:
            raise Exception(content)

        name = os.path.join(temp, "video_notebook.rst")
        clog("final checking", name)
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        clog("final read", name)
        exp = ".. raw:: html"
        if exp not in content:
            raise Exception(content)
        clog("done")
    def test_notebook_latex(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_latex"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["ipynb", "html", "python", "rst", "pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = os.path.join(path, "temp_nb_bug_latex")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])
    def test_notebook_slides(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_slides"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = ["slides"]

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        temp = get_temp_folder(__file__, "temp_nb_bug_slides")
        setup_environment_for_help()

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        with open(os.path.join(temp, "js_bokeh.slides.html"),
                  "r",
                  encoding="utf8") as f:
            content = f.read()
        exp = "is one if the most mature and complete library using javascript."
        if exp not in content:
            raise Exception(content)
    def test_notebook_comment(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_comment"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["rst", ]

        temp = os.path.join(path, "temp_nb_comment")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(os.path.exists(_[0]))

        with open(os.path.join(temp, "example_with_comments.rst"), "r", encoding="utf8") as f:
            lines = f.readlines()
        nb = 0
        for line in lines:
            if line.startswith(".. index:: comment, notebook, rst"):
                nb += 1
Пример #6
0
    def test_notebook_pdf(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = ["latex", "pdf"]

        temp = os.path.join(path, "temp_nb_bug_pdf")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        check = os.path.join(temp, "td1a_correction_session4.tex")
        with open(check, "r", encoding="utf8") as f:
            content = f.read()
        if "\\section{" not in content:
            raise Exception(content)
Пример #7
0
    def test_notebook_utf8(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_utf8"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = ["latex", "pdf", "rst", "html"]

        temp = os.path.join(path, "temp_nb_bug_utf8")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        setup_environment_for_help()

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        with open(os.path.join(temp, "simple_example.tex"),
                  "r",
                  encoding="utf8") as f:
            content = f.read()
        exp = "textquestiondown"
        if exp not in content:
            raise Exception(content)
    def test_notebook_rst_svg(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_nb_rst_svg")
        nbs = [os.path.normpath(os.path.join(
            temp, '..', "data", "rst_notebooks", "notebook_with_svg.ipynb"))]
        formats = ["rst"]

        res = process_notebooks(nbs, temp, temp, formats=formats, fLOG=fLOG)
        name = res[0][0]
        with open(name, 'r', encoding='utf-8') as f:
            content = f.read()
        self.assertIn('SVG in a notebook.', content)
        self.assertIn('.. image::', content)

        nb = 0
        for line in content.split('\n'):
            if '.. image::' in line:
                name = line.replace('.. image::', '').strip(' \r\t')
                dest = os.path.join(temp, name)
                self.assertExists(dest)
                nb += 1
        self.assertGreater(nb, 0)
    def test_notebook_python(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_python"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["python"]

        temp = os.path.join(path, "temp_nb_bug_python")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        setup_environment_for_help()

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        with open(os.path.join(temp, "seance5_approche_fonctionnelle_correction.py"), "r", encoding="utf8") as f:
            content = f.read()
        exp = "# -*- coding: utf-8 -*-"
        if exp not in content:
            raise Exception(content)
    def test_notebook_js(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_js"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["slides", "present", "ipynb", "html",
                   "python", "rst", "pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = get_temp_folder(__file__, "temp_nb_bug_js")

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            if not os.path.exists(_[0]):
                raise Exception(_[0])

        check = os.path.join(temp, "using_qgrid_with_jsdf.tex")
        with open(check, "r", encoding="utf8") as f:
            content = f.read()
        if "\\section{" not in content:
            raise Exception(content)
        checks = [os.path.join(temp, "reveal.js"),
                  os.path.join(temp, "require.js")]
        for check in checks:
            if not os.path.exists(check):
                raise Exception(check)
Пример #11
0
    def test_notebook_rst_svg(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_nb_rst_svg")
        nbs = [
            os.path.normpath(
                os.path.join(temp, '..', "data", "rst_notebooks",
                             "notebook_with_svg.ipynb"))
        ]
        formats = ["rst"]

        res = process_notebooks(nbs, temp, temp, formats=formats, fLOG=fLOG)
        name = res[0][0]
        with open(name, 'r', encoding='utf-8') as f:
            content = f.read()
        self.assertIn('SVG in a notebook.', content)
        self.assertIn('.. image::', content)

        nb = 0
        for line in content.split('\n'):
            if '.. image::' in line:
                name = line.replace('.. image::', '').strip(' \r\t')
                dest = os.path.join(temp, name)
                self.assertExists(dest)
                nb += 1
        self.assertGreater(nb, 0)
    def test_notebook_rst_image(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _ and '_11' in _]
        formats = ["rst", ]

        temp = get_temp_folder(__file__, "temp_nb_bug_rst_image")

        res = process_notebooks(nbs, temp, temp, formats=formats, fLOG=fLOG)
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        name = os.path.join(temp, "td1a_cenonce_session_11.rst")
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        exp = "output_7_0.png"
        if exp in content:
            raise Exception(content)
        exp = "td1a_cenonce_session_11_7_0.png"
        if exp not in content:
            raise Exception(content)
    def test_notebook_pdf(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["latex", "pdf"]

        temp = os.path.join(path, "temp_nb_bug_pdf")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        check = os.path.join(temp, "td1a_correction_session4.tex")
        with open(check, "r", encoding="utf8") as f:
            content = f.read()
        if "\\section{" not in content:
            raise Exception(content)
    def test_notebook_slides(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_slides"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["slides"]

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        temp = get_temp_folder(__file__, "temp_nb_bug_slides")
        setup_environment_for_help()

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        with open(os.path.join(temp, "js_bokeh.slides.html"), "r", encoding="utf8") as f:
            content = f.read()
        exp = "is one if the most mature and complete library using javascript."
        if exp not in content:
            raise Exception(content)
Пример #15
0
    def test_notebook_js(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_js"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = ["slides", "ipynb", "html", "python", "rst", "pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = get_temp_folder(__file__, "temp_nb_bug_js")

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            if not os.path.exists(_[0]):
                raise Exception(_[0])

        check = os.path.join(temp, "using_qgrid_with_jsdf.tex")
        with open(check, "r", encoding="utf8") as f:
            content = f.read()
        if "\\section{" not in content:
            raise Exception(content)
        checks = [
            os.path.join(temp, "reveal.js"),
            os.path.join(temp, "require.js")
        ]
        for check in checks:
            if not os.path.exists(check):
                raise Exception(check)
    def test_notebook_raw(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "data"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if "TD_2A" in _]
        self.assertGreater(len(nbs), 0)
        formats = ["latex", "present", "ipynb", "html",
                   "python", "rst", "pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = get_temp_folder(__file__, "temp_nb_bug_raw")

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        check = os.path.join(temp, "TD_2A_Eco_Web_Scraping.tex")
        with open(check, "r", encoding="utf8") as f:
            content = f.read()
        if "\\begin{verbatim" not in content:
            raise Exception(content)
    def test_notebook_rst_image_3a(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold)
            if ".ipynb" in _ and '3A' in _
        ]
        formats = [
            "rst",
        ]

        temp = get_temp_folder(__file__, "temp_nb_bug_rst_image_3A")

        res = process_notebooks(nbs, temp, temp, formats=formats, fLOG=fLOG)
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        name = os.path.join(temp, "td2a_cenonce_session_3A.rst")
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        exp = "output_7_0.png"
        if exp in content:
            raise AssertionError(content)
        exp = "td2a_cenonce_session_3A_12_0.png"
        if exp not in content:
            raise AssertionError(content)
Пример #18
0
    def test_notebook_docx(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_docx"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = ["ipynb", "html", "python", "rst", "pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = os.path.join(path, "temp_nb_bug_docx")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if sys.platform.startswith("win"):
            warnings.warn(
                "linux, unable to test TestNoteBooksBugDocx.test_notebook_docx"
            )
            return

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            assert os.path.exists(_[0])
    def test_notebook_rst(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_rst"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["rst", ]

        temp = get_temp_folder(__file__, "temp_nb_bug_rst")
        clog = CustomLog(temp)
        clog("test_notebook_rst")

        clog("process_notebooks: begin")
        res = process_notebooks(nbs, temp, temp, formats=formats, fLOG=clog)
        clog("process_notebooks: end")
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        name = os.path.join(temp, "having_a_form_in_a_notebook.rst")
        clog("final checking", name)
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        clog("final read", name)
        exp = "<#Animated-output>`"
        if exp in content or exp.lower() not in content:
            raise Exception(content)
        clog("done")
    def test_notebook_slides(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = ["slides"]

        temp = get_temp_folder(__file__, "temp_nb_bug_slides")

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            if not os.path.exists(_[0]):
                raise Exception(_[0])

        checks = [
            os.path.join(temp, "reveal.js"),
            os.path.join(temp, "require.js")
        ]
        for check in checks:
            if not os.path.exists(check):
                raise Exception(check)
    def test_notebook_video(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        formats = ["pdf", "rst"]
        temp = get_temp_folder(__file__, "temp_nb_bug_video")
        nbs = [os.path.join(temp, '..', 'data', 'video_notebook.ipynb')]
        clog = CustomLog(temp)
        clog("test_notebook_rst_audio")

        fold = 'static'
        if not os.path.exists(fold):
            os.mkdir(fold)
        for tpl in ['article']:
            sty = os.path.join(fold, '%s.tplx' % tpl)
            sr = os.path.join(temp, '..', 'data', '%s.tplx' % tpl)
            if not os.path.exists(sr):
                raise FileNotFoundError(sr)
            if not os.path.exists(sty):
                shutil.copy(sr, fold)
            if not os.path.exists('%s.tplx' % tpl):
                shutil.copy(sr, '.')

        clog("process_notebooks: begin")
        process_notebooks(nbs, temp, temp, formats=formats, fLOG=clog)
        clog("process_notebooks: end")

        name = os.path.join(temp, "video_notebook.rst")
        clog("final checking", name)
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        clog("final read", name)
        exp = ".. raw:: html"
        if exp not in content:
            raise Exception(content)

        clog("done")
        name = os.path.join(temp, "video_notebook.tex")
        clog("final checking", name)
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        clog("final read", name)
        exp = "<moviepy.video.io.html\\_tools.HTML2 object>"
        if exp not in content:
            raise Exception(content)
    def test_notebook_conversion_replacements(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        temp = get_temp_folder(
            __file__, "temp_notebook_conversion_replacements")
        this = os.path.join(temp, '..', "data", "TD_2A_Eco_Web_Scraping.ipynb")
        notebook_replacements = {'html': [('1ere page HTML', '2nd page-WWW')]}
        process_notebooks(this, build=temp, outfold=temp, formats=['html', 'slides'],
                          notebook_replacements=notebook_replacements)
        with open(os.path.join(temp, 'TD_2A_Eco_Web_Scraping2html.html'), 'r', encoding='utf-8') as f:
            text = f.read()
        self.assertNotIn(notebook_replacements['html'][0][0], text)
        self.assertIn(notebook_replacements['html'][0][1], text)
        with open(os.path.join(temp, 'TD_2A_Eco_Web_Scraping.slides.html'), 'r', encoding='utf-8') as f:
            text = f.read()
        self.assertIn(notebook_replacements['html'][0][0], text)
        self.assertNotIn(notebook_replacements['html'][0][1], text)
    def test_notebook_conversion_replacements(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        temp = get_temp_folder(__file__,
                               "temp_notebook_conversion_replacements")

        fold = 'static'
        if not os.path.exists(fold):
            os.mkdir(fold)
        for tpl in ['rst', 'display_priority', 'null', 'full']:
            sty = os.path.join(fold, '%s.tpl' % tpl)
            sr = os.path.join(temp, '..', 'data', '%s.tpl' % tpl)
            if not os.path.exists(sr):
                raise FileNotFoundError(sr)
            if not os.path.exists(sty):
                shutil.copy(sr, fold)
            if not os.path.exists('%s.tpl' % tpl):
                shutil.copy(sr, '.')

        this = os.path.join(temp, '..', "data", "TD_2A_Eco_Web_Scraping.ipynb")
        notebook_replacements = {'html': [('1ere page HTML', '2nd page-WWW')]}
        process_notebooks(this,
                          build=temp,
                          outfold=temp,
                          formats=['html', 'slides'],
                          notebook_replacements=notebook_replacements)
        with open(os.path.join(temp, 'TD_2A_Eco_Web_Scraping2html.html'),
                  'r',
                  encoding='utf-8') as f:
            text = f.read()
        self.assertNotIn(notebook_replacements['html'][0][0], text)
        self.assertIn(notebook_replacements['html'][0][1], text)
        with open(os.path.join(temp, 'TD_2A_Eco_Web_Scraping.slides.html'),
                  'r',
                  encoding='utf-8') as f:
            text = f.read()
        self.assertIn(notebook_replacements['html'][0][0], text)
        self.assertNotIn(notebook_replacements['html'][0][1], text)
    def test_notebook_rst_contents(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_nb_rst_contents")
        nbs = [os.path.normpath(os.path.join(
            temp, '..', "data", "rst_notebooks", "exemple_of_fix_menu.ipynb"))]
        formats = ["rst"]

        res = process_notebooks(nbs, temp, temp, formats=formats, fLOG=fLOG)
        name = res[0][0]
        with open(name, 'r', encoding='utf-8') as f:
            content = f.read()
        self.assertIn('.. contents::', content)
    def test_notebook_svg(self):
        """
        If the test fails, look into issue
        `216 <https://github.com/sdpython/pyquickhelper/issues/216>`_.
        Avoid nbconvert==5.4.0,==5.4.1.
        """
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_svg"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = ["latex", "pdf"]

        temp = os.path.join(path, "temp_nb_bug_svg")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor', 'azurepipe',
                                       'circleci'):
            return

        setup_environment_for_help()
        obj = SVG2PDFPreprocessor()
        self.assertIn('inkscape', obj.inkscape)
        cmd = '%s --version' % obj.inkscape
        out, err = run_cmd(cmd, wait=True, shell=False)
        self.assertIn('inkscape', out.lower())
        vers = obj.inkscape_version
        self.assertIn('inkscape', out.lower())

        res = process_notebooks(nbs, temp, temp, formats=formats)
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        with open(os.path.join(temp,
                               "seance4_projection_population_correction.tex"),
                  "r",
                  encoding="utf8") as f:
            content = f.read()
        exp = "seance4_projection_population_correction_50_0.pdf"
        if exp not in content:
            raise Exception(content)
    def test_notebook_rst(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_rst"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = [
            "rst",
        ]

        temp = get_temp_folder(__file__, "temp_nb_bug_rst")
        clog = CustomLog(temp)
        clog("test_notebook_rst")

        fold = 'static'
        if not os.path.exists(fold):
            os.mkdir(fold)
        for tpl in ['rst', 'display_priority', 'null']:
            sty = os.path.join(fold, '%s.tpl' % tpl)
            sr = os.path.join(temp, '..', 'data', '%s.tpl' % tpl)
            if not os.path.exists(sr):
                raise FileNotFoundError(sr)
            if not os.path.exists(sty):
                shutil.copy(sr, fold)
            if not os.path.exists('%s.tpl' % tpl):
                shutil.copy(sr, '.')

        clog("process_notebooks: begin")
        res = process_notebooks(nbs, temp, temp, formats=formats, fLOG=clog)
        clog("process_notebooks: end")
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        name = os.path.join(temp, "having_a_form_in_a_notebook.rst")
        clog("final checking", name)
        with open(name, "r", encoding="utf8") as f:
            content = f.read()
        clog("final read", name)
        exp = "<#Animated-output>`"
        if exp in content or exp.lower() not in content:
            raise Exception(content)
        clog("done")
Пример #27
0
    def test_notebook_rst_contents(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_nb_rst_contents")
        nbs = [
            os.path.normpath(
                os.path.join(temp, '..', "data", "rst_notebooks",
                             "exemple_of_fix_menu.ipynb"))
        ]
        formats = ["rst"]

        res = process_notebooks(nbs, temp, temp, formats=formats, fLOG=fLOG)
        name = res[0][0]
        with open(name, 'r', encoding='utf-8') as f:
            content = f.read()
        self.assertIn('.. contents::', content)
    def test_notebook_pdfa(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "data"))
        nbs = [os.path.join(fold, "completion_profiling.ipynb")]
        formats = ["pdf"]

        temp = get_temp_folder(__file__, 'temp_nb_bug_pdfa')

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])
    def test_notebook_pdfa(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "data"))
        nbs = [os.path.join(fold, "completion_profiling.ipynb")]
        formats = ["pdf"]

        temp = get_temp_folder(__file__, 'temp_nb_bug_pdfa')

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])
Пример #30
0
    def test_notebook_find(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_find"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["slides", "rst", "present", "ipynb", "html",
                   "python", "pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = get_temp_folder(__file__, "temp_nb_find")

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        nbs2 = []
        for r in nbs:
            r2 = os.path.join(temp, os.path.split(r)[-1])
            shutil.copy(r, r2)
            nbs2.append(r2)
            r = upgrade_notebook(r2)
            fLOG("change", r)
        nblinks = {('reftag', 'ipynb'): 'http://something',
                   ('reftag', 'python'): 'http://something'}
        res = process_notebooks(
            nbs2, temp, temp, formats=formats, exc=False, nblinks=nblinks)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertTrue(os.path.exists(_[0]))

        check = os.path.join(temp, "nb_find.tex")
        with open(check, "r", encoding="utf8") as f:
            content = f.read()
        self.assertTrue("\\end{document}" in content)
Пример #31
0
    def test_notebook_find(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_find"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["slides", "rst", "ipynb", "html",
                   "python", "pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = get_temp_folder(__file__, "temp_nb_find")

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        nbs2 = []
        for r in nbs:
            r2 = os.path.join(temp, os.path.split(r)[-1])
            shutil.copy(r, r2)
            nbs2.append(r2)
            r = upgrade_notebook(r2)
            fLOG("change", r)
        nblinks = {('reftag', 'ipynb'): 'http://something',
                   ('reftag', 'python'): 'http://something'}
        res = process_notebooks(
            nbs2, temp, temp, formats=formats, exc=False, nblinks=nblinks)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertTrue(os.path.exists(_[0]))

        check = os.path.join(temp, "nb_find.tex")
        with open(check, "r", encoding="utf8") as f:
            content = f.read()
        self.assertTrue("\\end{document}" in content)
    def test_notebook_svg(self):
        """
        If the test fails, look into issue
        `216 <https://github.com/sdpython/pyquickhelper/issues/216>`_.
        Avoid nbconvert==5.4.0,==5.4.1.
        """
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_svg"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["latex", "pdf"]

        temp = os.path.join(path, "temp_nb_bug_svg")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor', 'azurepipe'):
            return

        setup_environment_for_help()

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        with open(os.path.join(temp, "seance4_projection_population_correction.tex"), "r", encoding="utf8") as f:
            content = f.read()
        exp = "seance4_projection_population_correction_50_0.pdf"
        if exp not in content:
            raise Exception(content)
Пример #33
0
    def test_notebook_pdfa_indicatrice(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "data"))
        nbs = [os.path.join(fold, "classification_multiple.ipynb")]
        formats = ["pdf"]

        temp = get_temp_folder(__file__, 'temp_nb_bug_pdfa_indicatrice')

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])
        lat = os.path.join(temp, 'classification_multiple.tex')
        with open(lat, 'r', encoding='utf-8') as f:
            content = f.read()
        self.assertNotIn('\\mathbf{1}', content)
        self.assertNotIn('probl?me', content)
    def test_notebook_pdfs(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_pdf"))
        nbs = [os.path.join(fold, _)
               for _ in os.listdir(fold) if ".ipynb" in _]
        formats = ["pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = get_temp_folder(__file__, "temp_nb_bug_pdfs")

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])
Пример #35
0
    def ctest_notebook(self, name):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks2"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold)
            if ".ipynb" in _ and name in _
        ]
        formats = ["ipynb", "html", "python", "rst", "pdf"]
        if sys.platform.startswith("win"):
            formats.append("docx")

        temp = get_temp_folder(__file__, "temp_nb_bug2_" + name)

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        nbs2 = []
        for r in nbs:
            r2 = os.path.join(temp, os.path.split(r)[-1])
            shutil.copy(r, r2)
            nbs2.append(r2)
            r = upgrade_notebook(r2)
            fLOG("change", r)
        res = process_notebooks(nbs2, temp, temp, formats=formats, exc=False)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(os.path.exists(_[0]))

        check = os.path.join(temp, name + ".tex")
        with open(check, "r", encoding="utf8") as f:
            content = f.read()
        self.assertIn("\\end{document}", content)
Пример #36
0
    def test_notebook_comment(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_comment"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = [
            "rst",
        ]

        temp = os.path.join(path, "temp_nb_comment")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(os.path.exists(_[0]))

        with open(os.path.join(temp, "example_with_comments.rst"),
                  "r",
                  encoding="utf8") as f:
            lines = f.readlines()
        nb = 0
        for line in lines:
            if line.startswith(".. index:: comment, notebook, rst"):
                nb += 1
    def test_notebook_python(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        fold = os.path.normpath(os.path.join(path, "notebooks_python"))
        nbs = [
            os.path.join(fold, _) for _ in os.listdir(fold) if ".ipynb" in _
        ]
        formats = ["python"]

        temp = os.path.join(path, "temp_nb_bug_python")
        if not os.path.exists(temp):
            os.mkdir(temp)
        for file in os.listdir(temp):
            os.remove(os.path.join(temp, file))

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            return

        setup_environment_for_help()

        res = process_notebooks(nbs, temp, temp, formats=formats)
        fLOG("*****", len(res))
        for _ in res:
            fLOG(_)
            self.assertExists(_[0])

        with open(os.path.join(temp,
                               "seance5_approche_fonctionnelle_correction.py"),
                  "r",
                  encoding="utf8") as f:
            content = f.read()
        exp = "# -*- coding: utf-8 -*-"
        if exp not in content:
            raise Exception(content)
Пример #38
0
    def a_te_st_notebook(self, iteration):
        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")
        self.assertExists(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_pyquickhelper2html.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() in ('travis', 'appveyor'):
            # It requires pandoc.
            return

        res = process_notebooks(
            nb, temp, temp, latex_path=p1, pandoc_path=p2, formats=formats)
        for _ in res:
            fLOG(_)
            self.assertExists(_[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)
        self.assertTrue(os.path.exists(file))

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