Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only accept documented choices after -i and -q #3344

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
Expand All @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"):
Expand Down
Loading