diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-04-15 12:56:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-15 12:56:16 +0200 |
commit | 63173f8f3a21671155c9a3122c5ecaa8a66ce0b5 (patch) | |
tree | e850b0f78448032afd01c89689a150cdc5b39818 | |
parent | 64675c571f60bc5146b0e81a48126c1e088a205a (diff) | |
download | pylint-git-63173f8f3a21671155c9a3122c5ecaa8a66ce0b5.tar.gz |
Improve coverage of ``argparse`` (#6332)
* Fix coverage of ``pylint/config/config_file_parser.py``
* Fix coverage of ``pylint/config/argument.py``
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r-- | tests/config/functional/toml/toml_without_pylint.toml | 6 | ||||
-rw-r--r-- | tests/config/test_config.py | 25 | ||||
-rw-r--r-- | tests/config/test_find_default_config_files.py | 16 |
3 files changed, 47 insertions, 0 deletions
diff --git a/tests/config/functional/toml/toml_without_pylint.toml b/tests/config/functional/toml/toml_without_pylint.toml new file mode 100644 index 000000000..ede9086e4 --- /dev/null +++ b/tests/config/functional/toml/toml_without_pylint.toml @@ -0,0 +1,6 @@ +# Check that we do nothing if there is no pylint configuration + +[tool.othertool] +disable = "logging-not-lazy,logging-format-interpolation" +jobs = "10" +reports = "yes" diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 89b6198a4..10e3fa4c1 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -7,6 +7,7 @@ from __future__ import annotations import os from pathlib import Path +import pytest from pytest import CaptureFixture from pylint.lint import Run @@ -58,3 +59,27 @@ def test_unknown_message_id(capsys: CaptureFixture) -> None: Run([str(EMPTY_MODULE), "--disable=12345"], exit=False) output = capsys.readouterr() assert "Command line:1:0: E0012: Bad option value for --disable." in output.out + + +def test_unknown_confidence(capsys: CaptureFixture) -> None: + """Check that we correctly error an unknown confidence value.""" + with pytest.raises(SystemExit): + Run([str(EMPTY_MODULE), "--confidence=UNKNOWN_CONFIG"], exit=False) + output = capsys.readouterr() + assert "argument --confidence: UNKNOWN_CONFIG should be in" in output.err + + +def test_unknown_yes_no(capsys: CaptureFixture) -> None: + """Check that we correctly error on an unknown yes/no value.""" + with pytest.raises(SystemExit): + Run([str(EMPTY_MODULE), "--reports=maybe"], exit=False) + output = capsys.readouterr() + assert "Invalid yn value 'maybe', should be in " in output.err + + +def test_unknown_py_version(capsys: CaptureFixture) -> None: + """Check that we correctly error on an unknown python-version.""" + with pytest.raises(SystemExit): + Run([str(EMPTY_MODULE), "--py-version=the-newest"], exit=False) + output = capsys.readouterr() + assert "the-newest has an invalid format, should be a version string." in output.err diff --git a/tests/config/test_find_default_config_files.py b/tests/config/test_find_default_config_files.py index 7d25b4e8b..373099f08 100644 --- a/tests/config/test_find_default_config_files.py +++ b/tests/config/test_find_default_config_files.py @@ -14,9 +14,11 @@ from collections.abc import Iterator from pathlib import Path import pytest +from pytest import CaptureFixture from pylint import config, testutils from pylint.config.find_default_config_files import _cfg_has_config, _toml_has_config +from pylint.lint.run import Run @pytest.fixture @@ -143,6 +145,20 @@ def test_pylintrc_parentdir_no_package() -> None: assert next(config.find_default_config_files(), None) == expected +@pytest.mark.usefixtures("pop_pylintrc") +def test_verbose_output_no_config(capsys: CaptureFixture) -> None: + """Test that we print a log message in verbose mode with no file.""" + with tempdir() as chroot: + with fake_home(): + chroot_path = Path(chroot) + testutils.create_files(["a/b/c/d/__init__.py"]) + os.chdir(chroot_path / "a/b/c") + with pytest.raises(SystemExit): + Run(["--verbose"]) + out = capsys.readouterr() + assert "No config file found, using default configuration" in out.err + + @pytest.mark.parametrize( "content,expected", [ |