def createHarnessAndDAG(self, test_file): """ Return a tuple of the TestHarness, and the job_dag containing the testers generated by parsing 'test_file'. In order to do this, we have to schedule the actual test, but prevent (mock) the scheduler's ability to assign any threads to do work. By doing this, its important to know we need to properly close the threading pools when we are done; harness.waitFinish(). Calling harness.waitFinish() is also the only way the QueueManager knows when its safe to write the session file. """ ### We need to simulate what run_tests would do. Meaning, we need to ### instance the TestHarness while being in the directory where run_test ### sits. This is needed so tester's TestName is properly set (TestHarness ### takes the path leading up to run_tests, strips this off, and the ### results is what makes up the actual TestName). saved_cwd = os.getcwd() run_tests_dir = os.path.join(os.getenv('MOOSE_DIR'), 'test') os.chdir(run_tests_dir) # Instance the TestHarness self.harness = TestHarness(['foo', '--pbs', self.pbs_session_file], os.getenv('MOOSE_DIR'), app_name='moose_test') ### With the TestHarness properly instanced we now need to simulate ### what findAndRunTests does by changing into each tester directory ### before asking the factory to parse the file. tester_dir = os.path.dirname(test_file) tester_file = os.path.basename(test_file) sys.path.append(tester_dir) os.chdir(tester_dir) # Create the testers testers = self.harness.createTesters(tester_dir, tester_file, False) ### change back to original dir os.chdir(saved_cwd) sys.path.pop() ### TODO: that was a lot of chdir's. Lets figure out a way for the ### TestHarness to not have to do this. In actuality, we should only ### have had to do two things: Instance the TestHarness and create ### the testers. with mock.patch.object(self.harness.scheduler, 'queueJobs') as mock_queue_jobs: mock_queue_jobs.return_value = True self.harness.scheduler.schedule(testers) (args, kwargs) = mock_queue_jobs.call_args job_dag = kwargs['run_jobs'][0].getDAG() #### SANITY CHECK #### if job_dag.size() != 2: raise Exception('Sanity Check Failed: The test file has been modified but not the unittest') return (self.harness, job_dag)
def extractTestedRequirements(args, data): # Here we will use the TestHarness to find all of the # test files where we can look for tested requirements. # Assume SQA docs are located in <MOOSE_DIR>/framework/doc/sqa test_app_name = args.application_name test_app_dir = os.path.join(args.application_path) #### TODO # figure out a cleaner way to set this up # If test_app_name is framework, we need to reword some things if test_app_name == 'framework': test_app_name = 'moose_test' test_app_dir = os.path.join(args.moose_dir, 'test') # Set the current working directory to test_app_dir saved_cwd = os.getcwd() os.chdir(test_app_dir) sys.path.append(os.path.join(args.moose_dir, 'python')) import path_tool path_tool.activate_module('TestHarness') from TestHarness import TestHarness from Tester import Tester # Build the TestHarness object here harness = TestHarness([], test_app_name, args.moose_dir) # Tell it to parse the test files only, not run them harness.findAndRunTests(find_only=True) # Now retrieve all of the accumlated Testers from the TestHarness warehouse testers = harness.warehouse.getAllObjects() for tester in testers: print tester.specs['test_name'] input_filename = tester.getInputFile() if input_filename == None: continue input_path = os.path.join(tester.specs['test_dir'], input_filename) if not os.path.isfile(input_path): continue # Read the MOOSE input file f = open(os.path.join(tester.specs['test_dir'], tester.getInputFile())) text = f.read() f.close() # See if the file maps to a requirement (e.g. @Requirement) for req in re.finditer(r'@Requirement\s+([\w\.]+)', text): requirement = req.group(1) if requirement not in data: print 'Unable to find referenced requirement "' + requirement + '" in ' + input_path else: data[requirement][2].add( os.path.relpath(input_path, args.moose_dir)) os.chdir(saved_cwd)
def extractTestedRequirements(args, data): # Here we will use the TestHarness to find all of the # test files where we can look for tested requirements. # Assume SQA docs are located in <MOOSE_DIR>/framework/doc/sqa test_app_name = args.application_name test_app_dir = os.path.join(args.application_path) #### TODO # figure out a cleaner way to set this up # If test_app_name is framework, we need to reword some things if test_app_name == 'framework': test_app_name = 'moose_test' test_app_dir = os.path.join(args.moose_dir, 'test') # Set the current working directory to test_app_dir saved_cwd = os.getcwd() os.chdir(test_app_dir) sys.path.append(os.path.join(args.moose_dir, 'python')) import path_tool path_tool.activate_module('TestHarness') from TestHarness import TestHarness from Tester import Tester # Build the TestHarness object here harness = TestHarness([], test_app_name, args.moose_dir) # Tell it to parse the test files only, not run them harness.findAndRunTests(find_only=True) # Now retrieve all of the accumlated Testers from the TestHarness warehouse testers = harness.warehouse.getAllObjects() for tester in testers: print tester.specs['test_name'] input_filename = tester.getInputFile() if input_filename == None: continue input_path = os.path.join(tester.specs['test_dir'], input_filename) if not os.path.isfile(input_path): continue # Read the MOOSE input file f = open(os.path.join(tester.specs['test_dir'], tester.getInputFile())) text = f.read() f.close() # See if the file maps to a requirement (e.g. @Requirement) for req in re.finditer(r'@Requirement\s+([\w\.]+)', text): requirement = req.group(1) if requirement not in data: print 'Unable to find referenced requirement "' + requirement + '" in ' + input_path else: data[requirement][2].add(os.path.relpath(input_path, args.moose_dir)) os.chdir(saved_cwd)
def extractTestedRequirements(data): # Here we will use the TestHarness to find all of the # test files where we can look for tested requirements. # Assume SQA docs are located in <MOOSE_DIR>/framework/doc/sqa MOOSE_DIR = os.path.abspath(os.path.join('..', '..', '..')) #### See if MOOSE_DIR is already in the environment instead if os.environ.has_key("MOOSE_DIR"): MOOSE_DIR = os.environ['MOOSE_DIR'] test_app_name = 'moose_test' test_app_dir = os.path.join(MOOSE_DIR, 'test') # Set the current working directory to test_app_dir saved_cwd = os.getcwd() os.chdir(test_app_dir) sys.path.append(os.path.join(MOOSE_DIR, 'python')) import path_tool path_tool.activate_module('TestHarness') from TestHarness import TestHarness from Tester import Tester # Build the TestHarness object here harness = TestHarness(sys.argv, test_app_name, MOOSE_DIR) # Tell it to parse the test files only, not run them harness.findAndRunTests(find_only=True) # Now retrieve all of the accumlated Testers from the TestHarness warehouse testers = harness.warehouse.getAllObjects() for tester in testers: print tester.specs['test_name'] input_filename = tester.getInputFile() if input_filename == None: continue input_path = os.path.join(tester.specs['test_dir'], input_filename) if not os.path.isfile(input_path): continue # Read the MOOSE input file f = open(os.path.join(tester.specs['test_dir'], tester.getInputFile())) text = f.read() f.close() # See if the file maps to a requirement (e.g. @Requirement) m = re.search(r'@Requirement\s+([\w\.]+)', text) if m != None: requirement = m.group(1) if requirement not in data: print 'Unable to find referenced requirement "' + requirement + '" in ' + input_path else: data[requirement][2].add(os.path.relpath(input_path, MOOSE_DIR)) os.chdir(saved_cwd)
def __init__(self, argv, app_name, moose_dir): TestHarness.__init__(self, argv, app_name, moose_dir) try: from sqlite3 import dbapi2 as sqlite except: print 'Error: --store-timing requires the sqlite3 python module.' sys.exit(1) self.app_name = app_name self.db_file = self.options.dbFile if not self.db_file: home = os.environ['HOME'] self.db_file = os.path.join(home, 'timingDB/timing.sqlite') if not os.path.exists(self.db_file): print 'Warning: creating new database at default location: ' + str(self.db_file) self.createDB(self.db_file) else: print 'Warning: Assuming database location ' + self.db_file
def __init__(self, argv, app_name, moose_dir): TestHarness.__init__(self, argv, app_name, moose_dir) try: from sqlite3 import dbapi2 as sqlite except: print 'Error: --store-timing requires the sqlite3 python module.' sys.exit(1) self.app_name = app_name self.db_file = self.options.dbFile if not self.db_file: home = os.environ['HOME'] self.db_file = os.path.join(home, 'timingDB/timing.sqlite') if not os.path.exists(self.db_file): print 'Warning: creating new database at default location: ' + str( self.db_file) self.createDB(self.db_file) else: print 'Warning: Assuming database location ' + self.db_file
def testCleanup(self): """ Test the QueueManagers ability to clean up after itself """ # Launch jobs to create something we need to clean up self.testPBSGoodLaunch() # See if we actually made a mess, like we should have if os.path.exists(self.session_dir): harness = TestHarness(['foo', '--queue-cleanup', self.pbs_session_file], os.getenv('MOOSE_DIR'), app_name='moose') # Perform the clean up code harness.scheduler.cleanUp() if os.path.exists(os.path.join(self.session_dir)): self.fail('Failed to perform session cleanup') else: self.fail('Failed to create session: %s' % (self.session_dir))
def runTests(argv, app_name, moose_dir): if '--store-timing' in argv: # Pass control to TestTimer class for Test Timing harness = TestTimer(argv, app_name, moose_dir) else: harness = TestHarness(argv, app_name, moose_dir) # Get a reference to the factory out of the TestHarness factory = harness.getFactory() # TODO: We need to cascade the testers so that each app can use any # tester available in each parent application dirs = [os.path.abspath(os.path.dirname(sys.argv[0])), FRAMEWORK_DIR] # Load the tester plugins into the factory reference factory.loadPlugins(dirs, plugin_dir, Tester, factory) # Finally find and run the tests harness.findAndRunTests()