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

import sys
import os
import unittest


try:
    import src
except ImportError:
    path = os.path.normpath(
        os.path.abspath(
            os.path.join(
                os.path.split(__file__)[0],
                "..",
                "..")))
    if path not in sys.path:
        sys.path.append(path)
    import src

from src.pyquickhelper.pycode import ExtTestCase, skipif_vless
from src.pyquickhelper.helpgen.utils_sphinx_config import ie_layout_html, NbImage
from src.pyquickhelper.helpgen.post_process import remove_character_under32
from src.pyquickhelper.helpgen.utils_sphinx_doc import useless_class_UnicodeStringIOThreadSafe, doc_checking
from src.pyquickhelper.helpgen.sphinxm_mock_app import MockSphinxApp
from src.pyquickhelper.helpgen.default_conf import get_default_stylesheet, get_default_javascript, custom_setup
from src.pyquickhelper.helpgen.utils_sphinx_doc_helpers import example_function_latex
from src.pyquickhelper.helpgen._fake_function_to_documentation import f1, f2, f3, f4, f5, f6
from src.pyquickhelper.helpgen.sphinx_main import _import_conf_extract_parameter
from src.pyquickhelper.helpgen.sphinx_helper import everything_but_python


class TestMissingFunctionsHelpgen(ExtTestCase):

    def test_ie(self):
        if not sys.platform.startswith("win"):
            return

        if not ie_layout_html():
            self.fLOG(OutputPrint=__name__ == "__main__")
            self.fLOG("The output is not optimized for IE.")

    def test_nb_image(self):
        r = NbImage("completion.png")
        self.assertTrue(r is not None)

    def test_remove_character_under32(self):
        s = "a\na\r"
        s2 = remove_character_under32(s)
        self.assertEqual(s2, 'a a ')

    def test_utils_sphinx_doc(self):
        useless_class_UnicodeStringIOThreadSafe()
        doc_checking()

    def test_default_conf(self):
        self.assertNotEmpty(get_default_stylesheet())
        self.assertNotEmpty(get_default_javascript())
        app = MockSphinxApp.create()[0]
        res = custom_setup(app, "x")
        self.assertNotEmpty(res)

    def test_example_function_latex(self):
        example_function_latex()

    def test_fake(self):
        f1(3, 4)
        f2(3, 4)
        f3(3, 4)
        f4(3, 4)
        f5(3, 4)
        f6(3, 4)

    @skipif_vless((3, 6), "AttributeError: 'PosixPath' object has no attribute 'rfind'")
    def test_sphinx_main(self):
        all_tocs, build_paths, parameters, html_static_paths = [], [], [], []
        root = os.path.join(os.path.dirname(__file__), '..',
                            '..', '_doc', 'sphinxdoc', 'source')
        root = os.path.normpath(os.path.abspath(root))
        self.assertExists(root)
        folds = root
        root = os.path.join(folds, '..', '..', '..')
        root_source = os.path.join(folds, '..', 'source')
        build = os.path.join(folds, '..', 'build')
        _import_conf_extract_parameter(root, root_source, folds, build, "",
                                       all_tocs, build_paths, parameters,
                                       html_static_paths, None)
        self.assertNotEmpty(all_tocs)
        self.assertNotEmpty(build_paths)
        self.assertNotEmpty(parameters)
        self.assertNotEmpty(html_static_paths)

    def test_everything_but_python(self):
        self.assertFalse(everything_but_python('__pycache__/u.py'))
        self.assertFalse(everything_but_python('u.pyc'))
        self.assertFalse(everything_but_python('u.py'))
        self.assertTrue(everything_but_python('u.pfy'))


if __name__ == "__main__":
    unittest.main()<commit_msg>add test<commit_after>"""
@brief      test log(time=8s)
@author     <NAME>
"""

import sys
import os
import unittest


try:
    import src
except ImportError:
    path = os.path.normpath(
        os.path.abspath(
            os.path.join(
                os.path.split(__file__)[0],
                "..",
                "..")))
    if path not in sys.path:
        sys.path.append(path)
    import src

from src.pyquickhelper.pycode import ExtTestCase, skipif_vless
from src.pyquickhelper.helpgen.utils_sphinx_config import ie_layout_html, NbImage
from src.pyquickhelper.helpgen.post_process import remove_character_under32
from src.pyquickhelper.helpgen.utils_sphinx_doc import useless_class_UnicodeStringIOThreadSafe, doc_checking
from src.pyquickhelper.helpgen.sphinxm_mock_app import MockSphinxApp
from src.pyquickhelper.helpgen.default_conf import get_default_stylesheet, get_default_javascript, custom_setup
from src.pyquickhelper.helpgen.utils_sphinx_doc_helpers import example_function_latex
from src.pyquickhelper.helpgen._fake_function_to_documentation import f1, f2, f3, f4, f5, f6
from src.pyquickhelper.helpgen.sphinx_main import _import_conf_extract_parameter
from src.pyquickhelper.helpgen.sphinx_helper import everything_but_python


class TestMissingFunctionsHelpgen(ExtTestCase):

    def test_ie(self):
        if not sys.platform.startswith("win"):
            return

        if not ie_layout_html():
            self.fLOG(OutputPrint=__name__ == "__main__")
            self.fLOG("The output is not optimized for IE.")

    def test_nb_image(self):
        r = NbImage("completion.png")
        self.assertTrue(r is not None)

    def test_remove_character_under32(self):
        s = "a\na\r"
        s2 = remove_character_under32(s)
        self.assertEqual(s2, 'a a ')

    def test_utils_sphinx_doc(self):
        useless_class_UnicodeStringIOThreadSafe()
        doc_checking()

    def test_default_conf(self):
        self.assertNotEmpty(get_default_stylesheet())
        self.assertNotEmpty(get_default_javascript())
        app = MockSphinxApp.create()[0]
        res = custom_setup(app, "x")
        self.assertNotEmpty(res)

    def test_example_function_latex(self):
        example_function_latex()

    def test_fake(self):
        f1(3, 4)
        f2(3, 4)
        f3(3, 4)
        f4(3, 4)
        f5(3, 4)
        f6(3, 4)

    @skipif_vless((3, 6), "AttributeError: 'PosixPath' object has no attribute 'rfind'")
    def test_sphinx_main(self):
        all_tocs, build_paths, parameters, html_static_paths = [], [], [], []
        root = os.path.join(os.path.dirname(__file__), '..',
                            '..', '_doc', 'sphinxdoc', 'source')
        root = os.path.normpath(os.path.abspath(root))
        self.assertExists(root)
        folds = root
        root = os.path.join(folds, '..', '..', '..')
        root_source = os.path.join(folds, '..', 'source')
        build = os.path.join(folds, '..', 'build')
        _import_conf_extract_parameter(root, root_source, folds, build, "",
                                       all_tocs, build_paths, parameters,
                                       html_static_paths, None)
        self.assertNotEmpty(all_tocs)
        self.assertNotEmpty(build_paths)
        self.assertNotEmpty(parameters)
        self.assertNotEmpty(html_static_paths)
        self.assertNotIn('conf', sys.modules)

    def test_everything_but_python(self):
        self.assertFalse(everything_but_python('__pycache__/u.py'))
        self.assertFalse(everything_but_python('u.pyc'))
        self.assertFalse(everything_but_python('u.py'))
        self.assertTrue(everything_but_python('u.pfy'))


if __name__ == "__main__":
    unittest.main()
{'fraction_non_alphanumeric': 0.10930516050386022, 'fraction_numerical': 0.010023025870242449, 'mean_word_length': 2.882229232386961, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7146247', 'n_tokens_mistral': 2430, 'n_tokens_neox': 2359, 'n_words': 410}