This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch bschubert/standardize-source-tests in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 14a136e8e1311b9b6109f20c0cf96d96a2886c8b Author: Benjamin Schubert <[email protected]> AuthorDate: Thu Oct 8 21:30:06 2020 +0000 workspace.py: Remove arguments that are unused during the test --- src/buildstream/testing/_sourcetests/workspace.py | 46 ++++++++--------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/src/buildstream/testing/_sourcetests/workspace.py b/src/buildstream/testing/_sourcetests/workspace.py index 7f3c5de..881e85b 100644 --- a/src/buildstream/testing/_sourcetests/workspace.py +++ b/src/buildstream/testing/_sourcetests/workspace.py @@ -20,7 +20,6 @@ # pylint: disable=redefined-outer-name import os -import shutil import pytest from buildstream import _yaml @@ -34,28 +33,20 @@ DATA_DIR = os.path.join(TOP_DIR, "project") class WorkspaceCreator: - def __init__(self, cli, tmpdir, datafiles, project_path=None): + def __init__(self, cli, tmpdir, datafiles): self.cli = cli self.tmpdir = tmpdir - self.datafiles = datafiles - if not project_path: - project_path = str(datafiles) - else: - shutil.copytree(str(datafiles), project_path) - - self.project_path = project_path - self.bin_files_path = os.path.join(project_path, "files", "bin-files") + self.project_path = str(datafiles) + self.bin_files_path = os.path.join(self.project_path, "files", "bin-files") self.workspace_cmd = os.path.join(self.project_path, "workspace_cmd") - def create_workspace_element(self, kind, suffix="", workspace_dir=None, element_attrs=None): - element_name = "workspace-test-{}{}.bst".format(kind, suffix) + def create_workspace_element(self, kind): + element_name = "workspace-test-{}.bst".format(kind) element_path = os.path.join(self.project_path, "elements") - if not workspace_dir: - workspace_dir = os.path.join(self.workspace_cmd, element_name) - if workspace_dir[-4:] == ".bst": - workspace_dir = workspace_dir[:-4] + # remove the '.bst' at the end of the element + workspace_dir = os.path.join(self.workspace_cmd, element_name[-4:]) # Create our repo object of the given source type with # the bin files, and then collect the initial ref. @@ -64,40 +55,33 @@ class WorkspaceCreator: # Write out our test target element = {"kind": "import", "sources": [repo.source_config(ref=ref)]} - if element_attrs: - element = {**element, **element_attrs} _yaml.roundtrip_dump(element, os.path.join(element_path, element_name)) # Assert that there is no reference, a fetch is needed assert self.cli.get_element_state(self.project_path, element_name) == "fetch needed" return element_name, workspace_dir - def open_workspace(self, kind, suffix=None, workspace_dir=None, element_attrs=None, no_checkout=False): + def open_workspace(self, kind): - element_name, workspace_dir = self.create_workspace_element(kind, suffix, workspace_dir, element_attrs) + element_name, workspace_dir = self.create_workspace_element(kind) os.makedirs(self.workspace_cmd, exist_ok=True) # Now open the workspace, this should have the effect of automatically # fetching the source from the repo. args = ["workspace", "open"] - - if no_checkout: - args.append("--no-checkout") - if workspace_dir is not None: - args.extend(["--directory", workspace_dir]) + args.extend(["--directory", workspace_dir]) 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. - assert self.cli.get_element_state(self.project_path, element_name) == "buildable" + # Assert that we are now buildable because the source is now cached. + assert self.cli.get_element_state(self.project_path, element_name) == "buildable" - # Check that the executable hello file is found in each workspace - filename = os.path.join(workspace_dir, "usr", "bin", "hello") - assert os.path.exists(filename) + # Check that the executable hello file is found in each workspace + filename = os.path.join(workspace_dir, "usr", "bin", "hello") + assert os.path.exists(filename) @pytest.mark.datafiles(DATA_DIR)
