summaryrefslogtreecommitdiff
path: root/tests/config/pylint_config/test_pylint_config_utils.py
blob: d41afec1d12a34725b81d299478700da53b7a33c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
        == """Answer should be one of i, ini, t, toml.
Type 'exit()' if you want to exit the program.
Answer should be one of i, ini, t, toml.
Type 'exit()' if you want to exit the program.
Answer should be one of i, ini, t, toml.
Type 'exit()' if you want to exit the program.
Stopping 'pylint-config'.
"""
    )