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) self.assertNotEmpty(res) 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)
def zz_st_jconvert_sequence_into_batch_file_split(self, platform): this = os.path.abspath(os.path.dirname(__file__)) yml = os.path.abspath(os.path.join( this, "data", "local.yml")) if not os.path.exists(yml): raise FileNotFoundError(yml) context = dict(Python35="fake", Python36="C:\\Python35_x64", 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(type(conv)) convs.append(conv) assert len(res) > 0 self.assertEqual(len(convs), 2) conv = convs[0] 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 fLOG("-------------------------------") fLOG(c) self.assertEqual(fr, 1)
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 """.replace(" ", "") % (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="win32") obj, name = load_yaml(yml, context=context) self.assertTrue(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) if ("%s " % command) not in conv: raise Exception("{0}\n--\n{1}".format(command, 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": # linux, unable to test TestYamlExe.test_exe. pass else: if sys.platform.startswith("win"): cmd = name else: cmd = "bash " + name try: out, err = run_cmd(cmd, wait=True) except PermissionError as e: raise Exception( "Unable to execute '{0}' which contains\n{1}".format(name, conv)) from e 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))
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", Python37="C:\\Python37_x64", Python38="C:\\Python38_x64", Python39="C:\\Python39_x64", Python27="C:\\Python27_x64", Anaconda3=None, Anaconda2=None, WinPython36=None, project_name="pyquickhelper", root_path="ROOT") vers = "%d%d" % sys.version_info[:2] context["Python%s" % vers] = "C:\\Python%s_x64" % vers obj, name = load_yaml(yml, context=context, platform=platform) self.assertTrue(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 = [jenkins_final_postprocessing( _, True) for _ in convs if "VERSION=2.7" in _] self.assertEqual(len(convs), 0)
def zz_st_jconvert_sequence_into_batch_file(self, platform): this = os.path.abspath(os.path.dirname(__file__)) plat = "win" if platform.startswith("win") else "lin" yml = os.path.abspath(os.path.join( this, "..", "..", ".local.jenkins.%s.yml" % plat)) if not os.path.exists(yml): yml = os.path.abspath(os.path.join( this, "..", "..", "..", ".local.jenkins.%s.yml" % plat)) if not os.path.exists(yml): raise FileNotFoundError(yml) context = dict(Python34="fake", Python35="C:/Python35_x64", Python36="C:/Python36_x64", Python37="C:/Python37_x64", Python38="C:/Python38_x64", Python39="C:/Python39_x64", Python27=None, Anaconda3=None, Anaconda2=None, WinPython36=None, project_name="pyquickhelper", root_path="ROOT") vers = "%d%d" % sys.version_info[:2] context["Python%s" % vers] = "C:/Python%s_x64" % vers if platform.startswith("win"): for k in context: # pylint: disable=C0206 if context[k] is not None: context[k] = context[k].replace("/", "\\") obj, name = load_yaml(yml, context=context, platform=platform) self.assertTrue(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# self.assertTrue(isinstance(conv, typstr)) self.assertTrue(len(res) > 0) set_name = "SET" if platform.startswith("win") else "export" vers_ = "%d.%d" % sys.version_info[:2] conv = [ _ for _ in convs if set_name + " NAME=UT" in _ and "VERSION=%s" % vers_ in _ and '-g' not in _] if len(conv) != 3: vers_ = "3.9" vers = "39" conv = [ _ for _ in convs if set_name + " NAME=UT" in _ and "VERSION=%s" % vers_ in _ and '-g' not in _] if len(conv) not in (3, 4, 5, 6, 7): rows = [str(_) for _ in conv] raise AssertionError( "len(convs)={3}-len(conv)={0}\n----\n{1}\n-----\n{2}\n***\n{4}".format( len(conv), "\n".join(conv), "\n".join(rows), len(convs), "\n*****\n".join(convs))) conv = conv[0] if platform.startswith("win"): expected = """ @echo off set PATH0=%PATH% SET DIST=std SET VERSION=__VERSP__ SET NAME=UT SET TIMEOUT=899 @echo AUTOMATEDSETUP set current=ROOT\\pyquickhelper\\%NAME_JENKINS% @echo interpreter=C:\\Python__VERS___x64\\python @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv if not exist "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" set KEEPPATH=%PATH% set PATH=C:\\Python__VERS___x64;%PATH% "C:\\Python__VERS___x64\\python" -m virtualenv ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv --system-site-packages set PATH=%KEEPPATH% if %errorlevel% neq 0 exit /b %errorlevel% @echo INSTALL set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% pip install --upgrade pip if %errorlevel% neq 0 exit /b %errorlevel% pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper tkinterquickhelper --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 uninstall -y pyquickhelper if %errorlevel% neq 0 exit /b %errorlevel% python --version 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 PYTHONPATH=src if %errorlevel% neq 0 exit /b %errorlevel% set JOB_NAME=UT @echo SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py unittests if %errorlevel% neq 0 exit /b %errorlevel% @echo AFTER_SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% $PYINT -u src\\pyquicksetup\\setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% copy dist\\*.whl ROOT\\pyquickhelper\\..\\..\\local_pypi\\local_pypi_server if %errorlevel% neq 0 exit /b %errorlevel% @echo DOCUMENTATION set PATH=ROOT\\pyquickhelper\\%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") expected = expected.replace("__VERS__", vers) expected = expected.replace("__VERSP__", vers_) 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 + " DIST=std" in _ and "TIMEOUT=899" in _] if len(conv) not in (1, 2): raise Exception( "################################\nlen(conv)={0}\n{1}".format(len(conv), conv)) conv = conv[0] if platform.startswith("win"): expected = """ @echo off set PATH0=%PATH% SET DIST=std SET VERSION=__VERSP__ SET NAME=UT SET TIMEOUT=899 @echo AUTOMATEDSETUP set current=ROOT\\pyquickhelper\\%NAME_JENKINS% @echo interpreter=C:\\Python__VERS___x64\\python @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv if not exist "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" set KEEPPATH=%PATH% set PATH=C:\\Python__VERS___x64;%PATH% "C:\\Python__VERS___x64\\python" -m virtualenv ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv --system-site-packages set PATH=%KEEPPATH% if %errorlevel% neq 0 exit /b %errorlevel% @echo INSTALL set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% pip install --upgrade pip if %errorlevel% neq 0 exit /b %errorlevel% pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper tkinterquickhelper --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 uninstall -y pyquickhelper if %errorlevel% neq 0 exit /b %errorlevel% python --version 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 PYTHONPATH=src if %errorlevel% neq 0 exit /b %errorlevel% set JOB_NAME=UT @echo SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py unittests if %errorlevel% neq 0 exit /b %errorlevel% @echo AFTER_SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% $PYINT -u src\\pyquicksetup\\setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% copy dist\\*.whl ROOT\\pyquickhelper\\..\\..\\local_pypi\\local_pypi_server if %errorlevel% neq 0 exit /b %errorlevel% @echo DOCUMENTATION set PATH=ROOT\\pyquickhelper\\%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") expected = expected.replace("__VERS__", vers) expected = expected.replace("__VERSP__", vers_) 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) else: expected = """ export DIST=std export PYINT=python__VERSP__ export PYTHONPATH=src export VERSION=__VERSP__ export NAME=UT export TIMEOUT=899 echo AUTOMATEDSETUP export current=ROOT/pyquickhelper/$NAME_JENKINS echo interpreter=C:/Python__VERS___x64/$PYINT echo CREATE VIRTUAL ENVIRONMENT in ROOT/pyquickhelper/$NAME_JENKINS/_venv if [-f ROOT/pyquickhelper/$NAME_JENKINS/_venv]; then mkdir "ROOT/pyquickhelper/$NAME_JENKINS/_venv"; fi export KEEPPATH=$PATH export PATH=C:/Python__VERS___x64:$PATH "C:/Python__VERS___x64/$PYINT" -m virtualenv ROOT/pyquickhelper/$NAME_JENKINS/_venv --system-site-packages export PATH=$KEEPPATH if [ $? -ne 0 ]; then exit $?; fi echo INSTALL export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT -m pip install --upgrade pip if [ $? -ne 0 ]; then exit $?; fi $PYINT -m pip install --upgrade --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper tkinterquickhelper --extra-index-url=https://pypi.python.org/simple/ if [ $? -ne 0 ]; then exit $?; fi $PYINT -m pip install --upgrade --no-cache-dir --no-deps --index http://localhost:8067/simple/ pyrsslocal --extra-index-url=https://pypi.python.org/simple/ if [ $? -ne 0 ]; then exit $?; fi $PYINT -m pip install --upgrade --no-cache-dir --no-deps --index http://localhost:8067/simple/ pyensae --extra-index-url=https://pypi.python.org/simple/ if [ $? -ne 0 ]; then exit $?; fi $PYINT -m pip install -r requirements.txt if [ $? -ne 0 ]; then exit $?; fi $PYINT --version if [ $? -ne 0 ]; then exit $?; fi $PYINT -m pip uninstall -y pyquickhelper if [ $? -ne 0 ]; then exit $?; fi $PYINT -m pip freeze if [ $? -ne 0 ]; then exit $?; fi echo BEFORE_SCRIPT export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT setup.py write_version if [ $? -ne 0 ]; then exit $?; fi export JOB_NAME=UT echo SCRIPT export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT -u setup.py unittests --covtoken=69193a28-dc79-4a24-98ed-aedf441a8249 if [ $? -ne 0 ]; then exit $?; fi echo AFTER_SCRIPT export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT -u setup.py bdist_wheel if [ $? -ne 0 ]; then exit $?; fi cp dist/*.whl ROOT/pyquickhelper/../local_pypi/local_pypi_server if [ $? -ne 0 ]; then exit $?; fi echo DOCUMENTATION export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT -u setup.py build_sphinx if [ $? -ne 0 ]; then exit $?; fi cp -R -f _doc/sphinxdoc/build/html dist/html if [ $? -ne 0 ]; then exit $?; fi """.replace(" ", "").strip("\n \t\r") expected = expected.replace("__VERS__", vers) expected = expected.replace("__VERSP__", vers_) 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)
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", Python37="C:\\Python37_x64", Python27="C:\\Python27_x64", Anaconda3=None, Anaconda2=None, WinPython36=None, project_name="pyquickhelper", root_path="ROOT") vers = "%d%d" % sys.version_info[:2] context["Python%s" % vers] = "C:\\Python%s_x64" % vers obj, name = load_yaml(yml, context=context, platform=platform) self.assertTrue(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 = [jenkins_final_postprocessing( _, True) for _ in convs if "VERSION=2.7" in _] self.assertTrue(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=899 @echo AUTOMATEDSETUP set current=ROOT\\pyquickhelper\\%NAME_JENKINS% @echo interpreter=C:\\Python27_x64\\python @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv if not exist "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" set KEEPPATH=%PATH% set PATH=C:\\Python27_x64;%PATH% "C:\\Python27_x64\\python" -c "from virtualenv import create_environment;create_environment(\\"ROOT\\\\pyquickhelper\\\\%NAME_JENKINS%\\\\_venv\\", site_packages=True)" set PATH=%KEEPPATH% if %errorlevel% neq 0 exit /b %errorlevel% @echo INSTALL set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper tkinterquickhelper --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 uninstall -y pyquickhelper if %errorlevel% neq 0 exit /b %errorlevel% python --version 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 PYTHONPATH=src if %errorlevel% neq 0 exit /b %errorlevel% @echo BEFORE_SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% pip uninstall jyquickhelper if %errorlevel% neq 0 exit /b %errorlevel% pip install bin\\jyquickhelper-0.2-py2-none-any.whl if %errorlevel% neq 0 exit /b %errorlevel% C:\\Python37_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\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py unittests if %errorlevel% neq 0 exit /b %errorlevel% @echo AFTER_SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% $PYINT -u src\\pyquicksetup\\setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% copy dist\\*.whl ROOT\\pyquickhelper\\..\\..\\local_pypi\\local_pypi_server if %errorlevel% neq 0 exit /b %errorlevel% @echo DOCUMENTATION set PATH=ROOT\\pyquickhelper\\%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---\n{1}\n---".format( expected, val) for i, (a, b) in enumerate(zip(expected.split("\n"), val.split("\n"))): if a != b: raise Exception( "error on line {3}:\nEXP:\n{0}\nGOT:\n{1}\n#######\n{2}".format(a, b, mes, i)) raise Exception(mes)
def zz_st_jconvert_sequence_into_batch_file(self, platform): this = os.path.abspath(os.path.dirname(__file__)) plat = "win" if platform.startswith("win") else "lin" yml = os.path.abspath(os.path.join( this, "..", "..", ".local.jenkins.%s.yml" % plat)) if not os.path.exists(yml): yml = os.path.abspath(os.path.join( this, "..", "..", "..", ".local.jenkins.%s.yml" % plat)) if not os.path.exists(yml): raise FileNotFoundError(yml) context = dict(Python34="fake", Python35="C:/Python35_x64", Python36="C:/Python36_x64", Python37="C:/Python37_x64", Python27=None, Anaconda3=None, Anaconda2=None, WinPython36=None, project_name="pyquickhelper", root_path="ROOT") vers = "%d%d" % sys.version_info[:2] context["Python%s" % vers] = "C:/Python%s_x64" % vers if platform.startswith("win"): for k in context: if context[k] is not None: context[k] = context[k].replace("/", "\\") obj, name = load_yaml(yml, context=context, platform=platform) self.assertTrue(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# self.assertTrue(isinstance(conv, typstr)) self.assertTrue(len(res) > 0) set_name = "SET" if platform.startswith("win") else "export" vers_ = "%d.%d" % sys.version_info[:2] conv = [ _ for _ in convs if set_name + " NAME=UT" in _ and "VERSION=%s" % vers_ in _ and '-g' not in _] if len(conv) != 3: vers_ = "3.7" vers = "37" conv = [ _ for _ in convs if set_name + " NAME=UT" in _ and "VERSION=%s" % vers_ in _ and '-g' not in _] if len(conv) not in (3, 5, 4, 6, 7): rows = [str(_) for _ in conv] raise Exception("len(convs)={3}-len(conv)={0}\n----\n{1}\n-----\n{2}\n***\n{4}".format( len(conv), "\n".join(conv), "\n".join(rows), len(convs), "\n*****\n".join(convs))) conv = conv[0] if platform.startswith("win"): expected = """ @echo off set PATH0=%PATH% SET DIST=std SET VERSION=__VERSP__ SET NAME=UT SET TIMEOUT=899 @echo AUTOMATEDSETUP set current=ROOT\\pyquickhelper\\%NAME_JENKINS% @echo interpreter=C:\\Python__VERS___x64\\python @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv if not exist "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" set KEEPPATH=%PATH% set PATH=C:\\Python__VERS___x64;%PATH% "C:\\Python__VERS___x64\\python" -c "from virtualenv import create_environment;create_environment(\\"ROOT\\\\pyquickhelper\\\\%NAME_JENKINS%\\\\_venv\\", site_packages=True)" set PATH=%KEEPPATH% if %errorlevel% neq 0 exit /b %errorlevel% @echo INSTALL set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper tkinterquickhelper --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 uninstall -y pyquickhelper if %errorlevel% neq 0 exit /b %errorlevel% python --version 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 PYTHONPATH=src if %errorlevel% neq 0 exit /b %errorlevel% set JOB_NAME=UT @echo SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py unittests if %errorlevel% neq 0 exit /b %errorlevel% @echo AFTER_SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% $PYINT -u src\\pyquicksetup\\setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% copy dist\\*.whl ROOT\\pyquickhelper\\..\\..\\local_pypi\\local_pypi_server if %errorlevel% neq 0 exit /b %errorlevel% @echo DOCUMENTATION set PATH=ROOT\\pyquickhelper\\%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") expected = expected.replace("__VERS__", vers) expected = expected.replace("__VERSP__", vers_) 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 + " DIST=std" in _ and "TIMEOUT=899" in _] if len(conv) != 2: raise Exception( "################################\nlen(conv)={0}\n{1}".format(len(conv), conv)) conv = conv[0] if platform.startswith("win"): expected = """ @echo off set PATH0=%PATH% SET DIST=std SET VERSION=__VERSP__ SET NAME=UT SET TIMEOUT=899 @echo AUTOMATEDSETUP set current=ROOT\\pyquickhelper\\%NAME_JENKINS% @echo interpreter=C:\\Python__VERS___x64\\python @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv if not exist "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" set KEEPPATH=%PATH% set PATH=C:\\Python__VERS___x64;%PATH% "C:\\Python__VERS___x64\\python" -c "from virtualenv import create_environment;create_environment(\\"ROOT\\\\pyquickhelper\\\\%NAME_JENKINS%\\\\_venv\\", site_packages=True)" set PATH=%KEEPPATH% if %errorlevel% neq 0 exit /b %errorlevel% @echo INSTALL set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper tkinterquickhelper --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 uninstall -y pyquickhelper if %errorlevel% neq 0 exit /b %errorlevel% python --version 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 PYTHONPATH=src if %errorlevel% neq 0 exit /b %errorlevel% set JOB_NAME=UT @echo SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py unittests if %errorlevel% neq 0 exit /b %errorlevel% @echo AFTER_SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% $PYINT -u src\\pyquicksetup\\setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% copy dist\\*.whl ROOT\\pyquickhelper\\..\\..\\local_pypi\\local_pypi_server if %errorlevel% neq 0 exit /b %errorlevel% @echo DOCUMENTATION set PATH=ROOT\\pyquickhelper\\%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") expected = expected.replace("__VERS__", vers) expected = expected.replace("__VERSP__", vers_) 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) else: expected = """ export DIST=std export PYINT=python__VERSP__ export PYTHONPATH=src export VERSION=__VERSP__ export NAME=UT export TIMEOUT=899 echo AUTOMATEDSETUP export current=ROOT/pyquickhelper/$NAME_JENKINS echo interpreter=C:/Python__VERS___x64/$PYINT echo CREATE VIRTUAL ENVIRONMENT in ROOT/pyquickhelper/$NAME_JENKINS/_venv if [-f ROOT/pyquickhelper/$NAME_JENKINS/_venv]; then mkdir "ROOT/pyquickhelper/$NAME_JENKINS/_venv"; fi export KEEPPATH=$PATH export PATH=C:/Python__VERS___x64:$PATH "C:/Python__VERS___x64/$PYINT" -c "from virtualenv import create_environment;create_environment(\\"ROOT/pyquickhelper/$NAME_JENKINS/_venv\\", site_packages=True)" export PATH=$KEEPPATH if [ $? -ne 0 ]; then exit $?; fi echo INSTALL export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT -c "from pip._internal import main;main(\\"install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper tkinterquickhelper --extra-index-url=https://pypi.python.org/simple/\\".split())" if [ $? -ne 0 ]; then exit $?; fi $PYINT -c "from pip._internal import main;main(\\"install --no-cache-dir --no-deps --index http://localhost:8067/simple/ pyrsslocal --no-deps --extra-index-url=https://pypi.python.org/simple/\\".split())" if [ $? -ne 0 ]; then exit $?; fi $PYINT -c "from pip._internal import main;main(\\"install -r requirements.txt\\".split())" if [ $? -ne 0 ]; then exit $?; fi $PYINT --version if [ $? -ne 0 ]; then exit $?; fi $PYINT -m pip uninstall -y pyquickhelper if [ $? -ne 0 ]; then exit $?; fi $PYINT -c "from pip._internal import main;main([\\"freeze\\"])" if [ $? -ne 0 ]; then exit $?; fi export JOB_NAME=UT echo SCRIPT export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT -u setup.py unittests if [ $? -ne 0 ]; then exit $?; fi echo AFTER_SCRIPT export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT -u setup.py bdist_wheel if [ $? -ne 0 ]; then exit $?; fi $PYINT -u src/pyquicksetup/setup.py bdist_wheel if [ $? -ne 0 ]; then exit $?; fi cp dist/*.whl ROOT/pyquickhelper/../local_pypi/local_pypi_server if [ $? -ne 0 ]; then exit $?; fi echo DOCUMENTATION export PATH=ROOT/pyquickhelper/$NAME_JENKINS/_venv/bin:$PATH $PYINT -u setup.py build_sphinx if [ $? -ne 0 ]; then exit $?; fi cp -R -f _doc/sphinxdoc/build/html dist/html if [ $? -ne 0 ]; then exit $?; fi """.replace(" ", "").strip("\n \t\r") expected = expected.replace("__VERS__", vers) expected = expected.replace("__VERSP__", vers_) 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)
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", Python37="C:\\Python37_x64", Python27="C:\\Python27_x64", Anaconda3=None, Anaconda2=None, WinPython36=None, project_name="pyquickhelper", root_path="ROOT") vers = "%d%d" % sys.version_info[:2] context["Python%s" % vers] = "C:\\Python%s_x64" % vers obj, name = load_yaml(yml, context=context, platform=platform) self.assertTrue(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 = [jenkins_final_postprocessing( _, True) for _ in convs if "VERSION=2.7" in _] self.assertTrue(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=899 @echo AUTOMATEDSETUP set current=ROOT\\pyquickhelper\\%NAME_JENKINS% @echo interpreter=C:\\Python27_x64\\python @echo CREATE VIRTUAL ENVIRONMENT in ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv if not exist "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" mkdir "ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv" set KEEPPATH=%PATH% set PATH=C:\\Python27_x64;%PATH% "C:\\Python27_x64\\python" -m virtualenv ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv --system-site-packages set PATH=%KEEPPATH% if %errorlevel% neq 0 exit /b %errorlevel% @echo INSTALL set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% pip install --upgrade pip if %errorlevel% neq 0 exit /b %errorlevel% pip install --no-cache-dir --no-deps --index http://localhost:8067/simple/ jyquickhelper tkinterquickhelper --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 uninstall -y pyquickhelper if %errorlevel% neq 0 exit /b %errorlevel% python --version 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 PYTHONPATH=src if %errorlevel% neq 0 exit /b %errorlevel% @echo BEFORE_SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% pip uninstall jyquickhelper if %errorlevel% neq 0 exit /b %errorlevel% pip install bin\\jyquickhelper-0.2-py2-none-any.whl if %errorlevel% neq 0 exit /b %errorlevel% C:\\Python37_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\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py unittests if %errorlevel% neq 0 exit /b %errorlevel% @echo AFTER_SCRIPT set PATH=ROOT\\pyquickhelper\\%NAME_JENKINS%\\_venv\\Scripts;%PATH% python -u setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% $PYINT -u src\\pyquicksetup\\setup.py bdist_wheel if %errorlevel% neq 0 exit /b %errorlevel% copy dist\\*.whl ROOT\\pyquickhelper\\..\\..\\local_pypi\\local_pypi_server if %errorlevel% neq 0 exit /b %errorlevel% @echo DOCUMENTATION set PATH=ROOT\\pyquickhelper\\%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---\n{1}\n---".format( expected, val) for i, (a, b) in enumerate(zip(expected.split("\n"), val.split("\n"))): if a != b: raise Exception( "error on line {3}:\nEXP:\n{0}\nGOT:\n{1}\n#######\n{2}".format(a, b, mes, i)) raise Exception(mes)