Parameterize e2e tests using pytest

This commit is contained in:
2021-12-23 18:33:14 +01:00
parent 54fc48b37d
commit 3ac88260b5

View File

@@ -3,15 +3,18 @@
from helpers import *
import git
import pytest
import os.path
def test_worktree_add_simple():
for remote_branch_already_exists in (True, False):
for has_config in (True, False):
for has_default in (True, False):
for has_prefix in (True, False):
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
@pytest.mark.parametrize("has_config", [True, False])
@pytest.mark.parametrize("has_default", [True, False])
@pytest.mark.parametrize("has_prefix", [True, False])
def test_worktree_add_simple(
remote_branch_already_exists, has_config, has_default, has_prefix
):
with TempGitRepositoryWorktree() as base_dir:
if has_config:
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
@@ -52,11 +55,7 @@ def test_worktree_add_simple():
files = os.listdir(base_dir)
if has_config is True:
assert len(files) == 3
assert set(files) == {
".git-main-working-tree",
"grm.toml",
"test",
}
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
else:
assert len(files) == 2
assert set(files) == {".git-main-working-tree", "test"}
@@ -67,14 +66,10 @@ def test_worktree_add_simple():
if has_config and has_default:
if has_prefix and not remote_branch_already_exists:
assert (
str(repo.active_branch.tracking_branch())
== "origin/myprefix/test"
str(repo.active_branch.tracking_branch()) == "origin/myprefix/test"
)
else:
assert (
str(repo.active_branch.tracking_branch())
== "origin/test"
)
assert str(repo.active_branch.tracking_branch()) == "origin/test"
else:
assert repo.active_branch.tracking_branch() is None
@@ -109,11 +104,13 @@ def test_worktree_add_into_invalid_subdirectory():
assert "dir" not in os.listdir(base_dir)
def test_worktree_add_with_tracking():
for remote_branch_already_exists in (True, False):
for has_config in (True, False):
for has_default in (True, False):
for has_prefix in (True, False):
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
@pytest.mark.parametrize("has_config", [True, False])
@pytest.mark.parametrize("has_default", [True, False])
@pytest.mark.parametrize("has_prefix", [True, False])
def test_worktree_add_with_tracking(
remote_branch_already_exists, has_config, has_default, has_prefix
):
with TempGitRepositoryWorktree() as base_dir:
if has_config:
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
@@ -148,21 +145,14 @@ def test_worktree_add_with_tracking():
git --git-dir ./.git-main-working-tree worktree remove tmp
"""
)
cmd = grm(
["wt", "add", "test", "--track", "origin/test"],
cwd=base_dir,
)
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
print(cmd.stderr)
assert cmd.returncode == 0
files = os.listdir(base_dir)
if has_config is True:
assert len(files) == 3
assert set(files) == {
".git-main-working-tree",
"grm.toml",
"test",
}
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
else:
assert len(files) == 2
assert set(files) == {".git-main-working-tree", "test"}
@@ -171,16 +161,16 @@ def test_worktree_add_with_tracking():
assert not repo.bare
assert not repo.is_dirty()
assert str(repo.active_branch) == "test"
assert (
str(repo.active_branch.tracking_branch()) == "origin/test"
)
assert str(repo.active_branch.tracking_branch()) == "origin/test"
def test_worktree_add_with_explicit_no_tracking():
for has_config in (True, False):
for has_default in (True, False):
for has_prefix in (True, False):
for track in (True, False):
@pytest.mark.parametrize("has_config", [True, False])
@pytest.mark.parametrize("has_default", [True, False])
@pytest.mark.parametrize("has_prefix", [True, False])
@pytest.mark.parametrize("track", [True, False])
def test_worktree_add_with_explicit_no_tracking(
has_config, has_default, has_prefix, track
):
with TempGitRepositoryWorktree() as base_dir:
if has_config:
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
@@ -199,14 +189,7 @@ def test_worktree_add_with_explicit_no_tracking():
)
if track is True:
cmd = grm(
[
"wt",
"add",
"test",
"--track",
"origin/test",
"--no-track",
],
["wt", "add", "test", "--track", "origin/test", "--no-track"],
cwd=base_dir,
)
else:
@@ -217,11 +200,7 @@ def test_worktree_add_with_explicit_no_tracking():
files = os.listdir(base_dir)
if has_config is True:
assert len(files) == 3
assert set(files) == {
".git-main-working-tree",
"grm.toml",
"test",
}
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
else:
assert len(files) == 2
assert set(files) == {".git-main-working-tree", "test"}
@@ -233,10 +212,12 @@ def test_worktree_add_with_explicit_no_tracking():
assert repo.active_branch.tracking_branch() is None
def test_worktree_add_with_config():
for remote_branch_already_exists in (True, False):
for has_default in (True, False):
for has_prefix in (True, False):
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
@pytest.mark.parametrize("has_default", [True, False])
@pytest.mark.parametrize("has_prefix", [True, False])
def test_worktree_add_with_config(
remote_branch_already_exists, has_default, has_prefix
):
with TempGitRepositoryWorktree() as base_dir:
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
f.write(
@@ -284,14 +265,10 @@ def test_worktree_add_with_config():
if has_default:
if has_prefix and not remote_branch_already_exists:
assert (
str(repo.active_branch.tracking_branch())
== "origin/myprefix/test"
str(repo.active_branch.tracking_branch()) == "origin/myprefix/test"
)
else:
assert (
str(repo.active_branch.tracking_branch())
== "origin/test"
)
assert str(repo.active_branch.tracking_branch()) == "origin/test"
else:
assert repo.active_branch.tracking_branch() is None