Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1264)

Unified Diff: appengine/findit/common/findit_testcase.py

Issue 2158533002: [Findit] Use unittest.mock for testing and create a shared method to mock pipeline. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/findit/waterfall/analyze_build_failure_pipeline.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/common/findit_testcase.py
diff --git a/appengine/findit/common/findit_testcase.py b/appengine/findit/common/findit_testcase.py
index 4f9eabcf527dd8d336d227a9fed83ddcb16793a6..7050427d116c46d44d224c04948160b911a236d6 100644
--- a/appengine/findit/common/findit_testcase.py
+++ b/appengine/findit/common/findit_testcase.py
@@ -7,7 +7,28 @@ import os
from testing_utils import testing
-class FinditTestCase(testing.AppengineTestCase):
+class FinditTestCase(testing.AppengineTestCase): # pragma: no cover.
# Setup the customized queues.
taskqueue_stub_root_path = os.path.join(
os.path.dirname(__file__), os.path.pardir)
+
+ def MockPipeline(
+ self, pipeline_class, result, expected_args, expected_kwargs=None):
+ """ Mocks a pipeline to return a value and asserts the expected parameters.
+
+ Args:
+ pipeline_class (class): The class of the pipeline to be mocked.
+ result (object): The result to be returned by the pipeline.
+ expected_args (list): The list of positional parameters expected by the
+ pipeline.
+ expected_kwargs (dict): The dict of key-value parameters expected by the
+ pipeline. Default is None.
+ """
+ expected_kwargs = expected_kwargs or {}
+
+ def Mocked_run(_, *args, **kwargs):
+ self.assertEqual(list(args), expected_args)
+ self.assertEqual(kwargs, expected_kwargs)
+ return result
+
+ self.mock(pipeline_class, 'run', Mocked_run)
« no previous file with comments | « no previous file | appengine/findit/waterfall/analyze_build_failure_pipeline.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698