Example #1
0
def test_raise_on_invalid_filters():
    config = LinterConfig(name="TestLinter",
                          class_="TestLinter",
                          include=[1, 2, 3])
    with pytest.raises(ValueError):
        linter = LinterUnderTest(config)

    # Not nonetype but invalid regular expression field nonetheless
    config.include = dict()
    with pytest.raises(ValueError):
        linter = LinterUnderTest(config)
Example #2
0
def test_is_applicable():
    config = LinterConfig(name="TestLinter",
                          class_="TestLinter",
                          include=".(cpp|hpp)$",
                          exclude=[
                              "(.py$)", "CMakeLists.txt$", "(.*Doxyfile.in$)",
                              "(willow/include/popart/vendored/.*)"
                          ])
    linter = LinterUnderTest(config)

    included_files = [
        "file.cpp", "welldocumentedinterface.hpp",
        "long/path/to/file/header.hpp", "/absolute/path/to/file.hpp"
    ]

    excluded_files = [
        "useful_script.py", "path/to/robust_and_stable_linter.py",
        "CMakeLists.txt", "cmake/is/great/CMakeLists.txt",
        "willow/include/popart/vendored/iseven.hpp", "Doxyfile.in",
        "docs/Doxyfile.in"
    ]

    for inc in included_files:
        assert linter.is_applicable(inc)

    for exc in excluded_files:
        assert not linter.is_applicable(exc)
Example #3
0
def linter():
    dummy_config = LinterConfig(
        name="TestLinter",
        class_="scripts.lint.linters.ClangFormatLinter",
    )
    linter = ClangFormatLinter(dummy_config)
    yield linter
Example #4
0
def test_linter_from_config():
    dummy_config = LinterConfig(name="test_linter",
                                class_="linters.dummy_linters.LinterUnderTest",
                                version="0.0.0")
    linter = linter_from_config(dummy_config)
    assert linter is not None
    assert type(linter) is LinterUnderTest
    assert linter.get_version() == (0, 0, 0)
    assert linter.is_available()

    unavailable_config = LinterConfig(
        name="unavailable_linter",
        class_="linters.dummy_linters.UnavailableLinter",
        version="0.0.0")
    linter = linter_from_config(unavailable_config)
    assert not linter.is_available()
Example #5
0
def linter():
    dummy_config = LinterConfig(name="TestLinter",
                                class_="lint.linters.YapfLinter",
                                config_file=".style.yapf",
                                version='1.2.3')
    linter = YapfLinter(dummy_config)
    yield linter
Example #6
0
def test_create_linters():
    ok_linters = [
        LinterConfig(
            name="TestLinter",
            class_="linters.dummy_linters.LinterUnderTest",
        ),
        LinterConfig(name="DeleteLinter",
                     class_='linters.dummy_linters.DeleteLinter'),
    ]
    unavailable_linter = LinterConfig(
        name="UnavailableLinter",
        class_="linters.dummy_linters.UnavailableLinter")
    bad_version_linter = LinterConfig(
        name="BadVersionLinter",
        class_="linters.dummy_linters.LinterUnderTest",
        version="2.2.2")
    bad_linters = [unavailable_linter, bad_version_linter]
    configs = ok_linters + bad_linters
    linters, error_msgs = create_linters_and_check_for_errors(configs)
    assert len(linters) == len(ok_linters)
    for linter in linters:
        assert issubclass(type(linter), ILinter)
        assert linter.is_available()

    assert len(error_msgs) == len(bad_linters)
    for msg in error_msgs:
        assert msg
        assert type(msg) is LinterMessage

    linters, error_msgs = create_linters_and_check_for_errors(
        [unavailable_linter])
    assert not linters
    for msg in error_msgs:
        message_text = msg.message
        assert 'Linter UnavailableLinter is not available or installed.' in message_text
        assert 'UnavailableLinterInstallMessage' in message_text

    linters, error_msgs = create_linters_and_check_for_errors(
        [bad_version_linter])
    assert not linters
    for msg in error_msgs:
        message_text = msg.message
        assert 'Version requirement not satisfied for linter BadVersionLinter' in message_text
        assert 'Version required: 2.2.2' in message_text
        assert 'You have: 0.0.0' in message_text
def linter():
    dummy_config = LinterConfig(name="TestLinter",
                                class_="lint.linters.CopyrightLinter")
    linter = CopyrightLinter(dummy_config)
    yield linter
Example #8
0
def test_gives_correct_arc_message():
    config = LinterConfig(name="DeleteLinter", class_='DeleteLinter')

    linter = DeleteLinter(config)
    linter.apply_lint_function(file_path='', file_contents='BlahBlah')
    assert linter.get_linter_message() == 'Wiped the file.'