Parameterize e2e tests using pytest
This commit is contained in:
@@ -3,15 +3,18 @@
|
|||||||
from helpers import *
|
from helpers import *
|
||||||
|
|
||||||
import git
|
import git
|
||||||
|
import pytest
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
def test_worktree_add_simple():
|
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
|
||||||
for remote_branch_already_exists in (True, False):
|
@pytest.mark.parametrize("has_config", [True, False])
|
||||||
for has_config in (True, False):
|
@pytest.mark.parametrize("has_default", [True, False])
|
||||||
for has_default in (True, False):
|
@pytest.mark.parametrize("has_prefix", [True, False])
|
||||||
for has_prefix in (True, False):
|
def test_worktree_add_simple(
|
||||||
|
remote_branch_already_exists, has_config, has_default, has_prefix
|
||||||
|
):
|
||||||
with TempGitRepositoryWorktree() as base_dir:
|
with TempGitRepositoryWorktree() as base_dir:
|
||||||
if has_config:
|
if has_config:
|
||||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
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)
|
files = os.listdir(base_dir)
|
||||||
if has_config is True:
|
if has_config is True:
|
||||||
assert len(files) == 3
|
assert len(files) == 3
|
||||||
assert set(files) == {
|
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
|
||||||
".git-main-working-tree",
|
|
||||||
"grm.toml",
|
|
||||||
"test",
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
assert len(files) == 2
|
assert len(files) == 2
|
||||||
assert set(files) == {".git-main-working-tree", "test"}
|
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_config and has_default:
|
||||||
if has_prefix and not remote_branch_already_exists:
|
if has_prefix and not remote_branch_already_exists:
|
||||||
assert (
|
assert (
|
||||||
str(repo.active_branch.tracking_branch())
|
str(repo.active_branch.tracking_branch()) == "origin/myprefix/test"
|
||||||
== "origin/myprefix/test"
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
assert (
|
assert str(repo.active_branch.tracking_branch()) == "origin/test"
|
||||||
str(repo.active_branch.tracking_branch())
|
|
||||||
== "origin/test"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
assert repo.active_branch.tracking_branch() is None
|
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)
|
assert "dir" not in os.listdir(base_dir)
|
||||||
|
|
||||||
|
|
||||||
def test_worktree_add_with_tracking():
|
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
|
||||||
for remote_branch_already_exists in (True, False):
|
@pytest.mark.parametrize("has_config", [True, False])
|
||||||
for has_config in (True, False):
|
@pytest.mark.parametrize("has_default", [True, False])
|
||||||
for has_default in (True, False):
|
@pytest.mark.parametrize("has_prefix", [True, False])
|
||||||
for has_prefix in (True, False):
|
def test_worktree_add_with_tracking(
|
||||||
|
remote_branch_already_exists, has_config, has_default, has_prefix
|
||||||
|
):
|
||||||
with TempGitRepositoryWorktree() as base_dir:
|
with TempGitRepositoryWorktree() as base_dir:
|
||||||
if has_config:
|
if has_config:
|
||||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
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
|
git --git-dir ./.git-main-working-tree worktree remove tmp
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
cmd = grm(
|
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
|
||||||
["wt", "add", "test", "--track", "origin/test"],
|
|
||||||
cwd=base_dir,
|
|
||||||
)
|
|
||||||
print(cmd.stderr)
|
print(cmd.stderr)
|
||||||
assert cmd.returncode == 0
|
assert cmd.returncode == 0
|
||||||
|
|
||||||
files = os.listdir(base_dir)
|
files = os.listdir(base_dir)
|
||||||
if has_config is True:
|
if has_config is True:
|
||||||
assert len(files) == 3
|
assert len(files) == 3
|
||||||
assert set(files) == {
|
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
|
||||||
".git-main-working-tree",
|
|
||||||
"grm.toml",
|
|
||||||
"test",
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
assert len(files) == 2
|
assert len(files) == 2
|
||||||
assert set(files) == {".git-main-working-tree", "test"}
|
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.bare
|
||||||
assert not repo.is_dirty()
|
assert not repo.is_dirty()
|
||||||
assert str(repo.active_branch) == "test"
|
assert str(repo.active_branch) == "test"
|
||||||
assert (
|
assert str(repo.active_branch.tracking_branch()) == "origin/test"
|
||||||
str(repo.active_branch.tracking_branch()) == "origin/test"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_worktree_add_with_explicit_no_tracking():
|
@pytest.mark.parametrize("has_config", [True, False])
|
||||||
for has_config in (True, False):
|
@pytest.mark.parametrize("has_default", [True, False])
|
||||||
for has_default in (True, False):
|
@pytest.mark.parametrize("has_prefix", [True, False])
|
||||||
for has_prefix in (True, False):
|
@pytest.mark.parametrize("track", [True, False])
|
||||||
for track in (True, False):
|
def test_worktree_add_with_explicit_no_tracking(
|
||||||
|
has_config, has_default, has_prefix, track
|
||||||
|
):
|
||||||
with TempGitRepositoryWorktree() as base_dir:
|
with TempGitRepositoryWorktree() as base_dir:
|
||||||
if has_config:
|
if has_config:
|
||||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
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:
|
if track is True:
|
||||||
cmd = grm(
|
cmd = grm(
|
||||||
[
|
["wt", "add", "test", "--track", "origin/test", "--no-track"],
|
||||||
"wt",
|
|
||||||
"add",
|
|
||||||
"test",
|
|
||||||
"--track",
|
|
||||||
"origin/test",
|
|
||||||
"--no-track",
|
|
||||||
],
|
|
||||||
cwd=base_dir,
|
cwd=base_dir,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -217,11 +200,7 @@ def test_worktree_add_with_explicit_no_tracking():
|
|||||||
files = os.listdir(base_dir)
|
files = os.listdir(base_dir)
|
||||||
if has_config is True:
|
if has_config is True:
|
||||||
assert len(files) == 3
|
assert len(files) == 3
|
||||||
assert set(files) == {
|
assert set(files) == {".git-main-working-tree", "grm.toml", "test"}
|
||||||
".git-main-working-tree",
|
|
||||||
"grm.toml",
|
|
||||||
"test",
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
assert len(files) == 2
|
assert len(files) == 2
|
||||||
assert set(files) == {".git-main-working-tree", "test"}
|
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
|
assert repo.active_branch.tracking_branch() is None
|
||||||
|
|
||||||
|
|
||||||
def test_worktree_add_with_config():
|
@pytest.mark.parametrize("remote_branch_already_exists", [True, False])
|
||||||
for remote_branch_already_exists in (True, False):
|
@pytest.mark.parametrize("has_default", [True, False])
|
||||||
for has_default in (True, False):
|
@pytest.mark.parametrize("has_prefix", [True, False])
|
||||||
for has_prefix in (True, False):
|
def test_worktree_add_with_config(
|
||||||
|
remote_branch_already_exists, has_default, has_prefix
|
||||||
|
):
|
||||||
with TempGitRepositoryWorktree() as base_dir:
|
with TempGitRepositoryWorktree() as base_dir:
|
||||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
@@ -284,14 +265,10 @@ def test_worktree_add_with_config():
|
|||||||
if has_default:
|
if has_default:
|
||||||
if has_prefix and not remote_branch_already_exists:
|
if has_prefix and not remote_branch_already_exists:
|
||||||
assert (
|
assert (
|
||||||
str(repo.active_branch.tracking_branch())
|
str(repo.active_branch.tracking_branch()) == "origin/myprefix/test"
|
||||||
== "origin/myprefix/test"
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
assert (
|
assert str(repo.active_branch.tracking_branch()) == "origin/test"
|
||||||
str(repo.active_branch.tracking_branch())
|
|
||||||
== "origin/test"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
assert repo.active_branch.tracking_branch() is None
|
assert repo.active_branch.tracking_branch() is None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user