def write_output(file_base, data_dict, interesting_fields): fn = "output/" + file_base safe_rm(fn) fp = open(fn, "w") dict_copy = {} for x in interesting_fields: try: dict_copy[x] = data_dict[x] except KeyError: # yes, this means the output file cannot possibly be correct. pass fp.write(display.dprint(dict_copy)) fp.close() return fn
def list(env): # nose has --collect-only which identifies the tests, but does not run them. # We run nose with the same set of parameters as if we were running the # test, but we add --collect-only. The result is a pandokia log file # that contains abbreviated test reports. We read that log file to # find the test names. (Everything except the name is an uninteresting # side-effect.) # # Note that the PDK_TESTPREFIX is applied by the nose plugin, not us. # If this function is called, it is only once per process. import pandokia.helpers.process as process import pandokia.helpers.filecomp as filecomp tmpfile = 'pdk.runner.tmp' # Do our best to make sure the file is not there already. try: os.unlink(tmpfile) except OSError: pass # run the command to collect the names # pandokia log goes to tmpfile - it is ok to used a fixed name because we # know that only one process can be running tests in a single directory. s = 'pdknose --pdk --with-doctest --doctest-tests --collect-only %(PDK_FILE)s' % env env = env.copy() env['PDK_LOG'] = tmpfile process.run_process(s.split(), env, output_file='pdknose.tmp') # gather the names from pdk.log l = [] f = open(tmpfile, "r") for line in f: line = line.strip().split('=') if line[0] == 'test_name': l.append(line[1]) f.close() # clean up filecomp.safe_rm('pdknose.tmp') filecomp.safe_rm(tmpfile) # return list return l
def lst(env): # nose has --collect-only which identifies the tests, but does not run them. # We run nose with the same set of parameters as if we were running the # test, but we add --collect-only. The result is a pandokia log file # that contains abbreviated test reports. We read that log file to # find the test names. (Everything except the name is an uninteresting # side-effect.) # # Note that the PDK_TESTPREFIX is applied by the nose plugin, not us. # If this function is called, it is only once per process. import pandokia.helpers.process as process import pandokia.helpers.filecomp as filecomp tmpfile = 'pdk.runner.tmp' # Do our best to make sure the file is not there already. try: os.unlink(tmpfile) except OSError: pass # run the command to collect the names # pandokia log goes to tmpfile - it is ok to used a fixed name because we # know that only one process can be running tests in a single directory. s = 'pdknose --pdk --with-doctest --doctest-tests --collect-only %(PDK_FILE)s' % env env = env.copy() env['PDK_LOG'] = tmpfile process.run_process(s.split(), env, output_file='pdknose.tmp') # gather the names from pdk.log l = [] f = open(tmpfile, "r") for line in f: line = line.strip().split('=') if line[0] == 'test_name': l.append(line[1]) f.close() # clean up filecomp.safe_rm('pdknose.tmp') filecomp.safe_rm(tmpfile) # return list return l
def safe_rm(): with pycode.test('dne'): filecomp.safe_rm("does_not_exist") filecomp.safe_rm("does_not_exist") filecomp.safe_rm(["does_not_exist", "does_not_exist"]) with pycode.test('exists'): open("safe_rm.tmp", "w").close() filecomp.safe_rm("safe_rm.tmp") try: open("safe_rm.tmp", "r") except IOError: pass else: assert 0, "should have had IOError"
def open_okfile(test_name): # the okfile is in the subdirectory okfile/ okfile = os.getcwd() + '/okfile/' + test_name safe_rm(okfile) f = open(okfile, "w") return f
# using Pandokia - http://ssb.stsci.edu/testing/pandokia # # using this feature: # http://ssb.stsci.edu/testing/pandokia/docs_new/runner_minipyt.html#linear-execution-in-sequential-code-with-statement # import pandokia.helpers.pycode as pycode from pandokia.helpers.filecomp import safe_rm import shmht testfile = 'test_shmht.dat' safe_rm(testfile) with pycode.test('open-error'): try: ident = shmht.open(testfile) except shmht.error as e: pass else: assert False, 'should have raised an exception' with pycode.test('open-init'): ident = shmht.open(testfile, 10) with pycode.test('insert-lookup'):