Esempio n. 1
0
def test_get_expected_output(caplog: LogCaptureFixture) -> None:
    caplog.set_level(logging.INFO)
    exit_code, _ = get_expected_output(DATA_DIRECTORY / "t.toml", USER_SPECIFIC_PATH)
    assert "Too much .out files" in str(caplog.text)
    assert exit_code == -1
    exit_code, _ = get_expected_output(DATA_DIRECTORY / "u.toml", USER_SPECIFIC_PATH)
    assert exit_code == -1
    assert "Wrong format for .out file name" in str(caplog.text)
    exit_code, _ = get_expected_output(DATA_DIRECTORY / "v.toml", USER_SPECIFIC_PATH)
    assert exit_code == 0
    assert ".out file does not exists" in str(caplog.text)
Esempio n. 2
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