def __call__(self): """Execute the test from the run.py file.""" if _TEST_NAME_FILE: # pragma: debugging with open(_TEST_NAME_FILE, "w") as f: f.write(self.description.replace("/", "_")) # Prepare a dictionary of globals for the run.py files to use. fns = """ copy run runfunc clean skip compare contains contains_any doesnt_contain """.split() if self.clean_only: glo = dict((fn, noop) for fn in fns) glo['clean'] = clean else: glo = dict((fn, globals()[fn]) for fn in fns) if self.dont_clean: # pragma: not covered glo['clean'] = noop with change_dir(self.dir): try: execfile(self.runpy, glo) except Exception: self.ok = False raise
def run(cmds, rundir="src", outfile=None): """Run a list of commands. `cmds` is a string, commands separated by newlines. `rundir` is the directory in which to run the commands. `outfile` is a file name to redirect stdout to. """ with change_dir(rundir): if outfile: fout = open(outfile, "a+") try: for cmd in cmds.split("\n"): cmd = cmd.strip() if not cmd: continue retcode, output = run_command(cmd) print(output.rstrip()) if outfile: fout.write(output) if retcode: raise Exception("command exited abnormally") finally: if outfile: fout.close()
def run(cmds, rundir="src", outfile=None): """Run a list of commands. `cmds` is a string, commands separated by newlines. `rundir` is the directory in which to run the commands. `outfile` is a filename to redirect stdout to. """ with change_dir(rundir): if outfile: fout = open(outfile, "a+") try: for cmd in cmds.split("\n"): cmd = cmd.strip() if not cmd: continue retcode, output = run_command(cmd) print(output.rstrip()) if outfile: fout.write(output) if retcode: raise Exception("command exited abnormally") finally: if outfile: fout.close()
def runfunc(fn, rundir="src", addtopath=None): """Run a function. `fn` is a callable. `rundir` is the directory in which to run the function. """ with change_dir(rundir): with saved_sys_path(): if addtopath is not None: sys.path.insert(0, addtopath) fn()