Skip to content

Commit cc0a384

Browse files
authored
Merge pull request #26 from George-Ogden/empty-exceptions
Empty Exceptions
2 parents 39e750f + 4a60c21 commit cc0a384

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

.mirror.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# DANGER: EDIT AT YOUR OWN RISK. Track this file in version control so that others can sync files correctly.
2-
- commit: 96edaa5bb16a28eeea4f7a933c30088c2ee5df65
2+
- commit: 26f0c34dacfaf7ad3d790b9b8a005daf242960b2
33
files:
44
- .github/python-release.yaml
55
- .github/python-test.yaml

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ci:
66

77
repos:
88
- repo: https://github.com/George-Ogden/mirror-rorrim/
9-
rev: v0.4.3
9+
rev: v0.4.4
1010
hooks:
1111
- id: mirror-check
1212
fail_fast: true
@@ -33,7 +33,7 @@ repos:
3333
args: ["--severity=warning"]
3434

3535
- repo: https://github.com/astral-sh/ruff-pre-commit/
36-
rev: v0.14.10
36+
rev: v0.14.13
3737
hooks:
3838
- id: ruff-check
3939
args:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ If you use, `pre-commit`, consider adding this repo as a hook to check for updat
7070

7171
```yaml
7272
- repo: https://github.com/George-Ogden/mirror-rorrim/
73-
rev: v0.4.4
73+
rev: v0.4.5
7474
hooks:
7575
- id: mirror-check
7676
```

mirror/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def main(*args: P.args, **kwargs: P.kwargs) -> None:
2929
except BaseException as e:
3030
logger.debug(f"Threw {type(e)}!")
3131
logger.trace(traceback.format_exc())
32-
logger.error(f"{type(e).__name__}: {e}")
32+
message = str(e).strip()
33+
logger.error(f"{type(e).__name__}{f': {message}' if message else ''}")
3334
sys.exit(1)
3435
if exitcode is not None:
3536
sys.exit(exitcode)

mirror/main_test.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import shutil
66
import subprocess
77
import sys
8+
from unittest import mock
89

910
from inline_snapshot import snapshot
1011
import pytest
@@ -27,7 +28,7 @@ def remove_git_data(local: GitDir) -> None:
2728

2829

2930
@pytest.mark.parametrize(
30-
"args, exitcode ,logs, setup_repo",
31+
"args, exitcode, logs, setup_repo",
3132
[
3233
# install tests
3334
(
@@ -209,6 +210,40 @@ def test_main(
209210
assert normalize_message(out, git_dir=local_git_repo) == logs
210211

211212

213+
@pytest.mark.parametrize(
214+
"args, logs, setup_repo",
215+
[
216+
(
217+
# update mirror file
218+
"sync",
219+
snapshot("Updating all files [failed] KeyboardInterrupt"),
220+
"syncer_tests/update_mirror",
221+
)
222+
],
223+
)
224+
def test_main_with_keyboard_interrupt(
225+
args: str,
226+
logs: str,
227+
setup_repo: str | RelDir | None,
228+
local_git_repo: GitDir,
229+
test_data_path: AbsDir,
230+
capsys: CaptureFixture,
231+
) -> None:
232+
if setup_repo:
233+
add_commit(local_git_repo, test_data_path / RelDir(setup_repo))
234+
argv = ["-q", *shlex.split(args)]
235+
mirror_existed_before = (local_git_repo / MIRROR_LOCK).exists()
236+
with (
237+
pytest.raises(SystemExit) as e,
238+
mock.patch.object(GitHelper, "wait", mock.Mock(side_effect=[KeyboardInterrupt])), # type: ignore [arg-type]
239+
):
240+
main.main(argv, prog_name=MIRROR_NAME)
241+
assert e.value.code != 0
242+
assert (local_git_repo / MIRROR_LOCK).exists() == mirror_existed_before
243+
out, _err = capsys.readouterr()
244+
assert normalize_message(out, git_dir=local_git_repo) == logs
245+
246+
212247
@pytest.mark.slow
213248
def test_pre_commit_with_mirror(
214249
local_git_repo: GitDir, test_data_path: AbsDir, capfd: CaptureFixture

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.4
1+
0.4.5

0 commit comments

Comments
 (0)