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

import sys
import os
import unittest
import warnings


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.ipythonhelper import read_nb
from src.pyquickhelper.pycode import get_temp_folder, is_travis_or_appveyor
from src.pyquickhelper.loghelper import fLOG


class TestNotebookRunnerOperation (unittest.TestCase):

    def test_notebook_runner_operation(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        if sys.version_info[0] == 2:
            # written in Python 3
            return
        temp = get_temp_folder(__file__, "temp_notebook_operation")

        nbfile = os.path.join(temp, "..", "data", "simple_example.ipynb")
        nbfile2 = os.path.join(
            temp, "..", "data", "td2a_cenonce_session_4B.ipynb")
        if is_travis_or_appveyor() == "travis":
            warnings.warn("This test is not run on travis, it prevents the script from completing.")
            return
        nb1 = read_nb(nbfile, kernel=False)
        n1 = len(nb1)
        nb2 = read_nb(nbfile2, kernel=False)
        n2 = len(nb2)
        add = nb1 + nb2
        nb1.merge_notebook([nb2])
        n3a = len(add)
        n3 = len(nb1)
        if n1 + n2 != n3:
            raise Exception("{0} + {1} != {2}".format(n1, n2, n3))
        if n3a != n3:
            raise Exception("{0} != {1}".format(n3a, n3))

        fLOG(n1, n2, n3, n3a)
        outfile = os.path.join(temp, "merge_nb.ipynb")
        nb1.to_json(outfile)
        assert os.path.exists(outfile)
        outfile = os.path.join(temp, "merge_nb_add.ipynb")
        add.to_json(outfile)
        assert os.path.exists(outfile)


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

@@ -1092,32 +1092,165 @@
 sion_4B.ipynb%22)%0A
+        nb1 = read_nb(nbfile, kernel=False)%0A        n1 = len(nb1)%0A        nb2 = read_nb(nbfile2, kernel=False)%0A        n2 = len(nb2)%0A
         if is_tr
@@ -1405,141 +1405,8 @@
 urn%0A
-        nb1 = read_nb(nbfile, kernel=False)%0A        n1 = len(nb1)%0A        nb2 = read_nb(nbfile2, kernel=False)%0A        n2 = len(nb2)%0A
     

test for travis 7.2002