def test_find_current_step_failures_in_progress_now_passing(self): '''Test that a passing run for the in-progress build overrides a failing run from the previous complete build. ''' def fetch(build_id): results = None if build_id == 4119: results = 2 return { 'number': build_id, 'results': results, }, 'cache' def mock_complete_steps_by_type(build): passing = [{'name': 'foo_tests'}] if build['number'] == 4119: failing = [{'name': 'foo_tests'}] else: failing = [] return passing, failing old_complete_steps_by_type = alert_builder.complete_steps_by_type try: alert_builder.complete_steps_by_type = mock_complete_steps_by_type step_failures = alert_builder.find_current_step_failures(fetch, [4120, 4119]) expected_step_failures = [] self.assertEqual(step_failures, expected_step_failures) finally: alert_builder.complete_steps_by_type = old_complete_steps_by_type
def test_find_current_step_failures_in_progress_still_failing(self): '''Test that only the last failing step gets included if the test step failed in both the in-progress build and the last completed build. ''' def fetch(build_id): results = None if build_id == 4119: results = 2 return { 'number': build_id, 'results': results, }, 'cache' def mock_complete_steps_by_type(build): passing = [] if build['number'] == 4119: failing = [{'name': 'foo_tests'}] else: failing = [{'name': 'foo_tests'}] return passing, failing old_complete_steps_by_type = alert_builder.complete_steps_by_type try: alert_builder.complete_steps_by_type = mock_complete_steps_by_type step_failures = alert_builder.find_current_step_failures(fetch, [4120, 4119]) expected_step_failures = [ {'build_number': 4120, 'step_name': 'foo_tests'} ] self.assertEqual(step_failures, expected_step_failures) finally: alert_builder.complete_steps_by_type = old_complete_steps_by_type
def test_find_current_step_failures_in_progress(self): '''Test that failing steps from the previous completed build get included if the in-progress build hasn't run this test step yet. ''' def fetch(build_id): results = None if build_id == 4119: results = 2 return { 'number': build_id, 'results': results, }, 'cache' def mock_complete_steps_by_type(build): passing = [] if build['number'] == 4119: failing = [{'name': 'foo_tests'}, {'name': 'steps'}] else: failing = [] return passing, failing old_complete_steps_by_type = alert_builder.complete_steps_by_type try: alert_builder.complete_steps_by_type = mock_complete_steps_by_type step_failures = alert_builder.find_current_step_failures(fetch, [4120, 4119]) expected_step_failures = [ {'build_number': 4119, 'step_name': 'foo_tests'} ] self.assertEqual(step_failures, expected_step_failures) finally: alert_builder.complete_steps_by_type = old_complete_steps_by_type
def test_find_current_step_failures_only_ignored_steps(self): '''Test that when the only failing steps are ignored steps, we return those as the list of step failures. ''' def fetch(build_id): return { 'number': 4119, 'results': 2, }, 'cache' def mock_complete_steps_by_type(build): passing = [] failing = [{'name': 'steps'}] return passing, failing old_complete_steps_by_type = alert_builder.complete_steps_by_type try: alert_builder.complete_steps_by_type = mock_complete_steps_by_type step_failures = alert_builder.find_current_step_failures(fetch, [4119]) expected_step_failures = [ {'build_number': 4119, 'step_name': 'steps'} ] self.assertEqual(step_failures, expected_step_failures) finally: alert_builder.complete_steps_by_type = old_complete_steps_by_type
def test_find_current_step_failures_no_build(self): '''Test that we don't crash when the buildbot/CBE both don't have a build for a given build ID. ''' def fetch(build_id): return None, None step_failures = alert_builder.find_current_step_failures(fetch, [4119]) expected_step_failures = [] self.assertEqual(step_failures, expected_step_failures)
def test_find_current_step_failures_no_recent_build_ids(self): '''Silly test to get coverage of scenario that never happens, i.e. padding in an empty list of recent build ids. ''' step_failures = alert_builder.find_current_step_failures(None, []) self.assertEqual(step_failures, [])