def testFindSuiteSyntaxErrors(self): """Check all control files for syntax errors. This test actually parses all control files in the autotest directory for syntax errors, by using the un-forgiving parser and pretending to look for all control files with the suite attribute. """ autodir = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..', '..')) fs_getter = SuiteBase.create_fs_getter(autodir) predicate = lambda t: hasattr(t, 'suite') SuiteBase.find_and_parse_tests(fs_getter, predicate, forgiving_parser=False)
def mock_control_file_parsing(self): """Fake out find_and_parse_tests(), returning content from |self.files|. """ for test in self.files.values(): test.text = test.string # mimic parsing. self.mox.StubOutWithMock(SuiteBase, 'find_and_parse_tests') SuiteBase.find_and_parse_tests( mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), forgiving_parser=True, run_prod_code=False, test_args=None).AndReturn(self.files.values())
def testFindAndParseStableTests(self): """Should find only tests that match a predicate.""" self.expect_control_file_parsing() self.mox.ReplayAll() predicate = lambda d: d.text == self.files['two'].string tests = SuiteBase.find_and_parse_tests(self.getter, predicate, self._TAG) self.assertEquals(len(tests), 1) self.assertEquals(tests[0], self.files['two'])
def testGetTestsSortedByTime(self): """Should find all tests and sorted by TIME setting.""" self.expect_control_file_parsing() self.mox.ReplayAll() # Get all tests. tests = SuiteBase.find_and_parse_tests(self.getter, lambda d: True, self._TAG) self.assertEquals(len(tests), 7) times = [control_data.ControlData.get_test_time_index(test.time) for test in tests] self.assertTrue(all(x>=y for x, y in zip(times, times[1:])), 'Tests are not ordered correctly.')
def testFindAndParseTestsSuite(self): """Should find all tests that match a predicate.""" self.expect_control_file_parsing() self.mox.ReplayAll() predicate = lambda d: d.suite == self._TAG tests = SuiteBase.find_and_parse_tests(self.getter, predicate, self._TAG) self.assertEquals(len(tests), 6) self.assertTrue(self.files['one'] in tests) self.assertTrue(self.files['two'] in tests) self.assertTrue(self.files['three'] in tests) self.assertTrue(self.files['five'] in tests) self.assertTrue(self.files['six'] in tests) self.assertTrue(self.files['seven'] in tests)
def testFindAndParseTestsAttr(self): """Should find all tests that match a predicate.""" self.expect_control_file_parsing() self.mox.ReplayAll() predicate = SuiteBase.matches_attribute_expression_predicate('attr:attr') tests = SuiteBase.find_and_parse_tests(self.getter, predicate, self._TAG) self.assertEquals(len(tests), 6) self.assertTrue(self.files['one'] in tests) self.assertTrue(self.files['two'] in tests) self.assertTrue(self.files['three'] in tests) self.assertTrue(self.files['four'] in tests) self.assertTrue(self.files['six'] in tests) self.assertTrue(self.files['seven'] in tests)
def __init__(self, config, test_dir): """Init WrapperTestRunner. The test to run inside the wrapper test is usually a client side autotest. Look up the control file of the inner test, and then prepend the args to to the control file to pass the args to the inner test. @param config: the args argument from test_that in a dict, contains the test to look up in the autotest directory and the args to prepend to the control file. required data: {'test': 'test_TestName.tag'} @param test_dir: the directory to retrieve the test from. """ if not config: msg = 'Wrapper test must run with args input.' raise error.TestNAError(msg) if 'test' not in config: msg = 'User did not specify client side test to run in wrapper.' raise error.TestNAError(msg) # test_name is tagged test name. self._test_name = config['test'] # Find the test in autotest file system. fs_getter = suite.create_fs_getter(test_dir) predicate = suite.test_name_equals_predicate(self._test_name) test = suite.find_and_parse_tests(fs_getter, predicate) if not test: msg = '%s is not a valid test name.' % self._test_name raise error.TestNAError(msg) # If multiple tests with the same name are found, run the first one. if len(test) > 1: logging.warning( 'Found %d tests with name %s, running the first ' 'one.', len(test), self._test_name) control_file_no_args = test[0].text # Prepend the args. args_list = ['='.join((k, str(v))) for k, v in config.iteritems()] args_string = 'args = ' + json.dumps(args_list) args_dict_string = 'args_dict = ' + json.dumps(config) control_file_list = [args_string, args_dict_string] control_file_list.extend( ['%s = "%s"' % (k, str(v)) for k, v in config.iteritems()]) control_file_list.append(control_file_no_args) self._test_control_file = '\n'.join(control_file_list)
def _control_path_on_disk(control_name): """Find the control file corresponding to the given control name, on disk. @param control_name: NAME attribute of the control file to fetch. @return: Path to the control file. """ cf_getter = suite.create_fs_getter(_AUTOTEST_ROOT) control_name_predicate = suite.test_name_matches_pattern_predicate( '^%s$' % control_name) tests = suite.find_and_parse_tests(cf_getter, control_name_predicate) if not tests: raise error.AutoservError( 'Failed to find any control files with NAME %s' % control_name) if len(tests) > 1: logging.error('Found more than one control file with NAME %s: %s', control_name, [t.path for t in tests]) raise error.AutoservError( 'Found more than one control file with NAME %s' % control_name) return tests[0].path
def testFindAllTestInBatch(self): """Test switch on enable_getting_controls_in_batch for function find_all_test.""" self.use_batch = SuiteBase.ENABLE_CONTROLS_IN_BATCH self.expect_control_file_parsing_in_batch() SuiteBase.ENABLE_CONTROLS_IN_BATCH = True self.mox.ReplayAll() predicate = lambda d: d.suite == self._TAG tests = SuiteBase.find_and_parse_tests(self.getter, predicate, self._TAG) self.assertEquals(len(tests), 6) self.assertTrue(self.files['one'] in tests) self.assertTrue(self.files['two'] in tests) self.assertTrue(self.files['three'] in tests) self.assertTrue(self.files['five'] in tests) self.assertTrue(self.files['six'] in tests) self.assertTrue(self.files['seven'] in tests) SuiteBase.ENABLE_CONTROLS_IN_BATCH = self.use_batch