diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /python/mozversioncontrol/test/conftest.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python/mozversioncontrol/test/conftest.py')
-rw-r--r-- | python/mozversioncontrol/test/conftest.py | 84 |
1 files changed, 84 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 |