Debian Codegraph @

tests/config/pylint_config/test_pylint_config_utils.py

raw
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' utils."""
6
7
8 import pytest
9 from pytest import CaptureFixture, MonkeyPatch
10
11 from pylint.config._pylint_config.utils import get_and_validate_format
12
13
14 def test_retrying_user_input_validation(
15 monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]
16 ) -> None:
17 """Check that we retry after a wrong answer."""
18 # Set the answers needed for the input() calls
19 answers = iter(["A", "B", "EXIT", "EXIT()"])
20 monkeypatch.setattr("builtins.input", lambda x: next(answers))
21
22 with pytest.raises(SystemExit):
23 get_and_validate_format()
24 captured = capsys.readouterr()
25 assert (
26 captured.out
27 == """Answer should be one of i, ini, t, toml.
28 Type 'exit()' if you want to exit the program.
29 Answer should be one of i, ini, t, toml.
30 Type 'exit()' if you want to exit the program.
31 Answer should be one of i, ini, t, toml.
32 Type 'exit()' if you want to exit the program.
33 Stopping 'pylint-config'.
34 """
35 )