From 41211d2a8e96c2e6883c73f698c8fb820390c03c Mon Sep 17 00:00:00 2001 From: Mariatta Date: Tue, 10 Oct 2023 13:56:40 +0200 Subject: [PATCH 1/3] When raising error, show what the current state vs expected state. --- cherry_picker/cherry_picker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 0427f94..f90c22f 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -541,7 +541,7 @@ def abort_cherry_pick(self): run `git cherry-pick --abort` and then clean up the branch """ if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED: - raise ValueError("One can only abort a paused process.") + raise ValueError(f"One can only abort a paused process. Current state: {self.initial_state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}") try: validate_sha("CHERRY_PICK_HEAD") From e16707054a832cc607309ff70ccd3931afbad48d Mon Sep 17 00:00:00 2001 From: Mariatta Date: Tue, 10 Oct 2023 14:13:55 +0200 Subject: [PATCH 2/3] Fix the test --- cherry_picker/cherry_picker.py | 4 +++- cherry_picker/test_cherry_picker.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index f90c22f..ec5ddc4 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -541,7 +541,9 @@ def abort_cherry_pick(self): run `git cherry-pick --abort` and then clean up the branch """ if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED: - raise ValueError(f"One can only abort a paused process. Current state: {self.initial_state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}") + raise ValueError( + f"One can only abort a paused process. Current state: {self.initial_state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" + ) try: validate_sha("CHERRY_PICK_HEAD") diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 45a2562..84b23bb 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -2,6 +2,7 @@ import pathlib import subprocess import warnings +import re from collections import ChainMap from unittest import mock @@ -1141,7 +1142,7 @@ def test_continue_cherry_pick_invalid_state(tmp_git_repo_dir): assert get_state() == WORKFLOW_STATES.UNSET - with pytest.raises(ValueError, match=r"^One can only continue a paused process.$"): + with pytest.raises(ValueError, match=re.compile(r"^One can only continue a paused process.")): cherry_picker.continue_cherry_pick() assert get_state() == WORKFLOW_STATES.UNSET # success @@ -1167,7 +1168,7 @@ def test_abort_cherry_pick_invalid_state(tmp_git_repo_dir): assert get_state() == WORKFLOW_STATES.UNSET - with pytest.raises(ValueError, match=r"^One can only abort a paused process.$"): + with pytest.raises(ValueError, match=re.compile(r"^One can only abort a paused process.")): cherry_picker.abort_cherry_pick() From 44d9343a2617e6bd6c406c1e6319501bdfb21f17 Mon Sep 17 00:00:00 2001 From: Mariatta Date: Tue, 10 Oct 2023 14:16:06 +0200 Subject: [PATCH 3/3] Fix isort --- cherry_picker/test_cherry_picker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 84b23bb..0cdd96b 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -1,8 +1,8 @@ import os import pathlib +import re import subprocess import warnings -import re from collections import ChainMap from unittest import mock