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 22b6591950f79270e2a28d1930f2c83e56d87836 Author: Benjamin Schubert <[email protected]> AuthorDate: Fri Oct 9 07:59:23 2020 +0000 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 --- src/buildstream/testing/_sourcetests/workspace.py | 77 +++++++++-------------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/src/buildstream/testing/_sourcetests/workspace.py b/src/buildstream/testing/_sourcetests/workspace.py index 881e85b..f99f91a 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)) [email protected](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" [email protected](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)
