|
| 1 | +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 2 | +# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE |
| 3 | +# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt |
| 4 | + |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import pytest |
| 8 | +from _pytest.capture import CaptureFixture |
| 9 | + |
| 10 | +from pylint import run_pylint |
| 11 | + |
| 12 | + |
| 13 | +def test_run_pylint_with_invalid_argument(capsys: CaptureFixture[str]) -> None: |
| 14 | + """Check that appropriate exit code is used with invalid argument.""" |
| 15 | + with pytest.raises(SystemExit) as ex: |
| 16 | + run_pylint(["--never-use-this"]) |
| 17 | + captured = capsys.readouterr() |
| 18 | + assert captured.err.startswith("usage: pylint [options]") |
| 19 | + assert ex.value.code == 32 |
| 20 | + |
| 21 | + |
| 22 | +def test_run_pylint_with_invalid_argument_in_config( |
| 23 | + capsys: CaptureFixture[str], tmp_path: Path |
| 24 | +) -> None: |
| 25 | + """Check that appropriate exit code is used with an ambiguous |
| 26 | + argument in a config file. |
| 27 | + """ |
| 28 | + test_file = tmp_path / "testpylintrc" |
| 29 | + with open(test_file, "w", encoding="utf-8") as f: |
| 30 | + f.write("[MASTER]\nno=") |
| 31 | + |
| 32 | + with pytest.raises(SystemExit) as ex: |
| 33 | + run_pylint(["--rcfile", f"{test_file}"]) |
| 34 | + captured = capsys.readouterr() |
| 35 | + assert captured.err.startswith("usage: pylint [options]") |
| 36 | + assert ex.value.code == 32 |
0 commit comments