summaryrefslogtreecommitdiff
path: root/src/buildstream
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 /src/buildstream
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 'src/buildstream')
-rw-r--r--src/buildstream/_loader/loader.py13
-rw-r--r--src/buildstream/_project.py2
2 files changed, 10 insertions, 5 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py
index 5eaed9337..a9e686f1c 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -37,6 +37,11 @@ from ..types import CoreWarnings
from .._message import Message, MessageType
+# This should be used to deliberately disable progress reporting when
+# collecting an element
+_NO_PROGRESS = object()
+
+
# Loader():
#
# The Loader class does the heavy lifting of parsing target
@@ -94,7 +99,7 @@ class Loader():
# Raises: LoadError
#
# Returns: The toplevel LoadElement
- def load(self, targets, rewritable=False, ticker=None, task=None):
+ def load(self, targets, task, rewritable=False, ticker=None):
for filename in targets:
if os.path.isabs(filename):
@@ -148,7 +153,7 @@ class Loader():
self._clean_caches()
# Cache how many Elements have just been loaded
- if task:
+ if task is not _NO_PROGRESS:
# Workaround for task potentially being None (because no State object)
self.loaded = task.current_progress
@@ -483,7 +488,7 @@ class Loader():
# Cache it now, make sure it's already there before recursing
self._meta_elements[element.name] = meta_element
- if task:
+ if task is not _NO_PROGRESS:
task.add_current_progress()
return meta_element
@@ -593,7 +598,7 @@ class Loader():
# meta junction element
# XXX: This is a likely point for progress reporting to end up
# missing some elements, but it currently doesn't appear to be the case.
- meta_element = self._collect_element_no_deps(self._elements[filename], None)
+ meta_element = self._collect_element_no_deps(self._elements[filename], _NO_PROGRESS)
if meta_element.kind != 'junction':
raise LoadError("{}{}: Expected junction but element kind is {}"
.format(provenance_str, filename, meta_element.kind),
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index 6ae8aa9db..7ba93bba4 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -433,7 +433,7 @@ class Project():
#
def load_elements(self, targets, *, rewritable=False):
with self._context.messenger.simple_task("Loading elements", silent_nested=True) as task:
- meta_elements = self.loader.load(targets, rewritable=rewritable, ticker=None, task=task)
+ meta_elements = self.loader.load(targets, task, rewritable=rewritable, ticker=None)
with self._context.messenger.simple_task("Resolving elements") as task:
if task: