summaryrefslogtreecommitdiff
path: root/src/buildstream/_loader/loader.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 /src/buildstream/_loader/loader.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 'src/buildstream/_loader/loader.py')
-rw-r--r--src/buildstream/_loader/loader.py13
1 files changed, 9 insertions, 4 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),