commit: d37395418f44d5716a24d9cc84f8bf2d8bc084bb Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> AuthorDate: Sun Jun 2 19:18:05 2024 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Sun Jun 2 19:18:05 2024 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=d3739541
mask: fix test & improve error messages Resolves: https://github.com/pkgcore/pkgdev/issues/188 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgdev/scripts/pkgdev_mask.py | 7 ++++++- tests/scripts/test_pkgdev_mask.py | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pkgdev/scripts/pkgdev_mask.py b/src/pkgdev/scripts/pkgdev_mask.py index 1d614a0..450c52c 100644 --- a/src/pkgdev/scripts/pkgdev_mask.py +++ b/src/pkgdev/scripts/pkgdev_mask.py @@ -101,7 +101,12 @@ def _mask_validate(parser, namespace): atoms = set() maintainers = set() - namespace.bugs = list(map(int, dict.fromkeys(namespace.bugs))) + try: + namespace.bugs = list(map(int, dict.fromkeys(namespace.bugs))) + except ValueError: + parser.error("argument -b/--bug: invalid integer value") + if min(namespace.bugs, default=1) < 1: + parser.error("argument -b/--bug: must be >= 1") if not namespace.rites and namespace.file_bug: mask.error("bug filing requires last rites") diff --git a/tests/scripts/test_pkgdev_mask.py b/tests/scripts/test_pkgdev_mask.py index 8366ced..63d1e53 100644 --- a/tests/scripts/test_pkgdev_mask.py +++ b/tests/scripts/test_pkgdev_mask.py @@ -337,6 +337,7 @@ class TestPkgdevMask: for bug_nums, expected in [ (["42"], "Bug #42."), (["42", "43"], "Bugs #42, #43."), + (["42,43", "43"], "Bugs #42, #43."), ]: args = [] for bug_num in bug_nums: @@ -361,7 +362,7 @@ class TestPkgdevMask: def test_mask_bug_bad(self, capsys, tool): for arg, expected in [("-1", "must be >= 1"), ("foo", "invalid integer value")]: - with pytest.raises(SystemExit): + with pytest.raises(SystemExit), chdir(pjoin(self.repo.path)): tool.parse_args(["mask", "--bug", arg]) out, err = capsys.readouterr() assert err.strip() == f"pkgdev mask: error: argument -b/--bug: {expected}"