From 54fee6c8589e79728b5933598f1e4652540ca205 Mon Sep 17 00:00:00 2001 From: Phillip Smyth Date: Wed, 18 Jul 2018 16:06:52 +0100 Subject: _stream.py: Added functionality for workspace open -f tests/frontend/workspace.py: Added tests --- buildstream/_stream.py | 6 +++++- tests/frontend/workspace.py | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/buildstream/_stream.py b/buildstream/_stream.py index 365709c46..dcefc64f1 100644 --- a/buildstream/_stream.py +++ b/buildstream/_stream.py @@ -476,7 +476,7 @@ class Stream(): # Check for workspace config workspace = workspaces.get_workspace(target._get_full_name()) - if workspace: + if workspace and not force: raise StreamError("Workspace '{}' is already defined at: {}" .format(target.name, workspace.path)) @@ -495,6 +495,10 @@ class Stream(): "fetch the latest version of the " + "source.") + if workspace: + workspaces.delete_workspace(target._get_full_name()) + workspaces.save_config() + shutil.rmtree(directory) try: os.makedirs(directory, exist_ok=True) except OSError as e: diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py index 90b50613f..566fbb1cd 100644 --- a/tests/frontend/workspace.py +++ b/tests/frontend/workspace.py @@ -123,6 +123,58 @@ def test_open_force(cli, tmpdir, datafiles, kind): result.assert_success() +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("kind", repo_kinds) +def test_open_force_open(cli, tmpdir, datafiles, kind): + element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False) + + # Assert the workspace dir exists + assert os.path.exists(workspace) + + # Now open the workspace again with --force, this should happily succeed + result = cli.run(project=project, args=[ + 'workspace', 'open', '--force', element_name, workspace + ]) + result.assert_success() + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("kind", repo_kinds) +def test_open_force_different_workspace(cli, tmpdir, datafiles, kind): + element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False, "-alpha") + + # Assert the workspace dir exists + assert os.path.exists(workspace) + + hello_path = os.path.join(workspace, 'usr', 'bin', 'hello') + hello1_path = os.path.join(workspace, 'usr', 'bin', 'hello1') + + tmpdir = os.path.join(str(tmpdir), "-beta") + shutil.move(hello_path, hello1_path) + element_name2, project2, workspace2 = open_workspace(cli, tmpdir, datafiles, kind, False, "-beta") + + # Assert the workspace dir exists + assert os.path.exists(workspace2) + + # Assert that workspace 1 contains the modified file + assert os.path.exists(hello1_path) + + # Assert that workspace 2 contains the unmodified file + assert os.path.exists(os.path.join(workspace2, 'usr', 'bin', 'hello')) + + # Now open the workspace again with --force, this should happily succeed + result = cli.run(project=project, args=[ + 'workspace', 'open', '--force', element_name2, workspace + ]) + + # Assert that the file in workspace 1 has been replaced + # With the file from workspace 2 + assert os.path.exists(hello_path) + assert not os.path.exists(hello1_path) + + result.assert_success() + + @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("kind", repo_kinds) def test_close(cli, tmpdir, datafiles, kind): -- cgit v1.2.1