| 1 |
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 2 |
# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE |
| 3 |
# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt |
| 4 |
|
| 5 |
"""Test for the 'pylint-config generate' command.""" |
| 6 |
|
| 7 |
|
| 8 |
import warnings |
| 9 |
|
| 10 |
import pytest |
| 11 |
from pytest import CaptureFixture |
| 12 |
|
| 13 |
from pylint.constants import PY314_PLUS |
| 14 |
from pylint.lint.run import _PylintConfigRun as Run |
| 15 |
|
| 16 |
|
| 17 |
def test_pylint_config_main_messages(capsys: CaptureFixture[str]) -> None: |
| 18 |
"""Check that the help messages are displayed correctly.""" |
| 19 |
with warnings.catch_warnings(): |
| 20 |
warnings.filterwarnings("ignore", message="NOTE:.*", category=UserWarning) |
| 21 |
Run([], exit=False) |
| 22 |
captured = capsys.readouterr() |
| 23 |
assert captured.out.startswith("usage: pylint-config [options]") |
| 24 |
assert "--interactive" not in captured.out |
| 25 |
|
| 26 |
Run(["-h"], exit=False) |
| 27 |
captured_two = capsys.readouterr() |
| 28 |
assert captured_two.out == captured.out |
| 29 |
|
| 30 |
with pytest.raises(SystemExit): |
| 31 |
Run(["generate", "-h"]) |
| 32 |
captured = capsys.readouterr() |
| 33 |
if PY314_PLUS: |
| 34 |
assert captured.out.startswith("usage: pylint-config generate") |
| 35 |
else: |
| 36 |
assert captured.out.startswith("usage: pylint-config [options] generate") |
| 37 |
assert "--interactive" in captured.out |
| 38 |
|
| 39 |
with pytest.raises(SystemExit) as ex: |
| 40 |
Run(["generate"]) |
| 41 |
captured_two = capsys.readouterr() |
| 42 |
assert captured_two.out == captured.out |
| 43 |
# This gets auto-raised by argparse to be 0. |
| 44 |
assert ex.value.code == 32 |
| 45 |
|
| 46 |
with pytest.raises(SystemExit) as ex: |
| 47 |
Run(["-h"]) |
| 48 |
assert ex.value.code == 32 |