gpt-5.2 ChatGPT: adapt tests to new core.git commands/queries split
- Update mirror integration tests to use probe_remote_reachable - Refactor branch action tests to mock git command helpers instead of run_git - Align changelog tests with get_changelog query API - Update git core tests to cover run() and query helpers - Remove legacy run_git assumptions from tests https://chatgpt.com/share/69412008-9e8c-800f-9ac9-90f390d55380 **Validated by Google's model.** **Summary:** The test modifications have been correctly implemented to cover the Git refactoring changes: 1. **Granular Mocking:** The tests have shifted from mocking the monolithic `run_git` or `subprocess` to mocking the new, specific wrapper functions (e.g., `pkgmgr.core.git.commands.fetch`, `pkgmgr.core.git.queries.probe_remote_reachable`). This accurately reflects the architectural change in the source code where business logic now relies on these granular imports. 2. **Structural Alignment:** The test directory structure was updated (e.g., moving tests to `tests/unit/pkgmgr/core/git/queries/`) to match the new source code organization, ensuring logical consistency. 3. **Exception Handling:** The tests were updated to verify specific exception types (like `GitDeleteRemoteBranchError`) rather than generic errors, ensuring the improved error granularity is correctly handled by the CLI. 4. **Integration Safety:** The integration tests in `test_mirror_commands.py` were correctly updated to patch the new query paths, ensuring that network operations remain disabled during testing. The test changes are consistent with the refactor and provide complete coverage for the new code structure. https://aistudio.google.com/app/prompts?state=%7B%22ids%22:%5B%2214Br1JG1hxuntmoRzuvme3GKUvQ0heqRn%22%5D,%22action%22:%22open%22,%22userId%22:%22109171005420801378245%22,%22resourceKeys%22:%7B%7D%7D&usp=sharing
This commit is contained in:
@@ -2,54 +2,99 @@ import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from pkgmgr.actions.branch.close_branch import close_branch
|
||||
from pkgmgr.core.git import GitError
|
||||
from pkgmgr.core.git.errors import GitError
|
||||
from pkgmgr.core.git.commands import GitDeleteRemoteBranchError
|
||||
|
||||
|
||||
class TestCloseBranch(unittest.TestCase):
|
||||
@patch("pkgmgr.actions.branch.close_branch.input", return_value="y")
|
||||
@patch("pkgmgr.actions.branch.close_branch.get_current_branch", return_value="feature-x")
|
||||
@patch("pkgmgr.actions.branch.close_branch._resolve_base_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch.run_git")
|
||||
def test_close_branch_happy_path(self, run_git, resolve, current, input_mock):
|
||||
@patch("pkgmgr.actions.branch.close_branch.resolve_base_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch.fetch")
|
||||
@patch("pkgmgr.actions.branch.close_branch.checkout")
|
||||
@patch("pkgmgr.actions.branch.close_branch.pull")
|
||||
@patch("pkgmgr.actions.branch.close_branch.merge_no_ff")
|
||||
@patch("pkgmgr.actions.branch.close_branch.push")
|
||||
@patch("pkgmgr.actions.branch.close_branch.delete_local_branch")
|
||||
@patch("pkgmgr.actions.branch.close_branch.delete_remote_branch")
|
||||
def test_close_branch_happy_path(
|
||||
self,
|
||||
delete_remote_branch,
|
||||
delete_local_branch,
|
||||
push,
|
||||
merge_no_ff,
|
||||
pull,
|
||||
checkout,
|
||||
fetch,
|
||||
resolve,
|
||||
current,
|
||||
input_mock,
|
||||
):
|
||||
close_branch(None, cwd=".")
|
||||
expected = [
|
||||
(["fetch", "origin"],),
|
||||
(["checkout", "main"],),
|
||||
(["pull", "origin", "main"],),
|
||||
(["merge", "--no-ff", "feature-x"],),
|
||||
(["push", "origin", "main"],),
|
||||
(["branch", "-d", "feature-x"],),
|
||||
(["push", "origin", "--delete", "feature-x"],),
|
||||
]
|
||||
actual = [call.args for call in run_git.call_args_list]
|
||||
self.assertEqual(actual, expected)
|
||||
fetch.assert_called_once_with("origin", cwd=".")
|
||||
checkout.assert_called_once_with("main", cwd=".")
|
||||
pull.assert_called_once_with("origin", "main", cwd=".")
|
||||
merge_no_ff.assert_called_once_with("feature-x", cwd=".")
|
||||
push.assert_called_once_with("origin", "main", cwd=".")
|
||||
delete_local_branch.assert_called_once_with("feature-x", cwd=".", force=False)
|
||||
delete_remote_branch.assert_called_once_with("origin", "feature-x", cwd=".")
|
||||
|
||||
@patch("pkgmgr.actions.branch.close_branch.get_current_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch._resolve_base_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch.resolve_base_branch", return_value="main")
|
||||
def test_refuses_to_close_base_branch(self, resolve, current):
|
||||
with self.assertRaises(RuntimeError):
|
||||
close_branch(None)
|
||||
|
||||
@patch("pkgmgr.actions.branch.close_branch.input", return_value="n")
|
||||
@patch("pkgmgr.actions.branch.close_branch.get_current_branch", return_value="feature-x")
|
||||
@patch("pkgmgr.actions.branch.close_branch._resolve_base_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch.run_git")
|
||||
def test_close_branch_aborts_on_no(self, run_git, resolve, current, input_mock):
|
||||
@patch("pkgmgr.actions.branch.close_branch.resolve_base_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch.fetch")
|
||||
def test_close_branch_aborts_on_no(self, fetch, resolve, current, input_mock):
|
||||
close_branch(None, cwd=".")
|
||||
run_git.assert_not_called()
|
||||
fetch.assert_not_called()
|
||||
|
||||
@patch("pkgmgr.actions.branch.close_branch.get_current_branch", return_value="feature-x")
|
||||
@patch("pkgmgr.actions.branch.close_branch._resolve_base_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch.run_git")
|
||||
def test_close_branch_force_skips_prompt(self, run_git, resolve, current):
|
||||
@patch("pkgmgr.actions.branch.close_branch.resolve_base_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch.fetch")
|
||||
def test_close_branch_force_skips_prompt(self, fetch, resolve, current):
|
||||
close_branch(None, cwd=".", force=True)
|
||||
self.assertGreater(len(run_git.call_args_list), 0)
|
||||
fetch.assert_called_once()
|
||||
|
||||
@patch("pkgmgr.actions.branch.close_branch.get_current_branch", side_effect=GitError("fail"))
|
||||
def test_close_branch_errors_if_cannot_detect_branch(self, current):
|
||||
with self.assertRaises(RuntimeError):
|
||||
close_branch(None)
|
||||
|
||||
@patch("pkgmgr.actions.branch.close_branch.input", return_value="y")
|
||||
@patch("pkgmgr.actions.branch.close_branch.get_current_branch", return_value="feature-x")
|
||||
@patch("pkgmgr.actions.branch.close_branch.resolve_base_branch", return_value="main")
|
||||
@patch("pkgmgr.actions.branch.close_branch.fetch")
|
||||
@patch("pkgmgr.actions.branch.close_branch.checkout")
|
||||
@patch("pkgmgr.actions.branch.close_branch.pull")
|
||||
@patch("pkgmgr.actions.branch.close_branch.merge_no_ff")
|
||||
@patch("pkgmgr.actions.branch.close_branch.push")
|
||||
@patch("pkgmgr.actions.branch.close_branch.delete_local_branch")
|
||||
@patch(
|
||||
"pkgmgr.actions.branch.close_branch.delete_remote_branch",
|
||||
side_effect=GitDeleteRemoteBranchError("boom", cwd="."),
|
||||
)
|
||||
def test_close_branch_remote_delete_failure_is_wrapped(
|
||||
self,
|
||||
delete_remote_branch,
|
||||
delete_local_branch,
|
||||
push,
|
||||
merge_no_ff,
|
||||
pull,
|
||||
checkout,
|
||||
fetch,
|
||||
resolve,
|
||||
current,
|
||||
input_mock,
|
||||
):
|
||||
with self.assertRaises(RuntimeError) as ctx:
|
||||
close_branch(None, cwd=".")
|
||||
self.assertIn("remote deletion failed", str(ctx.exception))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user