Skip to content

Commit

Permalink
[symilar] Fix the short form options that weren't being processed pro…
Browse files Browse the repository at this point in the history
…perly

Closes #9343
  • Loading branch information
Pierre-Sassoulas committed Jun 11, 2024
1 parent e13544f commit 3cf313a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion doc/whatsnew/fragments/9343.bugfix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Fixed a crash in ``symilar`` when the ``-d`` option was not properly recognized.
Fixed a crash in ``symilar`` when the ``-d`` or ``-i`` short option were not properly recognized.
It's still impossible to do ``-d=1`` (you must do ``-d 1``).

Closes #9343
2 changes: 1 addition & 1 deletion pylint/checkers/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def Run(argv: Sequence[str] | None = None) -> NoReturn:
if argv is None:
argv = sys.argv[1:]

s_opts = "hdi"
s_opts = "hd:i:"
l_opts = [
"help",
"duplicates=",
Expand Down
8 changes: 4 additions & 4 deletions tests/checkers/unittest_similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,14 @@ def test_set_duplicate_lines_to_zero() -> None:
assert output.getvalue() == ""


@pytest.mark.parametrize("v", ["d", "i"])
@pytest.mark.parametrize("v", ["d"])
def test_bad_equal_short_form_option(v: str) -> None:
"""Regression test for https://github.com/pylint-dev/pylint/issues/9343"""
output = StringIO()
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
similar.Run([f"-{v}=0", SIMILAR1, SIMILAR2])
assert ex.value.code == 2
assert "option -= not recognized" in output.getvalue()
assert "invalid literal for int() with base 10: '=0'" in output.getvalue()


@pytest.mark.parametrize("v", ["i", "d"])
Expand All @@ -515,8 +515,8 @@ def test_space_short_form_option(v: str) -> None:
output = StringIO()
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
similar.Run([f"-{v} 2", SIMILAR1, SIMILAR2])
assert ex.value.code == 2
assert "option - not recognized" in output.getvalue()
assert ex.value.code == 0
assert "similar lines in" in output.getvalue()


def test_bad_short_form_option() -> None:
Expand Down

0 comments on commit 3cf313a

Please sign in to comment.