diff options
author | Benjamin Schubert <contact@benschubert.me> | 2020-10-09 07:59:23 +0000 |
---|---|---|
committer | Benjamin Schubert <1593324-BenjaminSchubert@users.noreply.gitlab.com> | 2020-10-26 14:22:00 +0000 |
commit | f1986c135c8bc8132c15c4b45230e872d13ad60a (patch) | |
tree | 3efd2ca64085a2734bb72fe4add0ba76216ac8e7 | |
parent | 4eaf1ba5ae52d722b9413af0fc0f9285ea0ae886 (diff) | |
download | buildstream-f1986c135c8bc8132c15c4b45230e872d13ad60a.tar.gz |
workspace.py: Remove some abstractions and write the whole test in place
This is to remove some hoops that are currently used, that do not fit
well with most of the style in the code. It also removes indirections
and make the test easier to understand
-rw-r--r-- | src/buildstream/testing/_sourcetests/workspace.py | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/src/buildstream/testing/_sourcetests/workspace.py b/src/buildstream/testing/_sourcetests/workspace.py index ebc03c97d..a171bf703 100644 --- a/src/buildstream/testing/_sourcetests/workspace.py +++ b/src/buildstream/testing/_sourcetests/workspace.py @@ -32,59 +32,44 @@ TOP_DIR = os.path.dirname(os.path.realpath(__file__)) DATA_DIR = os.path.join(TOP_DIR, "project") -class WorkspaceCreator: - def __init__(self, cli, tmpdir, datafiles): - self.cli = cli - self.tmpdir = tmpdir - - 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): - element_name = "workspace-test-{}.bst".format(kind) - element_path = os.path.join(self.project_path, "elements") - # 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. - repo = create_repo(kind, str(self.tmpdir)) - ref = repo.create(self.bin_files_path) - - # Write out our test target - element = {"kind": "import", "sources": [repo.source_config(ref=ref)]} - _yaml.roundtrip_dump(element, os.path.join(element_path, element_name)) +@pytest.mark.datafiles(DATA_DIR) +def test_open(cli, tmpdir, datafiles, kind): + project_path = str(datafiles) + bin_files_path = os.path.join(project_path, "files", "bin-files") - # 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 + element_name = "workspace-test-{}.bst".format(kind) + element_path = os.path.join(project_path, "elements") - def open_workspace(self, kind): + # Create our repo object of the given source type with + # the bin files, and then collect the initial ref. + repo = create_repo(kind, str(tmpdir)) + ref = repo.create(bin_files_path) - element_name, workspace_dir = self.create_workspace_element(kind) - os.makedirs(self.workspace_cmd, exist_ok=True) + # Write out our test target + element = {"kind": "import", "sources": [repo.source_config(ref=ref)]} + _yaml.roundtrip_dump(element, os.path.join(element_path, element_name)) - # Now open the workspace, this should have the effect of automatically - # fetching the source from the repo. - args = ["workspace", "open"] - args.extend(["--directory", workspace_dir]) + # Assert that there is no reference, a fetch is needed + assert cli.get_element_state(project_path, element_name) == "fetch needed" - args.append(element_name) - result = self.cli.run(cwd=self.workspace_cmd, project=self.project_path, args=args) + workspace_cmd = os.path.join(project_path, "workspace_cmd") + os.makedirs(workspace_cmd, exist_ok=True) + # remove the '.bst' at the end of the element + workspace_dir = os.path.join(workspace_cmd, element_name[:-4]) - result.assert_success() + # Now open the workspace, this should have the effect of automatically + # fetching the source from the repo. + args = ["workspace", "open"] + args.extend(["--directory", workspace_dir]) - # Assert that we are now buildable because the source is now cached. - assert self.cli.get_element_state(self.project_path, element_name) == "buildable" + args.append(element_name) + result = cli.run(cwd=workspace_cmd, project=project_path, args=args) - # 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) + result.assert_success() + # Assert that we are now buildable because the source is now cached. + assert cli.get_element_state(project_path, element_name) == "buildable" -@pytest.mark.datafiles(DATA_DIR) -def test_open(cli, tmpdir, datafiles, kind): - workspace_object = WorkspaceCreator(cli, tmpdir, datafiles) - workspace_object.open_workspace(kind) + # 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) |