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))
def test_py3to2(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if sys.version_info[0] == 2: return temp = get_temp_folder(__file__, "temp_py3to2") root = os.path.abspath(os.path.dirname(__file__)) root = os.path.normpath(os.path.join(root, "..", "..")) conv = py3to2_convert_tree(root, temp, fLOG=fLOG) if len(conv) < 20: raise Exception("not enough copied files") script = """ import sys sys.path = [ p for p in sys.path if "src" not in p and "ut_" not in p ] sys.path.append(r"{0}") print "" for k in sys.path: print k import pyquickhelper """.replace(" ", "") script = script.format(os.path.join(temp, "src")) to = os.path.join(temp, "simpletry.py") with open(to, "w", encoding="utf8") as f: f.write(script) pyexe2 = None for location in [r"C:\Anaconda2", r"C:\Anaconda", r"C:\WinPython-64bit-2.7.9.3\python-2.7.9.amd64", ]: exe = os.path.join(location, "python.exe") if os.path.exists(exe): pyexe2 = exe break if pyexe2 is not None: cmd = "{0} {1}".format(pyexe2, to) out, err = run_cmd(cmd, wait=True) if len(err) > 0: raise Exception( "conversion did not work:\nOUT\n:{0}\nERR:\n{1}".format(out, err)) else: fLOG("python 2.7 was not found")