diff options
Diffstat (limited to 'python/mozversioncontrol/test')
-rw-r--r-- | python/mozversioncontrol/test/conftest.py | 84 | ||||
-rw-r--r-- | python/mozversioncontrol/test/python.toml | 28 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_branch.py | 57 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_commit.py | 72 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_context_manager.py | 28 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_create_try_commit.py | 45 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_get_branch_nodes.py | 46 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_get_commit_patches.py | 56 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_get_mozilla_remote_args.py | 47 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_get_upstream_remotes.py | 45 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_push_to_try.py | 81 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_remove_current_commit.py | 44 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_update.py | 63 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_workdir_outgoing.py | 108 | ||||
-rw-r--r-- | python/mozversioncontrol/test/test_working_directory.py | 46 |
15 files changed, 850 insertions, 0 deletions
diff --git a/python/mozversioncontrol/test/conftest.py b/python/mozversioncontrol/test/conftest.py new file mode 100644 index 0000000000..78e5ad7ca8 --- /dev/null +++ b/python/mozversioncontrol/test/conftest.py @@ -0,0 +1,84 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import os +import shutil +import subprocess +from pathlib import Path + +import pytest + +SETUP = { + "hg": [ + """ + echo "foo" > foo + echo "bar" > bar + hg init + hg add * + hg commit -m "Initial commit" + hg phase --public . + """, + """ + echo [paths] > .hg/hgrc + echo "default = ../remoterepo" >> .hg/hgrc + """, + ], + "git": [ + """ + echo "foo" > foo + echo "bar" > bar + git init + git config user.name "Testing McTesterson" + git config user.email "<test@example.org>" + git add * + git commit -am "Initial commit" + """, + """ + git remote add upstream ../remoterepo + git fetch upstream + git branch -u upstream/master + """, + ], +} + + +class RepoTestFixture: + def __init__(self, repo_dir: Path, vcs: str, steps: [str]): + self.dir = repo_dir + self.vcs = vcs + + # This creates a step iterator. Each time execute_next_step() + # is called the next set of instructions will be executed. + self.steps = (shell(cmd, self.dir) for cmd in steps) + + def execute_next_step(self): + next(self.steps) + + +def shell(cmd, working_dir): + for step in cmd.split(os.linesep): + subprocess.check_call(step, shell=True, cwd=working_dir) + + +@pytest.fixture(params=["git", "hg"]) +def repo(tmpdir, request): + tmpdir = Path(tmpdir) + vcs = request.param + steps = SETUP[vcs] + + if hasattr(request.module, "STEPS"): + steps.extend(request.module.STEPS[vcs]) + + repo_dir = (tmpdir / "repo").resolve() + (tmpdir / "repo").mkdir() + + repo_test_fixture = RepoTestFixture(repo_dir, vcs, steps) + + repo_test_fixture.execute_next_step() + + shutil.copytree(str(repo_dir), str(tmpdir / "remoterepo")) + + repo_test_fixture.execute_next_step() + + yield repo_test_fixture diff --git a/python/mozversioncontrol/test/python.toml b/python/mozversioncontrol/test/python.toml new file mode 100644 index 0000000000..a194c2a22a --- /dev/null +++ b/python/mozversioncontrol/test/python.toml @@ -0,0 +1,28 @@ +[DEFAULT] +subsuite = "mozversioncontrol" + +["test_branch.py"] + +["test_commit.py"] + +["test_context_manager.py"] + +["test_create_try_commit.py"] + +["test_get_branch_nodes.py"] + +["test_get_commit_patches.py"] + +["test_get_mozilla_remote_args.py"] + +["test_get_upstream_remotes.py"] + +["test_push_to_try.py"] + +["test_remove_current_commit.py"] + +["test_update.py"] + +["test_workdir_outgoing.py"] + +["test_working_directory.py"] diff --git a/python/mozversioncontrol/test/test_branch.py b/python/mozversioncontrol/test/test_branch.py new file mode 100644 index 0000000000..7d211f18e8 --- /dev/null +++ b/python/mozversioncontrol/test/test_branch.py @@ -0,0 +1,57 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit +import pytest +from looseversion import LooseVersion + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + hg bookmark test + """, + """ + echo "bar" > foo + hg commit -m "second commit" + """, + ], + "git": [ + """ + git checkout -b test + """, + """ + echo "bar" > foo + git commit -a -m "second commit" + """, + ], +} + + +def test_branch(repo): + vcs = get_repository_object(repo.dir) + if vcs.name == "git" and LooseVersion(vcs.tool_version) < LooseVersion("2.22.0"): + pytest.xfail("`git branch --show-current` not implemented yet") + + if vcs.name == "git": + assert vcs.branch == "master" + else: + assert vcs.branch is None + + repo.execute_next_step() + assert vcs.branch == "test" + + repo.execute_next_step() + assert vcs.branch == "test" + + vcs.update(vcs.head_ref) + assert vcs.branch is None + + vcs.update("test") + assert vcs.branch == "test" + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_commit.py b/python/mozversioncontrol/test/test_commit.py new file mode 100644 index 0000000000..b795c0ea6e --- /dev/null +++ b/python/mozversioncontrol/test/test_commit.py @@ -0,0 +1,72 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + echo "bar" >> bar + echo "baz" > foo + """, + ], + "git": [ + """ + echo "bar" >> bar + echo "baz" > foo + """, + ], +} + + +def test_commit(repo): + vcs = get_repository_object(repo.dir) + assert vcs.working_directory_clean() + + # Modify both foo and bar + repo.execute_next_step() + assert not vcs.working_directory_clean() + + # Commit just bar + vcs.commit( + message="Modify bar\n\nbut not baz", + author="Testing McTesterson <test@example.org>", + date="2017-07-14 02:40:00 UTC", + paths=["bar"], + ) + + # We only committed bar, so foo is still keeping the working dir dirty + assert not vcs.working_directory_clean() + + if repo.vcs == "git": + log_cmd = ["log", "-1", "--format=%an,%ae,%aD,%B"] + patch_cmd = ["log", "-1", "-p"] + else: + log_cmd = [ + "log", + "-l", + "1", + "-T", + "{person(author)},{email(author)},{date|rfc822date},{desc}", + ] + patch_cmd = ["log", "-l", "1", "-p"] + + # Verify commit metadata (we rstrip to normalize trivial git/hg differences) + log = vcs._run(*log_cmd).rstrip() + assert log == ( + "Testing McTesterson,test@example.org,Fri, 14 " + "Jul 2017 02:40:00 +0000,Modify bar\n\nbut not baz" + ) + + # Verify only the intended file was added to the commit + patch = vcs._run(*patch_cmd) + diffs = [line for line in patch.splitlines() if "diff --git" in line] + assert len(diffs) == 1 + assert diffs[0] == "diff --git a/bar b/bar" + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_context_manager.py b/python/mozversioncontrol/test/test_context_manager.py new file mode 100644 index 0000000000..3186a144d9 --- /dev/null +++ b/python/mozversioncontrol/test/test_context_manager.py @@ -0,0 +1,28 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit + +from mozversioncontrol import get_repository_object + + +def test_context_manager(repo): + is_git = repo.vcs == "git" + cmd = ["show", "--no-patch"] if is_git else ["tip"] + + vcs = get_repository_object(repo.dir) + output_subprocess = vcs._run(*cmd) + assert is_git or vcs._client.server is None + assert "Initial commit" in output_subprocess + + with vcs: + assert is_git or vcs._client.server is not None + output_client = vcs._run(*cmd) + + assert is_git or vcs._client.server is None + assert output_subprocess == output_client + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_create_try_commit.py b/python/mozversioncontrol/test/test_create_try_commit.py new file mode 100644 index 0000000000..45e7facb0e --- /dev/null +++ b/python/mozversioncontrol/test/test_create_try_commit.py @@ -0,0 +1,45 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this, +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + echo "{}" > try_task_config.json + hg add try_task_config.json + """, + ], + "git": [ + """ + echo "{}" > try_task_config.json + git add try_task_config.json + """, + ], +} + + +def test_create_try_commit(repo): + commit_message = "try commit message" + vcs = get_repository_object(repo.dir) + + # Create a non-empty commit. + repo.execute_next_step() + vcs.create_try_commit(commit_message) + non_empty_commit_sha = vcs.head_ref + + assert vcs.get_changed_files(rev=non_empty_commit_sha) == ["try_task_config.json"] + + # Create an empty commit. + vcs.create_try_commit(commit_message) + empty_commit_sha = vcs.head_ref + + # Commit should be created with no changed files. + assert vcs.get_changed_files(rev=empty_commit_sha) == [] + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_get_branch_nodes.py b/python/mozversioncontrol/test/test_get_branch_nodes.py new file mode 100644 index 0000000000..898f1912c5 --- /dev/null +++ b/python/mozversioncontrol/test/test_get_branch_nodes.py @@ -0,0 +1,46 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + echo bar >> bar + hg commit -m "commit 1" + echo baz > baz + hg add baz + hg commit -m "commit 2" + """ + ], + "git": [ + """ + echo bar >> bar + git add bar + git commit -m "commit 1" + echo baz > baz + git add baz + git commit -m "commit 2" + """ + ], +} + + +def test_get_branch_nodes(repo): + vcs = get_repository_object(repo.dir) + + # Create some commits + repo.execute_next_step() + + # Get list of branch nodes. + nodes = vcs.get_branch_nodes() + + assert len(nodes) == 2 + assert all(len(node) == 40 for node in nodes), "Each node should be a 40-char SHA." + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_get_commit_patches.py b/python/mozversioncontrol/test/test_get_commit_patches.py new file mode 100644 index 0000000000..56301c88ae --- /dev/null +++ b/python/mozversioncontrol/test/test_get_commit_patches.py @@ -0,0 +1,56 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + echo bar >> bar + hg commit -m "FIRST PATCH" + """, + """ + echo baz > baz + hg add baz + hg commit -m "SECOND PATCH" + """, + ], + "git": [ + """ + echo bar >> bar + git add bar + git commit -m "FIRST PATCH" + """, + """ + echo baz > baz + git add baz + git commit -m "SECOND PATCH" + """, + ], +} + + +def test_get_commit_patches(repo): + vcs = get_repository_object(repo.dir) + nodes = [] + + # Create some commits and note the SHAs. + repo.execute_next_step() + nodes.append(vcs.head_ref) + + repo.execute_next_step() + nodes.append(vcs.head_ref) + + patches = vcs.get_commit_patches(nodes) + + assert len(patches) == 2 + # Assert the patches are returned in the correct order. + assert b"FIRST PATCH" in patches[0] + assert b"SECOND PATCH" in patches[1] + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_get_mozilla_remote_args.py b/python/mozversioncontrol/test/test_get_mozilla_remote_args.py new file mode 100644 index 0000000000..0d6872b642 --- /dev/null +++ b/python/mozversioncontrol/test/test_get_mozilla_remote_args.py @@ -0,0 +1,47 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [], + "git": [ + "git remote add blah https://example.com/blah", + """ + git remote add unified hg::https://hg.mozilla.org/mozilla-unified + git remote add central hg::https://hg.mozilla.org/central + git remote add try hg::https://hg.mozilla.org/try + """, + ], +} + + +def test_get_upstream_remotes(repo): + # Test is only relevant for Git. + if not repo.vcs == "git": + return + + repo.execute_next_step() + + vcs = get_repository_object(repo.dir) + remotes = vcs.get_mozilla_remote_args() + + assert remotes == [ + "--remotes" + ], "Default `--remotes` passed without finding official remote." + + repo.execute_next_step() + + remotes = sorted(vcs.get_mozilla_remote_args()) + + assert remotes == [ + "--remotes=central", + "--remotes=unified", + ], "Multiple non-try remote arguments should be found." + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_get_upstream_remotes.py b/python/mozversioncontrol/test/test_get_upstream_remotes.py new file mode 100644 index 0000000000..d1a4727ec3 --- /dev/null +++ b/python/mozversioncontrol/test/test_get_upstream_remotes.py @@ -0,0 +1,45 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [], + "git": [ + "git remote add blah https://example.com/blah", + """ + git remote add unified hg::https://hg.mozilla.org/mozilla-unified + git remote add central hg::https://hg.mozilla.org/central + git remote add try hg::https://hg.mozilla.org/try + """, + ], +} + + +def test_get_upstream_remotes(repo): + # Test is only relevant for Git. + if not repo.vcs == "git": + return + + repo.execute_next_step() + + vcs = get_repository_object(repo.dir) + remotes = vcs.get_mozilla_upstream_remotes() + + assert list(remotes) == [], "No official remotes should be found." + + repo.execute_next_step() + + remotes = sorted(list(vcs.get_mozilla_upstream_remotes())) + + assert remotes == [ + "central", + "unified", + ], "Multiple non-try remotes should be found." + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_push_to_try.py b/python/mozversioncontrol/test/test_push_to_try.py new file mode 100644 index 0000000000..d0a0b2d993 --- /dev/null +++ b/python/mozversioncontrol/test/test_push_to_try.py @@ -0,0 +1,81 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import subprocess + +import mozunit +import pytest + +from mozversioncontrol import MissingVCSExtension, get_repository_object + + +def test_push_to_try(repo, monkeypatch): + commit_message = "commit message" + vcs = get_repository_object(repo.dir) + + captured_commands = [] + + def fake_run(*args, **kwargs): + captured_commands.append(args[0]) + + monkeypatch.setattr(subprocess, "check_output", fake_run) + monkeypatch.setattr(subprocess, "check_call", fake_run) + + vcs.push_to_try(commit_message) + tool = vcs._tool + + if repo.vcs == "hg": + expected = [ + (str(tool), "push-to-try", "-m", commit_message), + (str(tool), "revert", "-a"), + ] + else: + expected = [ + (str(tool), "cinnabar", "--version"), + ( + str(tool), + "-c", + "commit.gpgSign=false", + "commit", + "--allow-empty", + "-m", + commit_message, + ), + ( + str(tool), + "push", + "hg::ssh://hg.mozilla.org/try", + "+HEAD:refs/heads/branches/default/tip", + ), + (str(tool), "reset", "HEAD~"), + ] + + for i, value in enumerate(captured_commands): + assert value == expected[i] + + assert len(captured_commands) == len(expected) + + +def test_push_to_try_missing_extensions(repo, monkeypatch): + if repo.vcs != "git": + return + + vcs = get_repository_object(repo.dir) + + orig = vcs._run + + def cinnabar_raises(*args, **kwargs): + # Simulate not having git cinnabar + if args[0] == "cinnabar": + raise subprocess.CalledProcessError(1, args) + return orig(*args, **kwargs) + + monkeypatch.setattr(vcs, "_run", cinnabar_raises) + + with pytest.raises(MissingVCSExtension): + vcs.push_to_try("commit message") + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_remove_current_commit.py b/python/mozversioncontrol/test/test_remove_current_commit.py new file mode 100644 index 0000000000..cec20c1ef4 --- /dev/null +++ b/python/mozversioncontrol/test/test_remove_current_commit.py @@ -0,0 +1,44 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit +import pytest + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + echo "{}" > try_task_config.json + hg add try_task_config.json + hg commit -m "Try config commit" + """ + ], + "git": [ + """ + echo "{}" > try_task_config.json + git add try_task_config.json + git commit -m "Try config commit" + """ + ], +} + + +@pytest.mark.xfail(reason="Requires the Mercurial evolve extension.", strict=False) +def test_remove_current_commit(repo): + vcs = get_repository_object(repo.dir) + initial_head_ref = vcs.head_ref + + # Create a new commit. + repo.execute_next_step() + + vcs.remove_current_commit() + + assert ( + vcs.head_ref == initial_head_ref + ), "Removing current commit should revert to previous head." + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_update.py b/python/mozversioncontrol/test/test_update.py new file mode 100644 index 0000000000..91c7469ee5 --- /dev/null +++ b/python/mozversioncontrol/test/test_update.py @@ -0,0 +1,63 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from subprocess import CalledProcessError + +import mozunit +import pytest + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + echo "bar" >> bar + echo "baz" > foo + hg commit -m "second commit" + """, + """ + echo "foobar" > foo + """, + ], + "git": [ + """ + echo "bar" >> bar + echo "baz" > foo + git add * + git commit -m "second commit" + """, + """ + echo "foobar" > foo + """, + ], +} + + +def test_update(repo): + vcs = get_repository_object(repo.dir) + rev0 = vcs.head_ref + + repo.execute_next_step() + rev1 = vcs.head_ref + assert rev0 != rev1 + + if repo.vcs == "hg": + vcs.update(".~1") + else: + vcs.update("HEAD~1") + assert vcs.head_ref == rev0 + + vcs.update(rev1) + assert vcs.head_ref == rev1 + + # Update should fail with dirty working directory. + repo.execute_next_step() + with pytest.raises(CalledProcessError): + vcs.update(rev0) + + assert vcs.head_ref == rev1 + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_workdir_outgoing.py b/python/mozversioncontrol/test/test_workdir_outgoing.py new file mode 100644 index 0000000000..7bf2e6ec57 --- /dev/null +++ b/python/mozversioncontrol/test/test_workdir_outgoing.py @@ -0,0 +1,108 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import os + +import mozunit + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + echo "bar" >> bar + echo "baz" > baz + hg add baz + hg rm foo + """, + """ + hg commit -m "Remove foo; modify bar; add baz" + """, + """ + echo ooka >> baz + echo newborn > baby + hg add baby + """, + """ + hg commit -m "Modify baz; add baby" + """, + ], + "git": [ + """ + echo "bar" >> bar + echo "baz" > baz + git add baz + git rm foo + """, + """ + git commit -am "Remove foo; modify bar; add baz" + """, + """ + echo ooka >> baz + echo newborn > baby + git add baz baby + """, + """ + git commit -m "Modify baz; add baby" + """, + ], +} + + +def assert_files(actual, expected): + assert set(map(os.path.basename, actual)) == set(expected) + + +def test_workdir_outgoing(repo): + vcs = get_repository_object(repo.dir) + assert vcs.path == str(repo.dir) + + remote_path = "../remoterepo" if repo.vcs == "hg" else "upstream/master" + + # Mutate files. + repo.execute_next_step() + + assert_files(vcs.get_changed_files("A", "all"), ["baz"]) + assert_files(vcs.get_changed_files("AM", "all"), ["bar", "baz"]) + assert_files(vcs.get_changed_files("D", "all"), ["foo"]) + if repo.vcs == "git": + assert_files(vcs.get_changed_files("AM", mode="staged"), ["baz"]) + elif repo.vcs == "hg": + # Mercurial does not use a staging area (and ignores the mode parameter.) + assert_files(vcs.get_changed_files("AM", "unstaged"), ["bar", "baz"]) + assert_files(vcs.get_outgoing_files("AMD"), []) + assert_files(vcs.get_outgoing_files("AMD", remote_path), []) + + # Create a commit. + repo.execute_next_step() + + assert_files(vcs.get_changed_files("AMD", "all"), []) + assert_files(vcs.get_changed_files("AMD", "staged"), []) + assert_files(vcs.get_outgoing_files("AMD"), ["bar", "baz", "foo"]) + assert_files(vcs.get_outgoing_files("AMD", remote_path), ["bar", "baz", "foo"]) + + # Mutate again. + repo.execute_next_step() + + assert_files(vcs.get_changed_files("A", "all"), ["baby"]) + assert_files(vcs.get_changed_files("AM", "all"), ["baby", "baz"]) + assert_files(vcs.get_changed_files("D", "all"), []) + + # Create a second commit. + repo.execute_next_step() + + assert_files(vcs.get_outgoing_files("AM"), ["bar", "baz", "baby"]) + assert_files(vcs.get_outgoing_files("AM", remote_path), ["bar", "baz", "baby"]) + if repo.vcs == "git": + assert_files(vcs.get_changed_files("AM", rev="HEAD~1"), ["bar", "baz"]) + assert_files(vcs.get_changed_files("AM", rev="HEAD"), ["baby", "baz"]) + else: + assert_files(vcs.get_changed_files("AM", rev=".^"), ["bar", "baz"]) + assert_files(vcs.get_changed_files("AM", rev="."), ["baby", "baz"]) + assert_files(vcs.get_changed_files("AM", rev=".^::"), ["bar", "baz", "baby"]) + assert_files(vcs.get_changed_files("AM", rev="modifies(baz)"), ["baz", "baby"]) + + +if __name__ == "__main__": + mozunit.main() diff --git a/python/mozversioncontrol/test/test_working_directory.py b/python/mozversioncontrol/test/test_working_directory.py new file mode 100644 index 0000000000..00094a0cc4 --- /dev/null +++ b/python/mozversioncontrol/test/test_working_directory.py @@ -0,0 +1,46 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import mozunit + +from mozversioncontrol import get_repository_object + +STEPS = { + "hg": [ + """ + echo "bar" >> bar + echo "baz" > baz + hg rm foo + """, + """ + hg commit -m "Remove foo; modify bar; touch baz (but don't add it)" + """, + ], + "git": [ + """ + echo "bar" >> bar + echo "baz" > baz + git rm foo + """, + """ + git commit -am "Remove foo; modify bar; touch baz (but don't add it)" + """, + ], +} + + +def test_working_directory_clean_untracked_files(repo): + vcs = get_repository_object(repo.dir) + assert vcs.working_directory_clean() + + repo.execute_next_step() + assert not vcs.working_directory_clean() + + repo.execute_next_step() + assert vcs.working_directory_clean() + assert not vcs.working_directory_clean(untracked=True) + + +if __name__ == "__main__": + mozunit.main() |