Skip to content

Commit c161a7b

Browse files
committed
✅ Add tests for cleanup_branch
1 parent 1b8e33d commit c161a7b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

cherry_picker/cherry_picker/test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ def git_add():
4949
)
5050

5151

52+
@pytest.fixture
53+
def git_checkout():
54+
git_checkout_cmd = 'git', 'checkout'
55+
return lambda *extra_args: (
56+
subprocess.run(git_checkout_cmd + extra_args, check=True)
57+
)
58+
59+
60+
@pytest.fixture
61+
def git_branch():
62+
git_branch_cmd = 'git', 'branch'
63+
return lambda *extra_args: (
64+
subprocess.run(git_branch_cmd + extra_args, check=True)
65+
)
66+
67+
5268
@pytest.fixture
5369
def git_commit():
5470
git_commit_cmd = 'git', 'commit', '-m'
@@ -483,3 +499,34 @@ def _fetch(cmd):
483499
with mock.patch.object(cherry_picker, 'run_cmd', _fetch):
484500
getattr(cherry_picker, method_name)()
485501
assert get_state() == end_state
502+
503+
504+
def test_cleanup_branch(
505+
tmp_git_repo_dir, git_checkout,
506+
):
507+
assert get_state() == 'UNSET'
508+
509+
with mock.patch(
510+
'cherry_picker.cherry_picker.validate_sha',
511+
return_value=True,
512+
):
513+
cherry_picker = CherryPicker('origin', 'xxx', [])
514+
assert get_state() == 'UNSET'
515+
516+
git_checkout('-b', 'some_branch')
517+
cherry_picker.cleanup_branch('some_branch')
518+
assert get_state() == 'REMOVED_BACKPORT_BRANCH'
519+
520+
521+
def test_cleanup_branch_fail(tmp_git_repo_dir):
522+
assert get_state() == 'UNSET'
523+
524+
with mock.patch(
525+
'cherry_picker.cherry_picker.validate_sha',
526+
return_value=True,
527+
):
528+
cherry_picker = CherryPicker('origin', 'xxx', [])
529+
assert get_state() == 'UNSET'
530+
531+
cherry_picker.cleanup_branch('some_branch')
532+
assert get_state() == 'REMOVING_BACKPORT_BRANCH_FAILED'

0 commit comments

Comments
 (0)