<commit_before># -*- coding: utf-8 -*-
"""
@brief      test log(time=183s)
"""

import sys
import os
import unittest
import shutil
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, is_travis_or_appveyor, add_missing_development_version

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


class TestNotebookRunner2aEcoNLP(unittest.TestCase):

    def setUp(self):
        add_missing_development_version(["pymyinstall", "pyensae", "pymmails", "jyquickhelper"],
                                        __file__, hide=True)

    def common_notebook_runner_2a_eco_nlp_enonce(self, sub):
        from src.ensae_teaching_cs.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_1a
        temp = get_temp_folder(__file__, "temp_notebook2a_eco_nlp_" + sub)
        keepnote = ls_notebooks("td2a_eco")
        if sub == "correction":
            folder = os.path.join(temp, "ressources_googleplus")
            os.mkdir(folder)
            folder_note = os.path.split(keepnote[0])[0]
            jsfile = os.path.join(
                folder_note, "ressources_googleplus", "107033731246200681024.json")
            shutil.copy(jsfile, folder)

        def filter(i, n):
            if "Traitement_automatique" not in n:
                return False
            if sub == "enonce":
                if "correction" in n:
                    return False
            elif sub not in n:
                return False
            return True

        res = execute_notebooks(temp, keepnote,
                                filter,
                                fLOG=fLOG,
                                clean_function=clean_function_1a,
                                dump=src.ensae_teaching_cs)
        return res

    def test_notebook_runner_2a_eco_nlp_enonce(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        if is_travis_or_appveyor():
            # requires credentials
            return
        self.common_notebook_runner_2a_eco_nlp_enonce("enonce")

    def test_notebook_runner_2a_eco_nlp_correction(self):<commit_msg>Update test_2A_notebook_eco_nlp.py<commit_after># -*- coding: utf-8 -*-
"""
@brief      test log(time=183s)
"""

import sys
import os
import unittest
import shutil
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, is_travis_or_appveyor, add_missing_development_version

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


class TestNotebookRunner2aEcoNLP(unittest.TestCase):

    def setUp(self):
        add_missing_development_version(["pymyinstall", "pyensae", "pymmails", "jyquickhelper"],
                                        __file__, hide=True)

    def common_notebook_runner_2a_eco_nlp_enonce(self, sub):
        from src.ensae_teaching_cs.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_1a
        temp = get_temp_folder(__file__, "temp_notebook2a_eco_nlp_" + sub)
        keepnote = ls_notebooks("td2a_eco")
        if sub in ("correction", "enonce"):
            folder = os.path.join(temp, "ressources_googleplus")
            os.mkdir(folder)
            folder_note = os.path.split(keepnote[0])[0]
            jsfile = os.path.join(
                folder_note, "ressources_googleplus", "107033731246200681024.json")
            shutil.copy(jsfile, folder)

        def filter(i, n):
            if "Traitement_automatique" not in n:
                return False
            if sub == "enonce":
                if "correction" in n:
                    return False
            elif sub not in n:
                return False
            return True

        res = execute_notebooks(temp, keepnote,
                                filter,
                                fLOG=fLOG,
                                clean_function=clean_function_1a,
                                dump=src.ensae_teaching_cs)
        return res

    def test_notebook_runner_2a_eco_nlp_enonce(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        self.common_notebook_runner_2a_eco_nlp_enonce("enonce")

    def test_notebook_runner_2a_eco_nlp_correction(self):
{'fraction_non_alphanumeric': 0.08520461699895068, 'fraction_numerical': 0.015739769150052464, 'mean_word_length': 1.9639303482587065, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3626884', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1447, 'n_words': 267}