From e4f927d85b084d2097514973afdf739acaf2cdd7 Mon Sep 17 00:00:00 2001 From: Mariatta Date: Tue, 10 Oct 2023 16:01:49 +0200 Subject: [PATCH] When raising error, show the current state vs expected state (#87) --- 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 0427f94..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("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") diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 45a2562..0cdd96b 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -1,5 +1,6 @@ import os import pathlib +import re import subprocess import warnings from collections import ChainMap @@ -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()