Skip to content

Commit 229708d

Browse files
committed
tests/cmd(test[GitRemote]): add tests for remote operations
why: Verify GitRemoteCmd set_branches, set_head, update methods what: - Add RemoteSetBranchesFixture with NamedTuple + test_id pattern - Add RemoteSetHeadFixture for set-head auto/explicit tests - Add RemoteUpdateFixture for update/prune tests - All tests use pytest fixtures (no mocks)
1 parent b752107 commit 229708d

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

tests/cmd/test_git.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,144 @@ def test_branch_unset_upstream(git_repo: GitSync) -> None:
482482

483483
# unset_upstream typically returns empty string on success
484484
assert result == "" or "upstream" not in result.lower()
485+
486+
487+
# =============================================================================
488+
# GitRemoteCmd Tests
489+
# =============================================================================
490+
491+
492+
class RemoteSetBranchesFixture(t.NamedTuple):
493+
"""Test fixture for GitRemoteCmd.set_branches() operations."""
494+
495+
test_id: str
496+
branches: tuple[str, ...]
497+
add: bool
498+
499+
500+
REMOTE_SET_BRANCHES_FIXTURES: list[RemoteSetBranchesFixture] = [
501+
RemoteSetBranchesFixture(
502+
test_id="set-single-branch",
503+
branches=("master",),
504+
add=False,
505+
),
506+
RemoteSetBranchesFixture(
507+
test_id="set-multiple-branches",
508+
branches=("master", "develop"),
509+
add=False,
510+
),
511+
RemoteSetBranchesFixture(
512+
test_id="add-branch",
513+
branches=("feature",),
514+
add=True,
515+
),
516+
]
517+
518+
519+
@pytest.mark.parametrize(
520+
list(RemoteSetBranchesFixture._fields),
521+
REMOTE_SET_BRANCHES_FIXTURES,
522+
ids=[test.test_id for test in REMOTE_SET_BRANCHES_FIXTURES],
523+
)
524+
def test_remote_set_branches(
525+
git_repo: GitSync,
526+
test_id: str,
527+
branches: tuple[str, ...],
528+
add: bool,
529+
) -> None:
530+
"""Test GitRemoteCmd.set_branches() with various scenarios."""
531+
remote = git_repo.cmd.remotes.get(remote_name="origin")
532+
assert remote is not None
533+
534+
# set_branches should succeed without error
535+
result = remote.set_branches(*branches, add=add)
536+
assert result == ""
537+
538+
539+
class RemoteSetHeadFixture(t.NamedTuple):
540+
"""Test fixture for GitRemoteCmd.set_head() operations."""
541+
542+
test_id: str
543+
branch: str | None
544+
auto: bool
545+
delete: bool
546+
547+
548+
REMOTE_SET_HEAD_FIXTURES: list[RemoteSetHeadFixture] = [
549+
RemoteSetHeadFixture(
550+
test_id="set-head-auto",
551+
branch=None,
552+
auto=True,
553+
delete=False,
554+
),
555+
RemoteSetHeadFixture(
556+
test_id="set-head-explicit",
557+
branch="master",
558+
auto=False,
559+
delete=False,
560+
),
561+
]
562+
563+
564+
@pytest.mark.parametrize(
565+
list(RemoteSetHeadFixture._fields),
566+
REMOTE_SET_HEAD_FIXTURES,
567+
ids=[test.test_id for test in REMOTE_SET_HEAD_FIXTURES],
568+
)
569+
def test_remote_set_head(
570+
git_repo: GitSync,
571+
test_id: str,
572+
branch: str | None,
573+
auto: bool,
574+
delete: bool,
575+
) -> None:
576+
"""Test GitRemoteCmd.set_head() with various scenarios."""
577+
remote = git_repo.cmd.remotes.get(remote_name="origin")
578+
assert remote is not None
579+
580+
result = remote.set_head(branch, auto=auto, delete=delete)
581+
582+
# set_head returns either confirmation message or empty string
583+
if auto:
584+
assert "set to" in result.lower() or result == ""
585+
else:
586+
assert result == "" or "head" in result.lower()
587+
588+
589+
class RemoteUpdateFixture(t.NamedTuple):
590+
"""Test fixture for GitRemoteCmd.update() operations."""
591+
592+
test_id: str
593+
prune: bool
594+
595+
596+
REMOTE_UPDATE_FIXTURES: list[RemoteUpdateFixture] = [
597+
RemoteUpdateFixture(
598+
test_id="update-simple",
599+
prune=False,
600+
),
601+
RemoteUpdateFixture(
602+
test_id="update-with-prune",
603+
prune=True,
604+
),
605+
]
606+
607+
608+
@pytest.mark.parametrize(
609+
list(RemoteUpdateFixture._fields),
610+
REMOTE_UPDATE_FIXTURES,
611+
ids=[test.test_id for test in REMOTE_UPDATE_FIXTURES],
612+
)
613+
def test_remote_update(
614+
git_repo: GitSync,
615+
test_id: str,
616+
prune: bool,
617+
) -> None:
618+
"""Test GitRemoteCmd.update() with various scenarios."""
619+
remote = git_repo.cmd.remotes.get(remote_name="origin")
620+
assert remote is not None
621+
622+
result = remote.update(prune=prune)
623+
624+
# update typically returns "Fetching <remote>" message
625+
assert "fetching" in result.lower() or result == ""

0 commit comments

Comments
 (0)