Skip to content

Commit

Permalink
Update minimum Python version to 3.9 in the configuration (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlenaYefymenko authored Oct 11, 2024
1 parent e2540af commit 7fdaa08
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 59 deletions.
133 changes: 76 additions & 57 deletions cherry_picker/test_cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,15 @@ def test_get_updated_commit_message_with_trailers(
with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True):
cherry_picker = CherryPicker("origin", commit, [])

with mock.patch(
"cherry_picker.cherry_picker.validate_sha", return_value=True
), mock.patch.object(
cherry_picker, "get_commit_message", return_value=commit_message
), mock.patch(
"cherry_picker.cherry_picker.get_author_info_from_short_sha",
return_value="PR Author <[email protected]>",
with (
mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True),
mock.patch.object(
cherry_picker, "get_commit_message", return_value=commit_message
),
mock.patch(
"cherry_picker.cherry_picker.get_author_info_from_short_sha",
return_value="PR Author <[email protected]>",
),
):
updated_commit_message = cherry_picker.get_updated_commit_message(
cherry_pick_branch
Expand Down Expand Up @@ -914,9 +916,10 @@ class tested_state:
r"stored in Git config using the following command: "
r"`git config --local --remove-section cherry-picker`"
)
with mock.patch(
"cherry_picker.cherry_picker.validate_sha", return_value=True
), pytest.raises(InvalidRepoException, match=expected_msg_regexp):
with (
mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True),
pytest.raises(InvalidRepoException, match=expected_msg_regexp),
):
CherryPicker("origin", "xxx", [])


Expand All @@ -932,9 +935,11 @@ def test_push_to_remote_interactive(tmp_git_repo_dir):
with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True):
cherry_picker = CherryPicker("origin", "xxx", [])

with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object(
cherry_picker, "open_pr"
), mock.patch.object(cherry_picker, "get_pr_url", return_value="https://pr_url"):
with (
mock.patch.object(cherry_picker, "run_cmd"),
mock.patch.object(cherry_picker, "open_pr"),
mock.patch.object(cherry_picker, "get_pr_url", return_value="https://pr_url"),
):
cherry_picker.push_to_remote("main", "backport-branch-test")
assert get_state() == WORKFLOW_STATES.PR_OPENING

Expand All @@ -944,8 +949,9 @@ def test_push_to_remote_botflow(tmp_git_repo_dir, monkeypatch):
with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True):
cherry_picker = CherryPicker("origin", "xxx", [])

with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object(
cherry_picker, "create_gh_pr"
with (
mock.patch.object(cherry_picker, "run_cmd"),
mock.patch.object(cherry_picker, "create_gh_pr"),
):
cherry_picker.push_to_remote("main", "backport-branch-test")
assert get_state() == WORKFLOW_STATES.PR_CREATING
Expand All @@ -956,8 +962,9 @@ def test_push_to_remote_no_auto_pr(tmp_git_repo_dir, monkeypatch):
with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True):
cherry_picker = CherryPicker("origin", "xxx", [], auto_pr=False)

with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object(
cherry_picker, "create_gh_pr"
with (
mock.patch.object(cherry_picker, "run_cmd"),
mock.patch.object(cherry_picker, "create_gh_pr"),
):
cherry_picker.push_to_remote("main", "backport-branch-test")
assert get_state() == WORKFLOW_STATES.PUSHED_TO_REMOTE
Expand Down Expand Up @@ -995,10 +1002,13 @@ def test_backport_cherry_pick_fail(
pr_remote, scm_revision, cherry_pick_target_branches
)

with pytest.raises(CherryPickException), mock.patch.object(
cherry_picker, "checkout_branch"
), mock.patch.object(cherry_picker, "fetch_upstream"), mock.patch.object(
cherry_picker, "cherry_pick", side_effect=CherryPickException
with (
pytest.raises(CherryPickException),
mock.patch.object(cherry_picker, "checkout_branch"),
mock.patch.object(cherry_picker, "fetch_upstream"),
mock.patch.object(
cherry_picker, "cherry_pick", side_effect=CherryPickException
),
):
cherry_picker.backport()

Expand Down Expand Up @@ -1027,13 +1037,16 @@ def test_backport_cherry_pick_crash_ignored(
pr_remote, scm_revision, cherry_pick_target_branches
)

with mock.patch.object(cherry_picker, "checkout_branch"), mock.patch.object(
cherry_picker, "fetch_upstream"
), mock.patch.object(cherry_picker, "cherry_pick"), mock.patch.object(
cherry_picker,
"amend_commit_message",
side_effect=subprocess.CalledProcessError(
1, ("git", "commit", "-am", "new commit message")
with (
mock.patch.object(cherry_picker, "checkout_branch"),
mock.patch.object(cherry_picker, "fetch_upstream"),
mock.patch.object(cherry_picker, "cherry_pick"),
mock.patch.object(
cherry_picker,
"amend_commit_message",
side_effect=subprocess.CalledProcessError(
1, ("git", "commit", "-am", "new commit message")
),
),
):
cherry_picker.backport()
Expand Down Expand Up @@ -1067,9 +1080,10 @@ def test_backport_cherry_pick_branch_already_exists(
)
git_branch(backport_branch_name)

with mock.patch.object(cherry_picker, "fetch_upstream"), pytest.raises(
BranchCheckoutException
) as exc_info:
with (
mock.patch.object(cherry_picker, "fetch_upstream"),
pytest.raises(BranchCheckoutException) as exc_info,
):
cherry_picker.backport()

assert exc_info.value.branch_name == backport_branch_name
Expand Down Expand Up @@ -1098,10 +1112,12 @@ def test_backport_success(
pr_remote, scm_revision, cherry_pick_target_branches
)

with mock.patch.object(cherry_picker, "checkout_branch"), mock.patch.object(
cherry_picker, "fetch_upstream"
), mock.patch.object(
cherry_picker, "amend_commit_message", return_value="commit message"
with (
mock.patch.object(cherry_picker, "checkout_branch"),
mock.patch.object(cherry_picker, "fetch_upstream"),
mock.patch.object(
cherry_picker, "amend_commit_message", return_value="commit message"
),
):
cherry_picker.backport()

Expand Down Expand Up @@ -1141,8 +1157,11 @@ def test_backport_pause_and_continue(
pr_remote, scm_revision, cherry_pick_target_branches, push=False
)

with mock.patch.object(cherry_picker, "fetch_upstream"), mock.patch.object(
cherry_picker, "amend_commit_message", return_value="commit message"
with (
mock.patch.object(cherry_picker, "fetch_upstream"),
mock.patch.object(
cherry_picker, "amend_commit_message", return_value="commit message"
),
):
cherry_picker.backport()

Expand All @@ -1164,26 +1183,26 @@ def test_backport_pause_and_continue(
Co-authored-by: Author Name <[email protected]>"""

with mock.patch(
"cherry_picker.cherry_picker.wipe_cfg_vals_from_git_cfg"
), mock.patch(
"cherry_picker.cherry_picker.get_full_sha_from_short",
return_value="xxxxxxyyyyyy",
), mock.patch(
"cherry_picker.cherry_picker.get_base_branch", return_value="3.8"
), mock.patch(
"cherry_picker.cherry_picker.get_current_branch",
return_value="backport-xxx-3.8",
), mock.patch.object(
cherry_picker, "amend_commit_message", return_value=commit_message
) as amend_commit_message, mock.patch.object(
cherry_picker, "get_updated_commit_message", return_value=commit_message
) as get_updated_commit_message, mock.patch.object(
cherry_picker, "checkout_branch"
), mock.patch.object(
cherry_picker, "fetch_upstream"
), mock.patch.object(
cherry_picker, "cleanup_branch"
with (
mock.patch("cherry_picker.cherry_picker.wipe_cfg_vals_from_git_cfg"),
mock.patch(
"cherry_picker.cherry_picker.get_full_sha_from_short",
return_value="xxxxxxyyyyyy",
),
mock.patch("cherry_picker.cherry_picker.get_base_branch", return_value="3.8"),
mock.patch(
"cherry_picker.cherry_picker.get_current_branch",
return_value="backport-xxx-3.8",
),
mock.patch.object(
cherry_picker, "amend_commit_message", return_value=commit_message
) as amend_commit_message,
mock.patch.object(
cherry_picker, "get_updated_commit_message", return_value=commit_message
) as get_updated_commit_message,
mock.patch.object(cherry_picker, "checkout_branch"),
mock.patch.object(cherry_picker, "fetch_upstream"),
mock.patch.object(cherry_picker, "cleanup_branch"),
):
cherry_picker.continue_cherry_pick()

Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ name = "cherry-picker"
readme = "README.md"
maintainers = [ { name = "Python Core Developers", email = "[email protected]" } ]
authors = [ { name = "Mariatta Wijaya", email = "[email protected]" } ]
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down

0 comments on commit 7fdaa08

Please sign in to comment.