Skip to content

Commit b6de749

Browse files
Only accept documented choices after -i and -q (#3344)
1 parent 058eaf1 commit b6de749

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

codespell_lib/_codespell.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,13 @@ def parse_options(
501501
action="store",
502502
type=int,
503503
default=0,
504+
choices=range(0, 4),
504505
help="set interactive mode when writing changes:\n"
505506
"- 0: no interactivity.\n"
506507
"- 1: ask for confirmation.\n"
507508
"- 2: ask user to choose one fix when more than one is available.\n"
508509
"- 3: both 1 and 2",
510+
metavar="MODE",
509511
)
510512

511513
parser.add_argument(
@@ -514,6 +516,7 @@ def parse_options(
514516
action="store",
515517
type=int,
516518
default=34,
519+
choices=range(0, 64),
517520
help="bitmask that allows suppressing messages:\n"
518521
"- 0: print all messages.\n"
519522
"- 1: disable warnings about wrong encoding.\n"
@@ -526,6 +529,7 @@ def parse_options(
526529
"combined; e.g. use 3 for levels 1+2, 7 for "
527530
"1+2+4, 23 for 1+2+4+16, etc. "
528531
"The default mask is %(default)s.",
532+
metavar="LEVEL",
529533
)
530534

531535
parser.add_argument(

codespell_lib/tests/test_basic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pathlib import Path
1010
from shutil import copyfile
1111
from typing import Any, Generator, Optional, Tuple, Union
12+
from unittest import mock
1213

1314
import pytest
1415

@@ -237,7 +238,11 @@ def test_interactivity(
237238
try:
238239
assert cs.main(fname) == 0, "empty file"
239240
fname.write_text("abandonned\n")
240-
assert cs.main("-i", "-1", fname) == 1, "bad"
241+
with mock.patch.object(sys, "argv", ("-i", "-1", fname)):
242+
with pytest.raises(SystemExit) as e:
243+
cs.main("-i", "-1", fname)
244+
assert e.type == SystemExit
245+
assert e.value.code != 0
241246
with FakeStdin("y\n"):
242247
assert cs.main("-i", "3", fname) == 1
243248
with FakeStdin("n\n"):

0 commit comments

Comments
 (0)