diff options
author | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-05-21 15:41:58 +0200 |
---|---|---|
committer | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-05-22 13:50:37 +0200 |
commit | b4e2ae201b44b446fd167ac65c28ba2fc3c824ef (patch) | |
tree | e16bc130c84ba8ca186d095b37f1a5e6b23b9cfb /tests/config | |
parent | b02d9af8fbbbedd25ad29518ef92851c08cdefa7 (diff) | |
download | pylint-git-b4e2ae201b44b446fd167ac65c28ba2fc3c824ef.tar.gz |
Retry user input if it is not correct
Diffstat (limited to 'tests/config')
-rw-r--r-- | tests/config/pylint_config/test_pylint_config_generate.py | 6 | ||||
-rw-r--r-- | tests/config/pylint_config/test_pylint_config_utils.py | 35 |
2 files changed, 38 insertions, 3 deletions
diff --git a/tests/config/pylint_config/test_pylint_config_generate.py b/tests/config/pylint_config/test_pylint_config_generate.py index 60a037747..118aff0fa 100644 --- a/tests/config/pylint_config/test_pylint_config_generate.py +++ b/tests/config/pylint_config/test_pylint_config_generate.py @@ -34,7 +34,7 @@ def test_format_of_output( ) -> None: """Check that we output the correct format.""" # Set the answers needed for the input() calls - answers = iter(["T", "toml", "TOML", "I", "INI", "TOMLINI"]) + answers = iter(["T", "toml", "TOML", "I", "INI", "TOMLINI", "exit()"]) monkeypatch.setattr("builtins.input", lambda x: next(answers)) with warnings.catch_warnings(): @@ -64,6 +64,6 @@ def test_format_of_output( captured = capsys.readouterr() assert "[MAIN]" in captured.out - # Check 'TOMLINI' - with pytest.raises(ValueError, match="Format should be one.*"): + # Check 'TOMLINI' and then 'exit()' + with pytest.raises(SystemExit): Run(["generate", "--interactive"], exit=False) diff --git a/tests/config/pylint_config/test_pylint_config_utils.py b/tests/config/pylint_config/test_pylint_config_utils.py new file mode 100644 index 000000000..210bcf93b --- /dev/null +++ b/tests/config/pylint_config/test_pylint_config_utils.py @@ -0,0 +1,35 @@ +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt + +"""Test for the 'pylint-config' utils.""" + + +import pytest +from pytest import CaptureFixture, MonkeyPatch + +from pylint.config._pylint_config.utils import get_and_validate_format + + +def test_retrying_user_input_validation( + monkeypatch: MonkeyPatch, capsys: CaptureFixture[str] +) -> None: + """Check that we retry after a wrong answer.""" + # Set the answers needed for the input() calls + answers = iter(["A", "B", "EXIT", "EXIT()"]) + monkeypatch.setattr("builtins.input", lambda x: next(answers)) + + with pytest.raises(SystemExit): + get_and_validate_format() + captured = capsys.readouterr() + assert ( + captured.out + == """Format should be one of i, ini, t, toml. +Type 'exit()' if you want to exit the program. +Format should be one of i, ini, t, toml. +Type 'exit()' if you want to exit the program. +Format should be one of i, ini, t, toml. +Type 'exit()' if you want to exit the program. +Stopping 'pylint-config'. +""" + ) |