You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:35:33 UTC
[buildstream] 01/15: workspace.py: Simplify test by only allowing
opening a single workspace
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch bschubert/standardize-source-tests
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 301c1649d8ecead56dfa89cde956e8a74c35d771
Author: Benjamin Schubert <co...@benschubert.me>
AuthorDate: Thu Oct 8 21:23:50 2020 +0000
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
---
src/buildstream/testing/_sourcetests/workspace.py | 62 ++++-------------------
1 file changed, 10 insertions(+), 52 deletions(-)
diff --git a/src/buildstream/testing/_sourcetests/workspace.py b/src/buildstream/testing/_sourcetests/workspace.py
index 3520a8c..7f3c5de 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)