summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2019-10-22 15:37:33 +0100
committerChandan Singh <csingh43@bloomberg.net>2019-10-22 15:37:33 +0100
commit9f947521fe652daec78c4554653c26024dbffe87 (patch)
treeca78ba737ecd8e738b60c6f0b0f9fbd18b16ba9c
parent27d3c61a3d91e4f0a962add150beafc3cd0fefe2 (diff)
downloadbuildstream-chandan/fix-source-key-test.tar.gz
tests/sources/keytest: Ensure element state is updated as expectedchandan/fix-source-key-test
This contains two changes: * tests/sources/keytest.py: Ensure that the element state before/after BuildStream operations is updated as expected. Previously we were just checking that the command succeeded. * tests/sources/project_key_test/plugins/sources/key-test.py: Update the dummy plugin that's used for tests, such that it conforms to the expectations of a BuildStream source class. Fixes #1179.
-rw-r--r--tests/sources/keytest.py3
-rw-r--r--tests/sources/project_key_test/plugins/sources/key-test.py18
2 files changed, 12 insertions, 9 deletions
diff --git a/tests/sources/keytest.py b/tests/sources/keytest.py
index dbfe97ab5..5b5ccaba0 100644
--- a/tests/sources/keytest.py
+++ b/tests/sources/keytest.py
@@ -41,8 +41,11 @@ def test_generate_key(cli, datafiles):
res = cli.run(project=project_dir, args=["build", "key-test.bst"])
res.assert_main_error(ErrorDomain.PIPELINE, "inconsistent-pipeline")
+ assert cli.get_element_state(project_dir, "key-test.bst") == "no reference"
res = cli.run(project=project_dir, args=["source", "track", "key-test.bst"])
res.assert_success()
+ assert cli.get_element_state(project_dir, "key-test.bst") == "fetch needed"
res = cli.run(project=project_dir, args=["build", "--track", "key-test.bst"])
res.assert_success()
+ assert cli.get_element_state(project_dir, "key-test.bst") == "cached"
diff --git a/tests/sources/project_key_test/plugins/sources/key-test.py b/tests/sources/project_key_test/plugins/sources/key-test.py
index 9331ba094..428846a3e 100644
--- a/tests/sources/project_key_test/plugins/sources/key-test.py
+++ b/tests/sources/project_key_test/plugins/sources/key-test.py
@@ -1,3 +1,5 @@
+import os
+
from buildstream import Source, Consistency
@@ -5,15 +7,11 @@ class KeyTest(Source):
""" This plugin should fail if get_unique_key is called before track
"""
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.ref = False
-
def preflight(self):
pass
def configure(self, node):
- pass
+ self.ref = node.get_bool("ref", False)
def get_unique_key(self):
assert self.ref
@@ -29,19 +27,21 @@ class KeyTest(Source):
pass
def get_ref(self):
- pass
+ return self.ref
def set_ref(self, ref, node):
- pass
+ node["ref"] = self.ref = ref
def track(self, **kwargs):
- self.ref = True
+ return True
def fetch(self, **kwargs):
pass
def stage(self, directory):
- pass
+ # Create a dummy file as output, as import elements do not allow empty
+ # output. Its existence is a statement that we have staged ourselves.
+ open(os.path.join(directory, "output"), "w").close()
def setup():