def configtest_main(parser=None): if parser is None: parser = argparse.ArgumentParser( description="GA4GH server configuration validator") parser.add_argument("--config", "-c", default='DevelopmentConfig', type=str, help="The configuration to use") parser.add_argument("--config-file", "-f", type=str, default=None, help="The configuration file to use") args = parser.parse_args() configStr = 'ga4gh.serverconfig:{0}'.format(args.config) configtest.TestConfig.configStr = configStr configtest.TestConfig.configFile = args.config_file configtest.TestConfig.configEnv = "GA4GH_CONFIGURATION" loader = unittest.TestLoader() tests = loader.loadTestsFromModule(configtest) results = SimplerResult() tests.run(results) logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) log.info('{0} Tests run. {1} errors, {2} failures, {3} skipped'.format( results.testsRun, len(results.errors), len(results.failures), len(results.skipped))) for result in results.errors: if result is not None: log.critical('Error: {0}: {1}'.format(result[0].id(), result[1])) for result in results.failures: if result is not None: log.critical('Failure: {0}: {1}'.format(result[0].id(), result[1])) for result in results.skipped: if result is not None: log.info('Skipped: {0}: {1}'.format(result[0].id(), result[1]))
def configtest_main(parser=None): if parser is None: parser = argparse.ArgumentParser( description="GA4GH server configuration validator") parser.add_argument( "--config", "-c", default='DevelopmentConfig', type=str, help="The configuration to use") parser.add_argument( "--config-file", "-f", type=str, default=None, help="The configuration file to use") args = parser.parse_args() configStr = 'ga4gh.serverconfig:{0}'.format(args.config) configtest.TestConfig.configStr = configStr configtest.TestConfig.configFile = args.config_file configtest.TestConfig.configEnv = "GA4GH_CONFIGURATION" loader = unittest.TestLoader() tests = loader.loadTestsFromModule(configtest) results = SimplerResult() tests.run(results) logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) log.info('{0} Tests run. {1} errors, {2} failures, {3} skipped'. format(results.testsRun, len(results.errors), len(results.failures), len(results.skipped))) for result in results.errors: if result is not None: log.critical('Error: {0}: {1}'.format(result[0].id(), result[1])) for result in results.failures: if result is not None: log.critical('Failure: {0}: {1}'.format(result[0].id(), result[1])) for result in results.skipped: if result is not None: log.info('Skipped: {0}: {1}'.format(result[0].id(), result[1]))
def _create_suite(package_name, test_name, test_dir, test_regex=r"(?:^|[b_./-])[Tt]est"): loader = GAETestLoader() suite = unittest.TestSuite() error = None def match_fn(test_name): """ Determine whether a qualified test name (module.class.method) should be run. """ return not not re.search(test_regex, test_name) try: if not package_name and not test_name: modules = _load_default_test_modules(test_dir) for module in modules: suite.addTest(loader.loadTestsFromModule(module, match_fn)) elif test_name: _load_default_test_modules(test_dir) suite.addTest(loader.loadTestsFromName(test_name, match_fn=match_fn)) elif package_name: package = reload(__import__(package_name)) module_names = package.__all__ for module_name in module_names: qualified_name = '%s.%s' % (package_name, module_name) suite.addTest(loader.loadTestsFromName(qualified_name, match_fn=match_fn)) if suite.countTestCases() == 0: raise Exception("'%s' is not found or does not contain any matching tests." % \ (test_name or package_name or 'local directory: \"%s\"' % _LOCAL_TEST_DIR)) except Exception, e: error = str(e) _log_error(error)
import unittest from unittest import TestSuite, loader from .routes_tests import rider_routes_test test_cases = [ ] if __name__ == '__main__': suite = TestSuite() for test in test_cases: tests = loader.loadTestsFromModule(test) suite.addTests(tests) unittest.main()