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

You should indicate a time in seconds. The program ``run_unittests.py``
will sort all test files by increasing time and run them.
"""


import sys
import os
import unittest


try:
    import src
    import pyquickhelper as skip_
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)
    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 src
    import pyquickhelper as skip_

from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, is_travis_or_appveyor
from src.pyensae.file_helper import run_jython, is_java_installed, download_java_standalone
from src.pyensae.remote.magic_azure import MagicAzure
from src.pyensae.file_helper.magic_file import MagicFile


class TestJython (unittest.TestCase):

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

        if is_travis_or_appveyor():
            return

        download_java_standalone()
        assert is_java_installed()

        this = os.path.abspath(os.path.dirname(__file__))
        temp = os.path.join(this, "temp_jython")
        if not os.path.exists(temp):
            os.mkdir(temp)

        jyt = os.path.join(temp, "jy1.py")
        with open(jyt, "w", encoding="utf8") as f:
            f.write('print("first try with jython")')

        out, err = run_jython(jyt, fLOG=fLOG)
        if "first try with jython" not in out:
            raise Exception("OUT:\n{0}\nERR:\n{1}\n".format(out, err))

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

        if "travis" in sys.executable:
            return

        download_java_standalone()
        assert is_java_installed()

        this = os.path.abspath(os.path.dirname(__file__))
        temp = os.path.join(this, "temp_jython")
        if not os.path.exists(temp):
            os.mkdir(temp)

        jyt = os.path.join(temp, "jy2.py")
        with open(jyt, "w", encoding="utf8") as f:
            f.write('''
                            if __name__ != '__lib__':
                                def outputSchema(dont_care):
                                    def wrapper(func):
                                        def inner(*args, **kwargs):
                                            return func(*args, **kwargs)
                                        return inner
                                    return wrapper

                            import datetime<commit_msg>disable a unit test on appveyor<commit_after>"""
@brief      test log(time=2s)

You should indicate a time in seconds. The program ``run_unittests.py``
will sort all test files by increasing time and run them.
"""


import sys
import os
import unittest


try:
    import src
    import pyquickhelper as skip_
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)
    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 src
    import pyquickhelper as skip_

from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, is_travis_or_appveyor
from src.pyensae.file_helper import run_jython, is_java_installed, download_java_standalone
from src.pyensae.remote.magic_azure import MagicAzure
from src.pyensae.file_helper.magic_file import MagicFile


class TestJython (unittest.TestCase):

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

        if is_travis_or_appveyor():
            return

        download_java_standalone()
        assert is_java_installed()

        this = os.path.abspath(os.path.dirname(__file__))
        temp = os.path.join(this, "temp_jython")
        if not os.path.exists(temp):
            os.mkdir(temp)

        jyt = os.path.join(temp, "jy1.py")
        with open(jyt, "w", encoding="utf8") as f:
            f.write('print("first try with jython")')

        out, err = run_jython(jyt, fLOG=fLOG)
        if "first try with jython" not in out:
            raise Exception("OUT:\n{0}\nERR:\n{1}\n".format(out, err))

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

        if is_travis_or_appveyor():
            # to avoid timeout on appveyor
            return

        download_java_standalone()
        assert is_java_installed()

        this = os.path.abspath(os.path.dirname(__file__))
        temp = os.path.join(this, "temp_jython")
        if not os.path.exists(temp):
            os.mkdir(temp)

        jyt = os.path.join(temp, "jy2.py")
        with open(jyt, "w", encoding="utf8") as f:
            f.write('''
                            if __name__ != '__lib__':
                                def outputSchema(dont_care):
                                    def wrapper(func):
                                        def inner(*args, **kwargs):
                                            return func(*args, **kwargs)
                                        return inner
                                    return wrapper

                            import datetime
{'fraction_non_alphanumeric': 0.10188189487345879, 'fraction_numerical': 0.0029201817001946787, 'mean_word_length': 1.6312419974391805, 'pattern_counts': {'":': 0, '<': 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': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4020860', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1784, 'n_words': 405}