diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 9d1fd9abd9..3170fb4a14 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -501,11 +501,13 @@ def parse_options( action="store", type=int, default=0, + choices=range(0, 4), help="set interactive mode when writing changes:\n" "- 0: no interactivity.\n" "- 1: ask for confirmation.\n" "- 2: ask user to choose one fix when more than one is available.\n" "- 3: both 1 and 2", + metavar="MODE", ) parser.add_argument( @@ -514,6 +516,7 @@ def parse_options( action="store", type=int, default=34, + choices=range(0, 64), help="bitmask that allows suppressing messages:\n" "- 0: print all messages.\n" "- 1: disable warnings about wrong encoding.\n" @@ -526,6 +529,7 @@ def parse_options( "combined; e.g. use 3 for levels 1+2, 7 for " "1+2+4, 23 for 1+2+4+16, etc. " "The default mask is %(default)s.", + metavar="LEVEL", ) parser.add_argument( diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 51ee4b8390..98e5dd41f0 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -9,6 +9,7 @@ from pathlib import Path from shutil import copyfile from typing import Any, Generator, Optional, Tuple, Union +from unittest import mock import pytest @@ -237,7 +238,11 @@ def test_interactivity( try: assert cs.main(fname) == 0, "empty file" fname.write_text("abandonned\n") - assert cs.main("-i", "-1", fname) == 1, "bad" + with mock.patch.object(sys, "argv", ("-i", "-1", fname)): + with pytest.raises(SystemExit) as e: + cs.main("-i", "-1", fname) + assert e.type == SystemExit + assert e.value.code != 0 with FakeStdin("y\n"): assert cs.main("-i", "3", fname) == 1 with FakeStdin("n\n"):