"""
@brief      test log(time=170s)

notebook test
"""

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_

from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, add_missing_development_version


class TestNotebookRunner2a_1 (unittest.TestCase):

    def setUp(self):
        fLOG("add missing dependencies", OutputPrint=__name__ == "__main__")
        add_missing_development_version(
            ["pyensae", "pymyinstall", "pymmails", "jyquickhelper"], __file__)

    def test_notebook_runner(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        from src.ensae_teaching_cs.automation.notebook_test_helper import ls_notebooks, execute_notebooks
        from src.ensae_teaching_cs.automation.notebook_test_helper import clean_function_1a
        temp = get_temp_folder(__file__, "temp_notebook2a_1")
        keepnote = ls_notebooks("td2a")
        execute_notebooks(temp, keepnote, (lambda i, n: "_1" in n),
                          clean_function=clean_function_1a, fLOG=fLOG, dump=src.ensae_teaching_cs)


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

@@ -86,16 +86,30 @@
 nittest%0A
+import shutil%0A
 %0A%0Atry:%0A 
@@ -1637,16 +1637,284 @@
 %22td2a%22)%0A
+        fold = os.path.dirname(keepnote%5B0%5D)%0A        for png in os.listdir(fold):%0A            if %22.png%22 not in png:%0A                continue%0A            fLOG(%22copy%22, png)%0A            shutil.copy(os.path.join(fold, png), temp)%0A        self.assertTrue(len(keepnote) %3E 0)%0A
         

fix missing image in unit test