<commit_before>"""
@brief      test log(time=35s)
@author     <NAME>
"""

import sys
import os
import unittest

from pyquickhelper.loghelper import fLOG
from pyquickhelper.helpgen.sphinx_main import process_notebooks
from pyquickhelper.helpgen.sphinx_main import setup_environment_for_help
from pyquickhelper.helpgen.post_process import post_process_latex
from pyquickhelper.pycode import is_travis_or_appveyor, ExtTestCase


class TestNoteBooksBugSvg(ExtTestCase):

    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)

    def test_replace_includgraphics(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        text = """\\usepackage{multirow}<commit_msg>disable one test on circleci<commit_after>"""
@brief      test log(time=35s)
@author     <NAME>
"""

import sys
import os
import unittest

from pyquickhelper.loghelper import fLOG
from pyquickhelper.helpgen.sphinx_main import process_notebooks
from pyquickhelper.helpgen.sphinx_main import setup_environment_for_help
from pyquickhelper.helpgen.post_process import post_process_latex
from pyquickhelper.pycode import is_travis_or_appveyor, ExtTestCase


class TestNoteBooksBugSvg(ExtTestCase):

    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()

        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)

    def test_replace_includgraphics(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        text = """\\usepackage{multirow}
{'fraction_non_alphanumeric': 0.11432009626955475, 'fraction_numerical': 0.01058965102286402, 'mean_word_length': 2.552136752136752, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7312611', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1330, 'n_words': 262}