<commit_before>"""
@brief      test log(time=2s)

"""


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

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

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

from pyquickhelper.loghelper import fLOG
from pyquickhelper.filehelper import explore_folder
from pyquickhelper.pycode import get_temp_folder
from src.ensae_teaching_cs.homeblog import file_build_rss, CopyFileForFtp, modify_all_posts
from src.ensae_teaching_cs.homeblog import file_all_keywords, build_process_all_pages


class TestHomeBlog(unittest.TestCase):

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

        temp = get_temp_folder(__file__, "temp_home_blog")
        blog = os.path.join(temp, "..", "blog")

        filessite = explore_folder(blog)[1]
        filessite = [_.replace("\\", "/") for _ in filessite]
        if len(filessite) == 0:
            raise Exception("no file found")

        cpf = CopyFileForFtp("copyDates.txt", specificTrigger=True)
        cpf.copy_file_ext(os.path.join(temp, ".."), "py", temp, doFTP=False)
        cpf.copy_file_ext(os.path.join(blog, "javascript"),
                          "js", os.path.join(temp, "javascript"))
        cpf.copy_file_ext(os.path.join(blog, "javascript"),
                          "css", os.path.join(temp, "javascript"))

        files, modified = modify_all_posts(blog, blog, exclude=lambda f: False)
        self.assertTrue(len(files) > 0)
        res = file_build_rss(blog, os.path.join(temp, "xdbrss.xml"))
        rss = res[0]
        self.assertTrue(os.path.exists(rss))
        res = file_all_keywords(blog,
                                mainpage=os.path.join(blog, "xd_blog.html"),
                                outmainpage=os.path.join(blog, "xd_blog.html"),
                                exclude=lambda f: "improbable" in f, allow_temp=True)
        self.assertTrue(len(res) > 0)
        add = build_process_all_pages(res, frequence_keywords=2, siteFolder=temp,
                                      xd_blog_template_nojs=os.path.join(blog, "xd_blog_template_nojs.html"))
        fLOG(add)
        cpf.add_if_modified(__file__)
<commit_msg>update unit test<commit_after>"""
@brief      test log(time=2s)

"""


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

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

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

from pyquickhelper.loghelper import fLOG
from pyquickhelper.filehelper import explore_folder
from pyquickhelper.pycode import get_temp_folder
from src.ensae_teaching_cs.homeblog import file_build_rss, CopyFileForFtp, modify_all_posts
from src.ensae_teaching_cs.homeblog import file_all_keywords, build_process_all_pages


class TestHomeBlog(unittest.TestCase):

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

        temp = get_temp_folder(__file__, "temp_home_blog")
        blog = os.path.abspath(os.path.normpath(os.path.join(temp, "..", "blog")))

        filessite = explore_folder(blog)[1]
        filessite = [_.replace("\\", "/") for _ in filessite]
        if len(filessite) == 0:
            raise Exception("no file found")

        cpf = CopyFileForFtp("copyDates.txt", specificTrigger=True)
        cpf.copy_file_ext(os.path.join(temp, ".."), "py", temp, doFTP=False)
        cpf.copy_file_ext(os.path.join(blog, "javascript"),
                          "js", os.path.join(temp, "javascript"))
        cpf.copy_file_ext(os.path.join(blog, "javascript"),
                          "css", os.path.join(temp, "javascript"))

        files, modified = modify_all_posts(blog, blog, exclude=lambda f: False)
        self.assertTrue(len(files) > 0)
        res = file_build_rss(blog, os.path.join(temp, "xdbrss.xml"))
        rss = res[0]
        self.assertTrue(os.path.exists(rss))
        res = file_all_keywords(blog,
                                mainpage=os.path.join(blog, "xd_blog.html"),
                                outmainpage=os.path.join(blog, "xd_blog.html"),
                                exclude=lambda f: "improbable" in f, allow_temp=True)
        self.assertTrue(len(res) > 0)
        add = build_process_all_pages(res, frequence_keywords=2, siteFolder=temp,
                                      xd_blog_template_nojs=os.path.join(blog, "xd_blog_template_nojs.html"))
        fLOG(add)
        cpf.add_if_modified(__file__)

{'fraction_non_alphanumeric': 0.12077596996245307, 'fraction_numerical': 0.0031289111389236545, 'mean_word_length': 1.9528868360277136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2352569', 'n_tokens_mistral': 2061, 'n_tokens_neox': 1978, 'n_words': 366}