summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2020-10-08 21:23:50 +0000
committerBenjamin Schubert <1593324-BenjaminSchubert@users.noreply.gitlab.com>2020-10-26 14:22:00 +0000
commitdf68855147c8bdc6b863ef9e4daec52a3c8cfe52 (patch)
treebf7c2995ae03aa797714207bf8a965afbd7274fb
parent5a82e0dbd50153cc42adede876c439eb7021e51e (diff)
downloadbuildstream-df68855147c8bdc6b863ef9e4daec52a3c8cfe52.tar.gz
workspace.py: Simplify test by only allowing opening a single workspace
This test seems to be copy pasted from our tests around workspaces and doesn't need to be so complicated
-rw-r--r--src/buildstream/testing/_sourcetests/workspace.py62
1 files changed, 10 insertions, 52 deletions
diff --git a/src/buildstream/testing/_sourcetests/workspace.py b/src/buildstream/testing/_sourcetests/workspace.py
index 3520a8cc4..7f3c5dea4 100644
--- a/src/buildstream/testing/_sourcetests/workspace.py
+++ b/src/buildstream/testing/_sourcetests/workspace.py
@@ -67,33 +67,14 @@ class WorkspaceCreator:
if element_attrs:
element = {**element, **element_attrs}
_yaml.roundtrip_dump(element, os.path.join(element_path, element_name))
- return element_name, element_path, workspace_dir
-
- def create_workspace_elements(self, kinds, suffixs=None, workspace_dir_usr=None, element_attrs=None):
-
- element_tuples = []
-
- if suffixs is None:
- suffixs = ["",] * len(kinds)
- else:
- if len(suffixs) != len(kinds):
- raise "terable error"
-
- for suffix, kind in zip(suffixs, kinds):
- element_name, _, workspace_dir = self.create_workspace_element(
- kind, suffix, workspace_dir_usr, element_attrs
- )
- element_tuples.append((element_name, workspace_dir))
# Assert that there is no reference, a fetch is needed
- states = self.cli.get_element_states(self.project_path, [e for e, _ in element_tuples])
- assert not any(states[e] != "fetch needed" for e, _ in element_tuples)
-
- return element_tuples
+ assert self.cli.get_element_state(self.project_path, element_name) == "fetch needed"
+ return element_name, workspace_dir
- def open_workspaces(self, kinds, suffixs=None, workspace_dir=None, element_attrs=None, no_checkout=False):
+ def open_workspace(self, kind, suffix=None, workspace_dir=None, element_attrs=None, no_checkout=False):
- element_tuples = self.create_workspace_elements(kinds, suffixs, workspace_dir, element_attrs)
+ element_name, workspace_dir = self.create_workspace_element(kind, suffix, workspace_dir, element_attrs)
os.makedirs(self.workspace_cmd, exist_ok=True)
# Now open the workspace, this should have the effect of automatically
@@ -103,46 +84,23 @@ class WorkspaceCreator:
if no_checkout:
args.append("--no-checkout")
if workspace_dir is not None:
- assert len(element_tuples) == 1, "test logic error"
- _, workspace_dir = element_tuples[0]
args.extend(["--directory", workspace_dir])
- args.extend([element_name for element_name, workspace_dir_suffix in element_tuples])
+ args.append(element_name)
result = self.cli.run(cwd=self.workspace_cmd, project=self.project_path, args=args)
result.assert_success()
if not no_checkout:
# Assert that we are now buildable because the source is now cached.
- states = self.cli.get_element_states(self.project_path, [e for e, _ in element_tuples])
- assert not any(states[e] != "buildable" for e, _ in element_tuples)
+ assert self.cli.get_element_state(self.project_path, element_name) == "buildable"
# Check that the executable hello file is found in each workspace
- for _, workspace in element_tuples:
- filename = os.path.join(workspace, "usr", "bin", "hello")
- assert os.path.exists(filename)
-
- return element_tuples
-
-
-def open_workspace(
- cli,
- tmpdir,
- datafiles,
- kind,
- suffix="",
- workspace_dir=None,
- project_path=None,
- element_attrs=None,
- no_checkout=False,
-):
- workspace_object = WorkspaceCreator(cli, tmpdir, datafiles, project_path)
- workspaces = workspace_object.open_workspaces((kind,), (suffix,), workspace_dir, element_attrs, no_checkout)
- assert len(workspaces) == 1
- element_name, workspace = workspaces[0]
- return element_name, workspace_object.project_path, workspace
+ filename = os.path.join(workspace_dir, "usr", "bin", "hello")
+ assert os.path.exists(filename)
@pytest.mark.datafiles(DATA_DIR)
def test_open(cli, tmpdir, datafiles, kind):
- open_workspace(cli, tmpdir, datafiles, kind)
+ workspace_object = WorkspaceCreator(cli, tmpdir, datafiles)
+ workspace_object.open_workspace(kind)