Skip to content

Commit 2076352

Browse files
committed
cmd/git(test[Git.init]): Add test for shared parameter boolean behavior
why: Commit 03b124c fixed shared=False passing --shared, but had no test. what: - Add InitSharedFixture NamedTuple with 4 test cases - Test shared=True, shared=False, shared=None, shared="group" - Verify "shared git repository" only in output when expected
1 parent 5c00880 commit 2076352

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/cmd/test_git.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,66 @@ def test_git_init_shared(tmp_path: pathlib.Path) -> None:
101101
assert "Initialized empty shared Git repository" in result
102102

103103

104+
class InitSharedFixture(t.NamedTuple):
105+
"""Test fixture for Git.init() shared parameter behavior."""
106+
107+
test_id: str
108+
shared: bool | str | None
109+
expect_shared_repo: bool # True = "shared Git repository" in output
110+
111+
112+
INIT_SHARED_FIXTURES: list[InitSharedFixture] = [
113+
InitSharedFixture(
114+
test_id="shared-true-passes-flag",
115+
shared=True,
116+
expect_shared_repo=True,
117+
),
118+
InitSharedFixture(
119+
test_id="shared-false-omits-flag",
120+
shared=False,
121+
expect_shared_repo=False, # Key: shared=False should NOT pass --shared
122+
),
123+
InitSharedFixture(
124+
test_id="shared-none-omits-flag",
125+
shared=None,
126+
expect_shared_repo=False,
127+
),
128+
InitSharedFixture(
129+
test_id="shared-group-passes-value",
130+
shared="group",
131+
expect_shared_repo=True,
132+
),
133+
]
134+
135+
136+
@pytest.mark.parametrize(
137+
list(InitSharedFixture._fields),
138+
INIT_SHARED_FIXTURES,
139+
ids=[test.test_id for test in INIT_SHARED_FIXTURES],
140+
)
141+
def test_git_init_shared_boolean_behavior(
142+
tmp_path: pathlib.Path,
143+
test_id: str,
144+
shared: bool | str | None,
145+
expect_shared_repo: bool,
146+
) -> None:
147+
"""Test Git.init() shared parameter behavior.
148+
149+
Verifies commit 03b124c: shared=False should NOT pass --shared flag.
150+
"""
151+
repo_dir = tmp_path / f"init_{test_id}"
152+
repo_dir.mkdir()
153+
repo = git.Git(path=repo_dir)
154+
155+
result = repo.init(shared=shared)
156+
157+
# Check for "shared Git repository" in output (not just "shared" - matches path)
158+
if expect_shared_repo:
159+
assert "shared git repository" in result.lower()
160+
else:
161+
assert "shared git repository" not in result.lower()
162+
163+
104164
def test_git_init_quiet(tmp_path: pathlib.Path) -> None:
105165
"""Test git init with quiet flag."""
106166
repo = git.Git(path=tmp_path)

0 commit comments

Comments
 (0)