diff options
author | Phillip Smyth <phillipsmyth@codethink.co.uk> | 2018-07-18 16:06:52 +0100 |
---|---|---|
committer | Valentin David <valentin.david@gmail.com> | 2018-08-13 19:04:16 +0000 |
commit | 60c817c0323647ef24714f3d64ba7d2b3c0bcbbc (patch) | |
tree | 765b04f4a9a06e6c1ccd5fbcc8d746be54acf27e | |
parent | 60df233d629782b6ce47cb51b46ae0187adb5e72 (diff) | |
download | buildstream-60c817c0323647ef24714f3d64ba7d2b3c0bcbbc.tar.gz |
_stream.py: Added functionality for workspace open -f
tests/frontend/workspace.py: Added tests
-rw-r--r-- | buildstream/_stream.py | 6 | ||||
-rw-r--r-- | tests/frontend/workspace.py | 52 |
2 files changed, 57 insertions, 1 deletions
diff --git a/buildstream/_stream.py b/buildstream/_stream.py index 99748f8e0..017f1e445 100644 --- a/buildstream/_stream.py +++ b/buildstream/_stream.py @@ -478,7 +478,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)) @@ -497,6 +497,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 @@ -125,6 +125,58 @@ def test_open_force(cli, tmpdir, datafiles, kind): @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): element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False) |