def test_pre_post_commands_ordering(self, mock_cedar, mock_copy_perf, mock_check_call, mock_prep_rep, mock_parse_results, mock_run_test, mock_pre_post, mock_delays): """Test that pre and post commands are called in the right order""" real_config_dict = ConfigDict('test_control') real_config_dict.raw = self.config run_tests(real_config_dict) # We will check that the calls to run_pre_post_commands() happened in expected order expected_args = [ 'pre_task', 'pre_test', 'post_test', 'between_tests', 'pre_test', 'post_test', 'between_tests', 'pre_test', 'post_test', 'post_task' ] observed_args = [args[0][0] for args in mock_pre_post.call_args_list] self.assertEqual(expected_args, observed_args)
def test_cedar_report(self, mock_cedar_report, mock_copy_perf, mock_check_call, mock_prep_rep, mock_parse_results, mock_run_test, mock_pre_post, mock_delays): """Test that cedar report is called the correct number of times""" real_config_dict = ConfigDict('test_control') real_config_dict.raw = self.config run_tests(real_config_dict) mock_cedar_test = MagicMock() mock_parse_results.return_value = (True, [mock_cedar_test]) run_tests(real_config_dict) mock_cedar_report.assert_called() mock_cedar_report().add_test.assert_has_calls([ call(mock_cedar_test), call(mock_cedar_test), call(mock_cedar_test), ]) mock_cedar_report().write_report.assert_called()
def test_run_test_exception(self, mock_cedar, mock_copy_perf, mock_check_call, mock_prep_rep, mock_parse_results, mock_pre_post, mock_delays): """ Test CalledProcessErrors with cause run_tests return false but other errors will cause it to return true """ real_config_dict = ConfigDict('test_control') real_config_dict.raw = self.config # pylint: disable=bad-continuation with patch('test_control.run_test', side_effect=[ subprocess.CalledProcessError(99, 'failed-cmd'), 0, 0 ]): utter_failure = run_tests(real_config_dict) self.assertFalse(utter_failure) with patch('test_control.run_test', side_effect=[ValueError(), 0, 0]): utter_failure = run_tests(real_config_dict) self.assertTrue(utter_failure)