Example #1
0
def test_functional_config_loading(
    configuration_path: str,
    default_configuration: PylintConfiguration,
    file_to_lint_path: str,
    capsys: CaptureFixture,
    caplog: LogCaptureFixture,
):
    """Functional tests for configurations."""
    # logging is helpful to see what's expected and why. The output of the
    # program is checked during the test so printing messes with the result.
    caplog.set_level(logging.INFO)
    configuration_path = str(FUNCTIONAL_DIR / configuration_path)
    msg = f"Wrong result with configuration {configuration_path}"
    expected_code, expected_output = get_expected_output(
        configuration_path, USER_SPECIFIC_PATH)
    expected_loaded_configuration = get_expected_configuration(
        configuration_path, default_configuration)
    mock_exit, _, runner = run_using_a_configuration_file(
        configuration_path, file_to_lint_path)
    mock_exit.assert_called_once_with(expected_code)
    out, err = capsys.readouterr()
    # 'rstrip()' applied, so we can have a final newline in the expected test file
    assert expected_output.rstrip() == out.rstrip(), msg
    assert sorted(expected_loaded_configuration.keys()) == sorted(
        runner.linter.namespace.__dict__.keys()), msg
    for key, expected_value in expected_loaded_configuration.items():
        key_msg = f"{msg} for key '{key}':"
        if isinstance(expected_value, list):
            assert sorted(expected_value) == sorted(
                runner.linter.namespace.__dict__[key]), key_msg
        else:
            assert expected_value == runner.linter.namespace.__dict__[
                key], key_msg
    assert not err, msg
Example #2
0
def default_configuration(tmp_path: Path,
                          file_to_lint_path: str) -> PylintConfiguration:
    empty_pylintrc = tmp_path / "pylintrc"
    empty_pylintrc.write_text("")
    mock_exit, _, runner = run_using_a_configuration_file(
        str(empty_pylintrc), file_to_lint_path)
    mock_exit.assert_called_once_with(0)
    return runner.linter.config.__dict__
Example #3
0
def test_can_read_toml_env_variable(tmp_path: Path,
                                    file_to_lint_path: str) -> None:
    """We can read and open a properly formatted toml file."""
    config_file = tmp_path / "pyproject.toml"
    config_file.write_text("""
[tool.pylint."messages control"]
disable = "logging-not-lazy,logging-format-interpolation"
jobs = "10"
reports = "yes"
""")
    env_var = "tmp_path_env"
    os.environ[env_var] = str(config_file)
    mock_exit, _, runner = run_using_a_configuration_file(
        f"${env_var}", file_to_lint_path)
    mock_exit.assert_called_once_with(0)
    check_configuration_file_reader(runner)