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

import sys
import os
import unittest
import re

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
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

try:
    import pyensae
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

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

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

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


from pyquickhelper import fLOG, get_temp_folder
from pyquickhelper.jenkinshelper import JenkinsExt
from src.ensae_teaching_cs.automation.jenkins_helper import setup_jenkins_server


class TestJenkins(unittest.TestCase):

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

        engines = dict(anaconda2="C:\\Anaconda2", anaconda3="C:\\Anaconda3",
                       winpython="C:\\WinPython-64bit-3.4.2.3\\python-3.4.2.amd64",
                       default="c:\\Python34_x64")

        js = JenkinsExt('http://machine:8080/', "user",
                        "password", mock=True, engines=engines, fLOG=fLOG)

        if sys.platform.startswith("win"):
            res = setup_jenkins_server(js,
                                       overwrite=True,
                                       location=r"c:\\jenkins\\pymy",
                                       prefix="_node_")
        else:
            modules = [("pyquickhelper", "H H(10-11) * * 0"),
                       ["pymyinstall"],
                       ["pymyinstall [anaconda] [update]",
                           "pymyinstall [anaconda2] [update27]"],
                       ["pyquickhelper [anaconda]",
                        "pyquickhelper [27] [anaconda2]"],
                       ["pyensae", ],
                       ["pymmails", "pysqllike", "pyrsslocal", "pymyinstall [27] [anaconda2]",
                        "python3_module_template", "pyensae [anaconda]", ],
                       ["pymmails [anaconda]", "pysqllike [anaconda]", "pyrsslocal [anaconda]",
                        "python3_module_template [anaconda]", "python3_module_template [27] [anaconda2]",
                        "pymyinstall [all]"],
                       # actuariat
                       [("actuariat_python", "H H(12-13) * * 0")],
                       ["actuariat_python [anaconda]"],
                       # code_beatrix
                       [("code_beatrix", "H H(14-15) * * 0")],
                       ["code_beatrix [anaconda]"],
                       # teachings
                       ("ensae_teaching_cs", "H H(15-16) * * 0"),
                       ["ensae_teaching_cs [anaconda]"],
                       ["ensae_teaching_cs [notebooks]"],
                       ["ensae_teaching_cs [anaconda] [notebooks]", ],
                       ]

            res = setup_jenkins_server(js,
                                       modules=modules,
                                       fLOG=fLOG,
                                       overwrite=True,
                                       location=r"c:\\jenkins\\pymy",
                                       prefix="_node_")
        assert len(res) > 0


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

@@ -3251,1767 +3251,8 @@
     
-    else:%0A            modules = %5B(%22pyquickhelper%22, %22H H(10-11) * * 0%22),%0A                       %5B%22pymyinstall%22%5D,%0A                       %5B%22pymyinstall %5Banaconda%5D %5Bupdate%5D%22,%0A                           %22pymyinstall %5Banaconda2%5D %5Bupdate27%5D%22%5D,%0A                       %5B%22pyquickhelper %5Banaconda%5D%22,%0A                        %22pyquickhelper %5B27%5D %5Banaconda2%5D%22%5D,%0A                       %5B%22pyensae%22, %5D,%0A                       %5B%22pymmails%22, %22pysqllike%22, %22pyrsslocal%22, %22pymyinstall %5B27%5D %5Banaconda2%5D%22,%0A                        %22python3_module_template%22, %22pyensae %5Banaconda%5D%22, %5D,%0A                       %5B%22pymmails %5Banaconda%5D%22, %22pysqllike %5Banaconda%5D%22, %22pyrsslocal %5Banaconda%5D%22,%0A                        %22python3_module_template %5Banaconda%5D%22, %22python3_module_template %5B27%5D %5Banaconda2%5D%22,%0A                        %22pymyinstall %5Ball%5D%22%5D,%0A                       # actuariat%0A                       %5B(%22actuariat_python%22, %22H H(12-13) * * 0%22)%5D,%0A                       %5B%22actuariat_python %5Banaconda%5D%22%5D,%0A                       # code_beatrix%0A                       %5B(%22code_beatrix%22, %22H H(14-15) * * 0%22)%5D,%0A                       %5B%22code_beatrix %5Banaconda%5D%22%5D,%0A                       # teachings%0A                       (%22ensae_teaching_cs%22, %22H H(15-16) * * 0%22),%0A                       %5B%22ensae_teaching_cs %5Banaconda%5D%22%5D,%0A                       %5B%22ensae_teaching_cs %5Bnotebooks%5D%22%5D,%0A                       %5B%22ensae_teaching_cs %5Banaconda%5D %5Bnotebooks%5D%22, %5D,%0A                       %5D%0A%0A            res = setup_jenkins_server(js,%0A                                       modules=modules,%0A                                       fLOG=fLOG,%0A                                       overwrite=True,%0A                                       location=r%22c:%5C%5Cjenkins%5C%5Cpymy%22,%0A                                       prefix=%22_node_%22)%0A
     

disable a unit test on linux