def _module_iter(self, filename): """Returns an iterator of Test objects for the contents of the given python module file. """ try: fname, mod = get_module(filename) except: t = Test(filename, self.options) t.status = 'FAIL' t.err_msg = traceback.format_exc() yield t else: if basename(fname).startswith('__init__.'): for result in self._dir_iter(dirname(fname)): yield result else: for name, obj in getmembers(mod): if isclass(obj) and issubclass(obj, TestCase): for result in self._testcase_iter(filename, obj): yield result elif isfunction(obj) and self.func_match(name): yield Test(':'.join((filename, obj.__name__)), self.options)
def _testcase_iter(self, fname, testcase): """Returns an iterator of Test objects coming from a given TestCase class. """ tcname = ':'.join((fname, testcase.__name__)) for name, method in getmembers(testcase, ismethod): if self.func_match(name): yield Test('.'.join((tcname, method.__name__)))
def _testspec_iter(self, testspec): """Returns an iterator of Test objects found in the module/testcase/method specified in testspec. The format of testspec is one of the following: <module> <module>:<testcase> <module>:<testcase>.<method> <module>:<function> where <module> is either the python module path or the actual file system path to the .py file. """ module, _, rest = testspec.partition(':') if rest: tcasename, _, method = rest.partition('.') if method: yield Test(testspec) else: # could be a test function or a TestCase try: fname, mod = get_module(module) except: yield Test(testspec, 'FAIL', err_msg=traceback.format_exc()) return try: tcase = get_testcase(fname, mod, tcasename) except (AttributeError, TypeError): yield Test(testspec) else: for test in self._testcase_iter(fname, tcase): yield test else: for test in self._module_iter(module): yield test
from testflo.qman import get_client_queue from testflo.options import get_options exitcode = 0 # use 0 for exit code of all ranks != 0 because otherwise, # MPI will terminate other processes queue = get_client_queue() os.environ['TESTFLO_QUEUE'] = '' options = get_options() setup_coverage(options) try: try: comm = MPI.COMM_WORLD test = Test(sys.argv[1], options) test.nocapture = True # so we don't lose stdout test.run() except: print(traceback.format_exc()) test.status = 'FAIL' test.err_msg = traceback.format_exc() # collect results results = comm.gather(test, root=0) if comm.rank == 0: if not all([isinstance(r, Test) for r in results]): print("\nNot all results gathered are Test objects. " "You may have out-of-sync collective MPI calls.\n") total_mem_usage = sum(r.memory_usage for r in results if isinstance(r, Test))
from testflo.test import Test from testflo.cover import save_coverage from testflo.qman import get_client_manager from testflo.util import get_addr_auth_from_args exitcode = 0 # use 0 for exit code of all ranks != 0 because otherwise, # MPI will terminate other processes address, authkey = get_addr_auth_from_args(sys.argv[2:]) manager = get_client_manager(address, authkey) try: try: comm = MPI.COMM_WORLD test = Test(sys.argv[1]) test.nocapture = True # so we don't lose stdout test.run() except: print(traceback.format_exc()) test.status = "FAIL" test.err_msg = traceback.format_exc() # collect results results = comm.gather(test, root=0) if comm.rank == 0: total_mem_usage = sum(r.memory_usage for r in results) test.memory_usage = total_mem_usage # check for errors and record error message for r in results:
import sys import os import traceback from testflo.test import Test from testflo.cover import save_coverage from testflo.qman import get_client_manager from testflo.util import get_addr_auth_from_args, to_bytes address, authkey = get_addr_auth_from_args(sys.argv[2:]) manager = get_client_manager(address, authkey) try: try: test = Test(sys.argv[1]) test.nocapture = True # so we don't lose stdout test.run() except: print(traceback.format_exc()) test.status = 'FAIL' test.err_msg = traceback.format_exc() save_coverage() except: test.err_msg = traceback.format_exc() test.status = 'FAIL' sys.stdout.flush() sys.stderr.flush()
if __name__ == '__main__': import sys import os import traceback from testflo.test import Test from testflo.cover import save_coverage from testflo.qman import get_client_queue queue = get_client_queue() os.environ['TESTFLO_QUEUE'] = '' try: try: test = Test(sys.argv[1]) test.nocapture = True # so we don't lose stdout test.run() except: print(traceback.format_exc()) test.status = 'FAIL' test.err_msg = traceback.format_exc() save_coverage() except: test.err_msg = traceback.format_exc() test.status = 'FAIL' sys.stdout.flush() sys.stderr.flush()