コード例 #1
0
def test_functional(
    test_file: FunctionalTestFile, recwarn: WarningsRecorder, pytestconfig: Config
) -> None:
    __tracebackhide__ = True  # pylint: disable=unused-variable
    if UPDATE_FILE.exists():
        lint_test: Union[
            LintModuleOutputUpdate, testutils.LintModuleTest
        ] = LintModuleOutputUpdate(test_file, pytestconfig)
    else:
        lint_test = testutils.LintModuleTest(test_file, pytestconfig)
    lint_test.setUp()
    lint_test.runTest()
    warning = None
    try:
        # Catch <unknown>:x: DeprecationWarning: invalid escape sequence
        # so it's not shown during tests
        warning = recwarn.pop()
    except AssertionError:
        pass
    if warning is not None:
        if (
            test_file.base in TEST_WITH_EXPECTED_DEPRECATION
            and sys.version_info.minor > 5
        ):
            assert issubclass(warning.category, DeprecationWarning)
            assert "invalid escape sequence" in str(warning.message)
コード例 #2
0
def test_functional(test_file):
    LintTest = (
        LintModuleOutputUpdate(test_file)
        if UPDATE
        else testutils.LintModuleTest(test_file)
    )
    LintTest.setUp()
    LintTest._runTest()
コード例 #3
0
def test_minimal_messages_config_excluded_file(pytest_config) -> None:
    """Test that functional test files can be excluded from the run with
    --minimal-messages-config if they set the exclude_from_minimal_messages_config
    option in their rcfile.
    """
    test_file = FunctionalTestFile(
        str(DATA_DIRECTORY / "m"), "minimal_messages_excluded.py"
    )
    mod_test = testutils.LintModuleTest(test_file, pytest_config)
    with pytest.raises(Skipped):
        mod_test.setUp()
コード例 #4
0
ファイル: test_functional.py プロジェクト: samdoran/pylint
def test_functional(test_file, recwarn):
    LintTest = (LintModuleOutputUpdate(test_file)
                if UPDATE.exists() else testutils.LintModuleTest(test_file))
    LintTest.setUp()
    LintTest._runTest()
    warning = None
    try:
        # Catch <unknown>:x: DeprecationWarning: invalid escape sequence
        # so it's not shown during tests
        warning = recwarn.pop()
    except AssertionError:
        pass
    if warning is not None:
        if (test_file.base in TEST_WITH_EXPECTED_DEPRECATION
                and sys.version_info.minor > 5):
            assert issubclass(warning.category, DeprecationWarning)
            assert "invalid escape sequence" in str(warning.message)
コード例 #5
0
def test_functional(test_file: FunctionalTestFile, recwarn: WarningsRecorder,
                    pytestconfig: Config) -> None:
    __tracebackhide__ = True  # pylint: disable=unused-variable
    if UPDATE_FILE.exists():
        lint_test: (LintModuleOutputUpdate
                    | testutils.LintModuleTest) = LintModuleOutputUpdate(
                        test_file, pytestconfig)
    else:
        lint_test = testutils.LintModuleTest(test_file, pytestconfig)
    lint_test.setUp()
    lint_test.runTest()
    if recwarn.list:
        if (test_file.base in TEST_WITH_EXPECTED_DEPRECATION
                and sys.version_info.minor > 5):
            assert any("invalid escape sequence" in str(i.message)
                       for i in recwarn.list
                       if issubclass(i.category, DeprecationWarning))
コード例 #6
0
def test_minimal_messages_config_enabled(pytest_config) -> None:
    """Test that all messages not targeted in the functional test are disabled
    when running with --minimal-messages-config.
    """
    test_file = FunctionalTestFile(
        str(DATA_DIRECTORY / "m"), "minimal_messages_config.py"
    )
    mod_test = testutils.LintModuleTest(test_file, pytest_config)
    assert all(
        mod_test._linter.is_message_enabled(msgid)
        for msgid in (
            "consider-using-with",
            "unspecified-encoding",
            "consider-using-f-string",
            # Always enable fatal errors: important not to have false negatives
            "astroid-error",
            "fatal",
            "syntax-error",
        )
    )
    assert not mod_test._linter.is_message_enabled("unused-import")
コード例 #7
0
def test_parsing_of_pylintrc_init_hook() -> None:
    """Test that we correctly parse an init-hook in a settings file."""
    with pytest.raises(RuntimeError):
        test_file = FunctionalTestFile(str(DATA_DIRECTORY), "init_hook.py")
        testutils.LintModuleTest(test_file)