print('-'* for arg in argsprint(argdef quiet(*args)pass trace quiet glob scripts to be tested testpatt os path join(testdir'scripts''py'testfiles glob glob(testpatttestfiles sort(trace(os getcwd()*testfilesnumfail for testpath in testfilestestname os path basename(testpathrun all tests in dir strip directory path get input and args infile testname replace(py'in'inpath os path join(testdir'inputs'infileindata open(inpath'rb'read(if os path exists(inpathelse 'argfile testname replace(py'args'argpath os path join(testdir'args'argfileargdata open(argpathread(if os path exists(argpathelse 'locate output and errorscrub prior results outfile testname replace(py'out'outpath os path join(testdir'outputs'outfileoutpathbad outpath badif os path exists(outpathbad)os remove(outpathbaderrfile testname replace(py'err'errpath os path join(testdir'errors'errfileif os path exists(errpath)os remove(errpathrun test with redirected streams pypath sys executable command '% % % (pypathtestpathargdatatrace(commandindataprocess popen(commandshell=truestdin=pipestdout=pipestderr=pipeprocess stdin write(indataprocess stdin close(outdata process stdout read(errdata process stderr read(data are bytes exitstatus process wait(requires binary files trace(outdataerrdataexitstatusanalyze results if exitstatus ! print('error status:'testnameexitstatusif errdataprint('error stream:'testnameerrpathopen(errpath'wb'write(errdata complete system programs status and/or stderr save error text