# -*- coding: utf-8 -*-
"""
@brief      test log(time=42s)
"""

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.loghelper import fLOG
from src.pyquickhelper.pycode import get_temp_folder, skipif_travis
from src.pyquickhelper.ipythonhelper import execute_notebook_list, execute_notebook_list_finalize_ut


class TestSKIPRunNotebooks(unittest.TestCase):

    def test_src_import(self):
        """for pylint"""
        self.assertTrue(src is not None)

    @unittest.skipIf(sys.version_info[0] == 2, reason="notebooks are not converted into python 2.7, so not tested")
    @skipif_travis("does not complete")
    def test_skip_run_notebook(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        temp = get_temp_folder(__file__, "temp_skip_run_notebooks_pyq_long")

        fnb = os.path.normpath(os.path.join(
            os.path.abspath(os.path.dirname(__file__)), "..", "..", "_doc", "notebooks"))
        keepnote = []
        for f in os.listdir(fnb):
            if os.path.splitext(f)[-1] == ".ipynb":
                if "javascript" in f:
                    keepnote.append(os.path.join(fnb, f))
                if "git_data" in f and os.environ.get("PYINT", "") == "python3.7":
                    # the notebook on git takes for ever
                    keepnote.append(os.path.join(fnb, f))
        self.assertTrue(len(keepnote) > 0)

        def valid(cell):
            if "git log --log-size --abbrev --follow" in cell:
                return False
            return True

        import jyquickhelper
        addpaths = [os.path.normpath(os.path.join(
            os.path.abspath(os.path.dirname(__file__)), "..", "..", "src")),
            os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(jyquickhelper.__file__)), ".."))]

        res = execute_notebook_list(
            temp, keepnote, fLOG=fLOG, valid=valid, additional_path=addpaths)
        execute_notebook_list_finalize_ut(
            res, fLOG=fLOG, dump=src.pyquickhelper)


if __name__ == "__main__":
    unittest.main()

@@ -482,24 +482,9 @@
 lder
-, skipif_travis
 %0A
+
 from
@@ -736,177 +736,21 @@
     
-@unit
+def 
 test
-.
+_
 skip
-If(sys.version_info%5B0%5D == 2, reason=%22notebooks are not converted into python 2.7, so not tested%22)%0A    @skipif_travis(%22does not complete%22)%0A    def test_skip
 _run
@@ -758,16 +758,27 @@
 notebook
+_javascript
 (self):%0A
@@ -1325,139 +1325,1229 @@
     
-        if %22git_data%22 in f and os.environ.get(%22PYINT%22, %22%22) == %22python3.7%22:%0A                    # the notebook on git takes for ever
+self.assertTrue(len(keepnote) %3E 0)%0A%0A        def valid(cell):%0A            return True%0A%0A        import jyquickhelper%0A        addpaths = %5Bos.path.normpath(os.path.join(%0A            os.path.abspath(os.path.dirname(__file__)), %22..%22, %22..%22, %22src%22)),%0A            os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(jyquickhelper.__file__)), %22..%22))%5D%0A%0A        try:%0A            res = execute_notebook_list(%0A                temp, keepnote, fLOG=fLOG, valid=valid, additional_path=addpaths)%0A            execute_notebook_list_finalize_ut(%0A                res, fLOG=fLOG, dump=src.pyquickhelper)%0A        except PermissionError as e:%0A            warnings.warn(%22Unable to test this notebook due to %22 + str(e))%0A%0A    def test_skip_run_notebook_git(self):%0A        fLOG(%0A            __file__,%0A            self._testMethodName,%0A            OutputPrint=__name__ == %22__main__%22)%0A%0A        temp = get_temp_folder(__file__, %22temp_skip_run_notebooks_pyq_long%22)%0A%0A        fnb = os.path.normpath(os.path.join(%0A            os.path.abspath(os.path.dirname(__file__)), %22..%22, %22..%22, %22_doc%22, %22notebooks%22))%0A        keepnote = %5B%5D%0A        for f in os.listdir(fnb):%0A            if os.path.splitext(f)%5B-1%5D == %22.ipynb%22:%0A                if %22git_data%22 in f:
 %0A   

Split unit tests