summaryrefslogtreecommitdiff
path: root/tests/testutils/context.py
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2019-09-18 17:55:19 +0100
committerTristan Maat <tristan.maat@codethink.co.uk>2019-10-10 12:21:15 +0100
commit17144d84c2b63daf6e3aa9b42c6c773f134e8660 (patch)
tree1fd9a4e53ed641592dd26e3d07d241554463a4cf /tests/testutils/context.py
parentacf99b789a92e9e124e9492d1dbbc34b83f5ab23 (diff)
downloadbuildstream-17144d84c2b63daf6e3aa9b42c6c773f134e8660.tar.gz
testutils/context.py: Mock tasks instead of accepting Nones
To ensure that we only disable element loading task progress reporting for very specific code paths, we need to teach the test suite to be a bit smarter. For this reason we now mock a _Task object and return it in our mock context's relevant method invocations. Other code paths that deliberately invoke the loader without task reporting now mark their loads with NO_PROGRESS.
Diffstat (limited to 'tests/testutils/context.py')
-rw-r--r--tests/testutils/context.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/testutils/context.py b/tests/testutils/context.py
index 899bad247..849895e92 100644
--- a/tests/testutils/context.py
+++ b/tests/testutils/context.py
@@ -15,10 +15,13 @@
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
import os
+from unittest.mock import MagicMock
+from types import MethodType
from contextlib import contextmanager
from buildstream._context import Context
+from buildstream._state import _Task
# Handle messages from the pipeline
@@ -26,6 +29,11 @@ def _dummy_message_handler(message, is_silenced):
pass
+@contextmanager
+def _get_dummy_task(self, activity_name, *, element_name=None, full_name=None, silent_nested=False):
+ yield MagicMock(spec=_Task("state", activity_name, full_name, 0))
+
+
# dummy_context()
#
# Context manager to create minimal context for tests.
@@ -42,5 +50,6 @@ def dummy_context(*, config=None):
context.load(config=config)
context.messenger.set_message_handler(_dummy_message_handler)
+ context.messenger.simple_task = MethodType(_get_dummy_task, context.messenger)
yield context