def runTests(): if args.timeout is not None: UnitTestCommon.startTimeoutThread(args.timeout[0]) try: return executeTests(args) except: import traceback logging.error("executeTests() threw an exception: \n%s", traceback.format_exc()) return 1
def runPythonUnitTests_(args, testFilter, testGroupName, testFiles): testArgs = ["dummy"] if args.testHarnessVerbose or args.list: testArgs.append('--nocaptureall') testArgs.append('--verbosity=0') if not args.list: print "Executing %s unit tests." % testGroupName Setup.config().configureLoggingForUserProgram() parser = PythonTestArgumentParser() filterActions = parser.parse_args(args.remainder) bsaRootDir = os.path.split(ufora.__file__)[0] testCasesToRun = [] plugins = nose.plugins.manager.PluginManager([OutputCaptureNosePlugin()]) config = nose.config.Config(plugins=plugins) config.configure(testArgs) for i in range(args.copies): testCases = UnitTestCommon.loadTestCases(config, testFiles, bsaRootDir, 'ufora') if filterActions: testCases = applyFilterActions(filterActions, testCases) testCasesToRun += testCases if testFilter is not None: testCasesToRun = testFilter(testCasesToRun) if args.list: for test in testCasesToRun: print test.id() os._exit(0) if args.random: import random random.shuffle(testCasesToRun) if args.pythreadcheck: results = {} for test in testCasesToRun: results[test] = runPyTestSuite(config, None, unittest.TestSuite([test]), testArgs) return True in results.values() else: testFiles = '.' return runPyTestSuite(config, None, testCasesToRun, testArgs)
def runPythonUnitTests(args, testFilter): """run python unittests in all *_test.py files in the project. Args contains arguments from a UnitTestArgumentParser. Returns True if any failed. """ bsaRootDir = os.path.split(ufora.__file__)[0] return runPythonUnitTests_( args, testFilter, testGroupName = "python", testFiles = UnitTestCommon.findTestFiles(bsaRootDir, '.*_test.py$') )
def UnitTestMainline(modulesToInitialize=None, exit=True, loginConfiguration=LoginConfiguration.LoginConfiguration. defaultForTesting(), disableLogCapture=False): """Helper function to call the unittest mainline Constructs a default Setup from the config. Calls x.initialize(setup) for all x in modulesToInitialize. """ modulesToInitialize = modulesToInitialize or [] import ufora.native argv = list(sys.argv) setup = Setup.defaultSetup() parser = Setup.defaultParser() unitTestOptions = parser.add_argument_group( title='UnitTestMainline options', description='options for the general UnitTest framework') addNoseVerbosityArgument(unitTestOptions) unitTestOptions.add_argument('testHarnessArguments', nargs=argparse.REMAINDER) parser.add_argument( '-timeout', type=float, nargs=1, help='fail test if not completed after TIMEOUT seconds', default=None) parsedArguments = parser.parse_args(argv[1:]) if parsedArguments.timeout is not None: UnitTestCommon.startTimeoutThread(parsedArguments.timeout[0]) setup.processArgs(parsedArguments) testHarnessArguments = ["dummy"] + parsedArguments.testHarnessArguments testHarnessArguments.append('--verbosity=0') if parsedArguments.testHarnessVerbose or disableLogCapture: testHarnessArguments.append('--nocaptureall') setup.config.configureLoggingForUserProgram() plugins = nose.plugins.manager.PluginManager([OutputCaptureNosePlugin()]) config = nose.config.Config(plugins=plugins) config.configure(testHarnessArguments) with Setup.PushSetup(setup): result = None for toInitialize in modulesToInitialize: toInitialize.initialize(setup) result = nose.core.TestProgram(exit=False, defaultTest="__main__", config=config, argv=testHarnessArguments).success sys.stdout.flush() sys.stderr.flush() ufora.native.Tests.gcov_flush() if not exit: return 0 if result else 1 else: os._exit(0 if result else 1)
def UnitTestMainline(modulesToInitialize=None, exit=True, loginConfiguration=LoginConfiguration.LoginConfiguration.defaultForTesting(), disableLogCapture=False): """Helper function to call the unittest mainline Constructs a default Setup from the config. Calls x.initialize(setup) for all x in modulesToInitialize. """ modulesToInitialize = modulesToInitialize or [] import ufora.native argv = list(sys.argv) setup = Setup.defaultSetup() parser = Setup.defaultParser() unitTestOptions = parser.add_argument_group( title='UnitTestMainline options', description='options for the general UnitTest framework' ) addNoseVerbosityArgument(unitTestOptions) unitTestOptions.add_argument( 'testHarnessArguments', nargs=argparse.REMAINDER ) parser.add_argument('-timeout', type=float, nargs=1, help='fail test if not completed after TIMEOUT seconds', default=None) parsedArguments = parser.parse_args(argv[1:]) if parsedArguments.timeout is not None: UnitTestCommon.startTimeoutThread(parsedArguments.timeout[0]) setup.processArgs(parsedArguments) testHarnessArguments = ["dummy"] + parsedArguments.testHarnessArguments testHarnessArguments.append('--verbosity=0') if parsedArguments.testHarnessVerbose or disableLogCapture: testHarnessArguments.append('--nocaptureall') setup.config.configureLoggingForUserProgram() plugins = nose.plugins.manager.PluginManager([OutputCaptureNosePlugin()]) config = nose.config.Config(plugins=plugins) config.configure(testHarnessArguments) with Setup.PushSetup(setup): result = None for toInitialize in modulesToInitialize: toInitialize.initialize(setup) result = nose.core.TestProgram( exit=False, defaultTest="__main__", config=config, argv=testHarnessArguments ).success sys.stdout.flush() sys.stderr.flush() ufora.native.Tests.gcov_flush() if not exit: return 0 if result else 1 else: os._exit(0 if result else 1)