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(Suite, 'find_and_parse_tests') Suite.find_and_parse_tests(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), add_experimental=True, forgiving_parser=True, run_prod_code=False).AndReturn( self.files.values())
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 = Suite.create_fs_getter(autodir) predicate = lambda t: hasattr(t, 'suite') Suite.find_and_parse_tests(fs_getter, predicate, add_experimental=True, forgiving_parser=False)
def testFindAndParseStableTests(self): """Should find only non-experimental tests that match a predicate.""" self.expect_control_file_parsing() self.mox.ReplayAll() predicate = lambda d: d.text == self.files['two'].string tests = Suite.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 = Suite.find_and_parse_tests(self.getter, lambda d: True, self._TAG, add_experimental=True) 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 testFindAndParseTestsAttr(self): """Should find all tests that match a predicate.""" self.expect_control_file_parsing() self.mox.ReplayAll() predicate = Suite.matches_attribute_expression_predicate('attr:attr') tests = Suite.find_and_parse_tests(self.getter, predicate, self._TAG, add_experimental=True) 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 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 = Suite.find_and_parse_tests(self.getter, predicate, self._TAG, add_experimental=True) 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)