Example #1
0
    def test_jenkins_job_verif(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(os.path.join(
            this, "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            yml = os.path.abspath(os.path.join(
                this, "..", "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            raise FileNotFoundError(yml)
        context = dict(Python34=None, Python35=os.path.dirname(sys.executable),
                       Python36=os.path.dirname(sys.executable),
                       Python27=None, Anaconda3=None, Anaconda2=None,
                       WinPython35=None, project_name="pyquickhelper",
                       root_path="ROOT")
        obj, name = load_yaml(yml, context=context)
        for k, v in obj.items():
            fLOG(k, type(v), v)
        assert "python" in obj
        assert isinstance(obj["python"], list)
        assert name is not None
Example #2
0
    def test_bug_exe(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        command = "dir" if sys.platform.startswith("win32") else "ls"
        yml = """
        language: python
        python:
            - {{Python35}}
        before:
            - %s
        after_script:
            - %s {{PLATFORM}}
        script:
            - %s
        """ % (command, command, command)
        context = dict(Python34="fake", Python35=os.path.dirname(sys.executable),
                       Python27=None, Anaconda3=None, Anaconda2=None,
                       WinPython35=None, project_name="pyquickhelper",
                       root_path="ROOT", PLATFORM="win")
        obj, name = load_yaml(yml, context=context)
        assert name is not None
        try:
            res = list(enumerate_convert_yaml_into_instructions(
                obj, variables=context))
            assert False
            assert res
        except ValueError as e:
            assert "'before'" in str(e)
Example #3
0
    def zz_st_jconvert_sequence_into_batch_file_split2(self, platform):
        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(os.path.join(
            this, "data", "local2.yml"))
        if not os.path.exists(yml):
            raise FileNotFoundError(yml)
        context = dict(Python35="py35", Python36="C:\\Python36_x64",
                       Python27="py27", Anaconda3="ana3", Anaconda2="ana2",
                       project_name="pyquickhelper", root_path="ROOT")
        obj, name = load_yaml(yml, context=context, platform=platform)
        assert name is not None
        res = list(enumerate_convert_yaml_into_instructions(
            obj, add_environ=False))
        convs = []
        for r, v in res:
            conv = convert_sequence_into_batch_file(
                r, variables=v, platform=platform)
            if not isinstance(conv, list):
                raise TypeError(str(type(conv)) + "\n" + str(conv))
            convs.append(conv)
        assert len(res) > 0

        self.assertEqual(len(convs), 17)
        for conv in convs:
            assert conv
            assert isinstance(conv, list)
            fr = 0
            for c in conv:
                if "JENKINS_SPLIT" in c:
                    raise Exception(c)
                if "pip freeze" in c:
                    fr += 1
            self.assertEqual(fr, 2)
Example #4
0
    def test_exe(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        command = "dir" if sys.platform.startswith("win32") else "ls"
        yml = """
        language: python
        python:
            - {{Python35}}
        before_script:
            - %s
        after_script:
            - %s {{PLATFORM}}
        script:
            - %s
        """ % (command, command, command)
        temp = get_temp_folder(__file__, "temp_yaml_exe")
        context = dict(Python34="fake", Python35=os.path.dirname(sys.executable),
                       Python27=None, Anaconda3=None, Anaconda2=None,
                       WinPython35=None, project_name="pyquickhelper",
                       root_path="ROOT", PLATFORM="win")
        obj, name = load_yaml(yml, context=context)
        assert name is not None
        res = list(enumerate_convert_yaml_into_instructions(
            obj, variables=context))
        for r, var in res:
            conv = convert_sequence_into_batch_file(r, variables=var)
            assert ("%s " % command) in conv
            fLOG("####", conv)
            ext = "bat" if command == "dir" else "sh"
            name = os.path.join(temp, "yml.%s" % ext)
            with open(name, "w") as f:
                f.write(conv)
            if is_travis_or_appveyor() == "travis":
                warnings.warn("Test disabled on travis")
            else:
                out, err = run_cmd(name, wait=True)
                fLOG("###")
                fLOG(out)
                if "BEFORE_SCRIPT" not in out:
                    raise Exception(
                        "{0}\nERR\n{2}\n#########\n{1}".format(out, conv, err))
                if "AFTER_SCRIPT" not in out:
                    raise Exception(
                        "{0}\nERR\n{2}\n#########\n{1}".format(out, conv, err))
                if "SCRIPT" not in out:
                    raise Exception(
                        "{0}\nERR\n{2}\n#########\n{1}".format(out, conv, err))
Example #5
0
    def test_jenkins_job_multiplication(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(os.path.join(
            this, "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            yml = os.path.abspath(os.path.join(
                this, "..", "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            raise FileNotFoundError(yml)
        context = dict(Python34="fake", Python35=os.path.dirname(sys.executable) + "35",
                       Python36=os.path.dirname(sys.executable) + "36",
                       Python27="fake2", Anaconda3=None, Anaconda2=None,
                       WinPython35=None, root_path="ROOT")
        obj, name = load_yaml(yml, context=context, platform="win")
        assert name is not None
        res = list(enumerate_convert_yaml_into_instructions(
            obj, add_environ=False))

        for r, v in res:
            if None in r:
                raise Exception(r)
            if r[0][0] != "python" and r[0][0] != "INFO":
                raise Exception(r)
        if len(res) != 7:
            rows = [str(_) for _ in res]
            raise Exception("\n".join(rows))

        doc = [[s[0] for s in seq if s[1] is not None] for seq, _ in res]
        fLOG(doc)
        doc = [s for s in doc if "documentation" in s]
        if len(doc) != 2:
            raise Exception("\n".join(str(_) for _ in doc))
        else:
            fLOG("**", doc)
Example #6
0
    def test_jconvert_sequence_into_batch_file27(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        platform = "win"
        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(os.path.join(
            this, "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            yml = os.path.abspath(os.path.join(
                this, "..", "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            raise FileNotFoundError(yml)
        context = dict(Python34=None, Python35="C:\\Python35_x64",
                       Python36="C:\\Python36_x64",
                       Python27="C:\\Python27_x64", Anaconda3=None, Anaconda2=None,
                       WinPython35=None, project_name="pyquickhelper",
                       root_path="ROOT")
        obj, name = load_yaml(yml, context=context, platform=platform)
        assert name is not None
        res = list(enumerate_convert_yaml_into_instructions(
            obj, add_environ=False))
        convs = []
        for r, v in res:
            conv = convert_sequence_into_batch_file(
                r, variables=v, platform=platform)
            typstr = str  # unicode#
            if not isinstance(conv, typstr):
                raise TypeError(type(conv))
            convs.append(conv)
        fLOG("number of jobs", len(res))
        convs = [_ for _ in convs if "VERSION=2.7" in _]
        assert len(convs) > 0
        conv = convs[0]

        if platform.startswith("win"):
            expected = """
            @echo off
            set PATH0=%PATH%
            SET DIST=std
            SET VERSION=2.7
            SET NAME=UT
            SET TIMEOUT=900
            @echo interpreter=C:\\Python27_x64\\python

            @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\%NAME_JENKINS%\\_venv
            if not exist "ROOT\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\%NAME_JENKINS%\\_venv"
            "C:\\Python27_x64\\Scripts\\virtualenv" --system-site-packages "ROOT\\%NAME_JENKINS%\\_venv"
            if %errorlevel% neq 0 exit /b %errorlevel%

            @echo INSTALL
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper --extra-index-url=https://pypi.python.org/simple/
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip install -r requirements.txt
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip freeze
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip freeze > pip_freeze.txt
            if %errorlevel% neq 0 exit /b %errorlevel%

            @echo BEFORE_SCRIPT
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            pip install jyquickhelper==0.1.26
            if %errorlevel% neq 0 exit /b %errorlevel%
            C:\\Python35_x64\\python -u setup.py copy27
            if %errorlevel% neq 0 exit /b %errorlevel%
            cd dist_module27
            if %errorlevel% neq 0 exit /b %errorlevel%
            set JOB_NAME=UT

            @echo SCRIPT
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            python -u setup.py unittests
            if %errorlevel% neq 0 exit /b %errorlevel%

            @echo AFTER_SCRIPT
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            python -u setup.py bdist_wheel
            if %errorlevel% neq 0 exit /b %errorlevel%
            copy dist\\*.whl ..\\..\\..\\local_pypi\\local_pypi_server
            if %errorlevel% neq 0 exit /b %errorlevel%
            cd ..
            if %errorlevel% neq 0 exit /b %errorlevel%
            """.replace("            ", "").strip("\n \t\r")
            val = conv.strip("\n \t\r")
            if expected != val:
                mes = "EXP:\n{0}\n###########\nGOT:\n{1}".format(expected, val)
                for a, b in zip(expected.split("\n"), val.split("\n")):
                    if a != b:
                        raise Exception(
                            "error on line:\nEXP:\n{0}\nGOT:\n{1}\n#######\n{2}".format(a, b, mes))
                raise Exception(mes)
Example #7
0
    def zz_st_jconvert_sequence_into_batch_file(self, platform):
        this = os.path.abspath(os.path.dirname(__file__))
        yml = os.path.abspath(os.path.join(
            this, "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            yml = os.path.abspath(os.path.join(
                this, "..", "..", "..", ".local.jenkins.win.yml"))
        if not os.path.exists(yml):
            raise FileNotFoundError(yml)
        context = dict(Python34="fake", Python35="C:\\Python35_x64",
                       Python36="C:\\Python36_x64",
                       Python27=None, Anaconda3=None, Anaconda2=None,
                       WinPython35=None, project_name="pyquickhelper",
                       root_path="ROOT")
        obj, name = load_yaml(yml, context=context, platform=platform)
        assert name is not None
        res = list(enumerate_convert_yaml_into_instructions(
            obj, add_environ=False))
        convs = []
        for r, v in res:
            conv = convert_sequence_into_batch_file(
                r, variables=v, platform=platform)
            convs.append(conv)
            typstr = str  # unicode#
            assert isinstance(conv, typstr)
        assert len(res) > 0

        conv = [_ for _ in convs if "SET NAME=UT" in _ and "VERSION=3.5" in _]
        if len(conv) != 2:
            rows = [str(_) for _ in conv]
            raise Exception("\n".join(rows))
        conv = conv[0]
        if platform.startswith("win"):
            expected = """
            @echo off
            set PATH0=%PATH%
            SET DIST=std
            SET VERSION=3.5
            SET NAME=UT
            SET TIMEOUT=900
            @echo interpreter=C:\\Python35_x64\\python

            @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\%NAME_JENKINS%\\_venv
            if not exist "ROOT\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\%NAME_JENKINS%\\_venv"
            "C:\\Python35_x64\\Scripts\\virtualenv" --system-site-packages "ROOT\\%NAME_JENKINS%\\_venv"
            if %errorlevel% neq 0 exit /b %errorlevel%

            @echo INSTALL
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper --extra-index-url=https://pypi.python.org/simple/
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip install -r requirements.txt
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip freeze
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip freeze > pip_freeze.txt
            if %errorlevel% neq 0 exit /b %errorlevel%
            set JOB_NAME=UT

            @echo SCRIPT
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            python -u setup.py unittests
            if %errorlevel% neq 0 exit /b %errorlevel%

            @echo AFTER_SCRIPT
            set PATH=ROOT\%NAME_JENKINS%\_venv\Scripts;%PATH%
            python -u setup.py bdist_wheel
            if %errorlevel% neq 0 exit /b %errorlevel%
            copy dist\*.whl ..\..\local_pypi\local_pypi_server
            if %errorlevel% neq 0 exit /b %errorlevel%

            @echo DOCUMENTATION
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            python -u setup.py build_sphinx
            if %errorlevel% neq 0 exit /b %errorlevel%
            xcopy /E /C /I /Y _doc\\sphinxdoc\\build\\html dist\\html
            if %errorlevel% neq 0 exit /b %errorlevel%
            """.replace("            ", "").strip("\n \t\r")
            val = conv.strip("\n \t\r")
            if expected != val:
                mes = "EXP:\n{0}\n###########\nGOT:\n{1}".format(expected, val)
                for a, b in zip(expected.split("\n"), val.split("\n")):
                    if a != b:
                        raise Exception(
                            "error on line:\nEXP:\n{0}\nGOT:\n{1}\n#######\n{2}".format(a, b, mes))
                raise Exception(mes)

        conv = [_ for _ in convs if "SET NAME=DOC" in _]
        if len(conv) != 1:
            raise Exception("################################".format(conv))
        conv = conv[0]
        if platform.startswith("win"):
            expected = """
            @echo off
            set PATH0=%PATH%
            SET DIST=std
            SET VERSION=3.5
            SET NAME=DOC
            @echo interpreter=C:\\Python35_x64\\python

            @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\%NAME_JENKINS%\\_venv
            if not exist "ROOT\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\%NAME_JENKINS%\\_venv"
            "C:\\Python35_x64\\Scripts\\virtualenv" --system-site-packages "ROOT\\%NAME_JENKINS%\\_venv"
            if %errorlevel% neq 0 exit /b %errorlevel%

            @echo INSTALL
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper --extra-index-url=https://pypi.python.org/simple/
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip install -r requirements.txt
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip freeze
            if %errorlevel% neq 0 exit /b %errorlevel%
            pip freeze > pip_freeze.txt
            if %errorlevel% neq 0 exit /b %errorlevel%
            set JOB_NAME=DOC

            @echo SCRIPT
            set PATH=ROOT\\%NAME_JENKINS%\\_venv\\Scripts;%PATH%
            python -u setup.py build_sphinx
            if %errorlevel% neq 0 exit /b %errorlevel%

            @echo AFTER_SCRIPT
            set PATH=ROOT\%NAME_JENKINS%\_venv\Scripts;%PATH%
            python -u setup.py bdist_wheel
            if %errorlevel% neq 0 exit /b %errorlevel%
            """.replace("            ", "").strip("\n \t\r")
            val = conv.strip("\n \t\r")
            if expected != val:
                mes = "EXP:\n{0}\n###########\nGOT:\n{1}".format(expected, val)
                for a, b in zip(expected.split("\n"), val.split("\n")):
                    if a != b:
                        raise Exception(
                            "error on line:\nEXP:\n{0}\nGOT:\n{1}\n#######\n{2}".format(a, b, mes))
                raise Exception(mes)