def testRemoveExpectation(self): """Tests that specifying to remove an expectation does so.""" self._input_mock.return_value = 'r' # yapf: disable test_expectation_map = data_types.TestExpectationMap({ 'foo/test': data_types.ExpectationBuilderMap({ data_types.Expectation( 'foo/test', ['win'], 'Failure', 'crbug.com/1234'): data_types.BuilderStepMap(), }), }) # yapf: enable modified_urls = expectations.ModifySemiStaleExpectations( test_expectation_map, self.filename) self.assertEqual(modified_urls, set(['crbug.com/1234'])) expected_file_contents = """\ # tags: [ win linux ] # results: [ Failure RetryOnFailure Skip ] [ linux ] foo/test [ Failure ] crbug.com/2345 [ linux ] bar/* [ RetryOnFailure ] crbug.com/3456 [ linux ] some/bad/test [ Skip ] """ with open(self.filename) as f: self.assertEqual(f.read(), expected_file_contents)
def testEmptyExpectationMap(self): """Tests that an empty expectation map results in a no-op.""" modified_urls = expectations.ModifySemiStaleExpectations( data_types.TestExpectationMap(), self.filename) self.assertEqual(modified_urls, set()) self._input_mock.assert_not_called() with open(self.filename) as f: self.assertEqual(f.read(), FAKE_EXPECTATION_FILE_CONTENTS)
def main(): args = ParseArgs() test_expectation_map = expectations.CreateTestExpectationMap( args.expectation_file, args.tests) ci_builders = builders.GetCiBuilders( SUITE_TO_TELEMETRY_SUITE_MAP.get(args.suite, args.suite)) querier = queries.BigQueryQuerier(args.suite, args.project, args.num_samples, args.large_query_mode) # Unmatched results are mainly useful for script maintainers, as they don't # provide any additional information for the purposes of finding unexpectedly # passing tests or unused expectations. unmatched = querier.FillExpectationMapForCiBuilders( test_expectation_map, ci_builders) try_builders = builders.GetTryBuilders(ci_builders) unmatched.update( querier.FillExpectationMapForTryBuilders(test_expectation_map, try_builders)) unused_expectations = expectations.FilterOutUnusedExpectations( test_expectation_map) stale, semi_stale, active = expectations.SplitExpectationsByStaleness( test_expectation_map) result_output.OutputResults(stale, semi_stale, active, unmatched, unused_expectations, args.output_format) affected_urls = set() stale_message = '' if args.remove_stale_expectations: stale_expectations = [] for _, expectation_map in stale.iteritems(): stale_expectations.extend(expectation_map.keys()) stale_expectations.extend(unused_expectations) affected_urls |= expectations.RemoveExpectationsFromFile( stale_expectations, args.expectation_file) stale_message += ( 'Stale expectations removed from %s. Stale comments, ' 'etc. may still need to be removed.\n' % args.expectation_file) if args.modify_semi_stale_expectations: affected_urls |= expectations.ModifySemiStaleExpectations( semi_stale, args.expectation_file) stale_message += ('Semi-stale expectations modified in %s. Stale ' 'comments, etc. may still need to be removed.\n' % args.expectation_file) if stale_message: print(stale_message) if affected_urls: result_output.OutputAffectedUrls(affected_urls)
def testIgnoreExpectation(self): """Tests that specifying to ignore an expectation does nothing.""" self._input_mock.return_value = 'i' # yapf: disable test_expectation_map = data_types.TestExpectationMap({ 'foo/test': data_types.ExpectationBuilderMap({ data_types.Expectation( 'foo/test', ['win'], 'Failure', 'crbug.com/1234'): data_types.BuilderStepMap(), }), }) # yapf: enable modified_urls = expectations.ModifySemiStaleExpectations( test_expectation_map, self.filename) self.assertEqual(modified_urls, set()) with open(self.filename) as f: self.assertEqual(f.read(), FAKE_EXPECTATION_FILE_CONTENTS)