示例#1
0
def test_resources_get_file_doesnt_exist():
    """
    Test get_file where the file doesn't exist

    Expected results: None is returned
    """
    with TemporaryDirectory() as tmp_dir:
        resources = Resources([tmp_dir])
        os.mkdir(os.path.join(tmp_dir, "rsc"))
        assert resources.get_file("nope") is None
示例#2
0
def test_tool_plugin_get_user_flags_invalid_level():
    """Test that we return an empty list for invalid levels."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources([os.path.join(os.path.dirname(__file__), 'user_flags_config')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    flags = tp.get_user_flags('level2', name='test')
    assert flags == []
示例#3
0
def test_tool_dependencies():
    """Verify that dependencies are reported correctly."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources(
        [os.path.join(os.path.dirname(__file__), "user_flags_config")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    assert tp.get_tool_dependencies() == []
示例#4
0
def test_resources_get_file_exists():
    """
    Test get_file where the file exists.

    Expected results: The file path is returned
    """
    with TemporaryDirectory() as tmp_dir:
        resources = Resources([tmp_dir])
        os.mkdir(os.path.join(tmp_dir, 'rsc'))
        with tempfile.NamedTemporaryFile(dir=os.path.join(tmp_dir, 'rsc')) as tmpfile:
            assert resources.get_file(tmpfile.name) == os.path.join(tmp_dir, 'rsc', tmpfile.name)
示例#5
0
def test_tool_plugin_get_user_flags_valid_flags():
    """Test that we return a list of user flags."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources(
        [os.path.join(os.path.dirname(__file__), "user_flags_config")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    flags = tp.get_user_flags("level", name="test")
    assert flags == ["look", "a", "flag"]
def setup_yamllint_tool_plugin():
    """Construct and return an instance of the YAMLLint plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_true", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    yltp = YamllintToolPlugin()
    yltp.set_plugin_context(plugin_context)
    return yltp
示例#7
0
def setup_pydocstyle_tool_plugin():
    """Initialize and return a PyCodeStyle plugin."""
    arg_parser = argparse.ArgumentParser()

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    pdstp = PydocstyleToolPlugin()
    pdstp.set_plugin_context(plugin_context)
    return pdstp
def setup_cpplint_tool_plugin():
    """Initialize and return an instance of the cpplint plugin."""
    arg_parser = argparse.ArgumentParser()

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")]
    )
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    ctp = CpplintToolPlugin()
    ctp.set_plugin_context(plugin_context)
    return ctp
示例#9
0
def setup_json_reporting_plugin(file_path, use_plugin_context=True):
    """Create an instance of the file writer plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("output_directory")

    resources = Resources([os.path.join(os.path.dirname(__file__), "config")])
    config = Config(resources.get_file("config.yaml"))
    jrp = JsonReportingPlugin()
    if use_plugin_context:
        plugin_context = PluginContext(arg_parser.parse_args([file_path]),
                                       resources, config)
        jrp.set_plugin_context(plugin_context)
    return jrp
示例#10
0
def setup_mypy_tool_plugin():
    """Create and return an instance of the Mypy plugin."""
    arg_parser = argparse.ArgumentParser()

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")]
    )
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    mtp = MypyToolPlugin()
    mtp.set_plugin_context(plugin_context)
    return mtp
示例#11
0
def setup_jshint_tool_plugin():
    """Initialize and return an instance of the jshint plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__), 'plugins'),
                           os.path.join(os.path.dirname(__file__), 'valid_package')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin = JSHintToolPlugin()
    plugin.set_plugin_context(plugin_context)
    return plugin
示例#12
0
def setup_cmake_discovery_plugin():
    """Create an instance of the CMake discovery plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    cmdp = CMakeDiscoveryPlugin()
    cmdp.set_plugin_context(plugin_context)
    return cmdp
示例#13
0
def setup_json_reporting_plugin():
    """Create an instance of the xmllint plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("output_directory")
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_true", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([os.getcwd()]), resources, config)
    jrarp = JSONRiskAssessmentReportingPlugin()
    jrarp.set_plugin_context(plugin_context)
    return jrarp
示例#14
0
def setup_pyflakes_tool_plugin():
    """Initialize and return a Pyflakes plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    pftp = PyflakesToolPlugin()
    pftp.set_plugin_context(plugin_context)
    return pftp
示例#15
0
def setup_cmake_discovery_plugin(add_plugin_context=True, cmake_flags=""):
    """Create an instance of the CMake discovery plugin."""
    arg_parser = argparse.ArgumentParser()

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    cmdp = CMakeDiscoveryPlugin()
    if add_plugin_context:
        plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                       config)
        plugin_context.args.output_directory = os.path.dirname(__file__)
        plugin_context.args.cmake_flags = cmake_flags
        cmdp.set_plugin_context(plugin_context)
    return cmdp
示例#16
0
def setup_write_jenkins_warnings_ng_reporting_plugin(file_path,
                                                     use_plugin_context=True):
    """Create an instance of the file writer plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("output_directory")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    wfrp = WriteJenkinsWarningsNGReportingPlugin()
    if use_plugin_context:
        plugin_context = PluginContext(arg_parser.parse_args([file_path]),
                                       resources, config)
        wfrp.set_plugin_context(plugin_context)
    return wfrp
示例#17
0
def setup_spotbugs_tool_plugin():
    """Initialize and return a spotbugs plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str)

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    sbtp = SpotbugsToolPlugin()
    sbtp.set_plugin_context(plugin_context)
    return sbtp
示例#18
0
def setup_shellcheck_tool_plugin(binary=None):
    """Construct and return an instance of the Shellcheck plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--shellcheck-bin", dest="shellcheck_bin")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    sctp = ShellcheckToolPlugin()
    if binary:
        plugin_context.args.shellcheck_bin = binary
    sctp.set_plugin_context(plugin_context)
    return sctp
示例#19
0
def setup_make_tool_plugin():
    """Construct and return an instance of the Make plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--mapping-file-suffix",
                            dest="mapping_file_suffix",
                            type=str)

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    mtp = MakeToolPlugin()
    mtp.set_plugin_context(plugin_context)
    return mtp
def setup_pycodestyle_tool_plugin():
    """Create and return an instance of the PyCodeStyle plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output",
                            dest="show_tool_output",
                            action="store_true",
                            help="Show tool output")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), 'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    pcstp = PycodestyleToolPlugin()
    pcstp.set_plugin_context(plugin_context)
    return pcstp
示例#21
0
def setup_lizard_tool_plugin(custom_rsc_path=None):
    """Initialize and return an instance of the lizard plugin."""
    arg_parser = argparse.ArgumentParser()

    if custom_rsc_path is not None:
        resources = Resources([custom_rsc_path])
    else:
        resources = Resources(
            [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    ltp = LizardToolPlugin()
    ltp.set_plugin_context(plugin_context)
    return ltp
def setup_flawfinder_tool_plugin():
    """Initialize and return an instance of the flawfinder plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--flawfinder-bin", dest="flawfinder_bin")
    arg_parser.add_argument("--mapping-file-suffix",
                            dest="mapping_file_suffix",
                            type=str)

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    fftp = FlawfinderToolPlugin()
    fftp.set_plugin_context(plugin_context)
    return fftp
示例#23
0
def setup_write_jenkins_warnings_reporting_plugin(file_path):
    """Create an instance of the file writer plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("output_directory")
    arg_parser.add_argument("--show-tool-output",
                            dest="show_tool_output",
                            action="store_false",
                            help="Show tool output")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), 'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([file_path]),
                                   resources, config)
    wfrp = WriteJenkinsWarningsReportingPlugin()
    wfrp.set_plugin_context(plugin_context)
    return wfrp
def setup_clang_format_tool_plugin(use_plugin_context=True,
                                   binary=None,
                                   do_raise=False,
                                   issue_per_line=False):
    """Initialize and return an instance of the clang-format plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--clang-format-bin", dest="clang_format_bin")
    if do_raise:
        arg_parser.add_argument(
            "--clang-format-raise-exception",
            dest="clang_format_raise_exception",
            action="store_false",
        )
    else:
        arg_parser.add_argument(
            "--clang-format-raise-exception",
            dest="clang_format_raise_exception",
            action="store_true",
        )

    if issue_per_line:
        arg_parser.add_argument(
            "--clang-format-issue-per-line",
            dest="clang_format_issue_per_line",
            action="store_false",
        )
    else:
        arg_parser.add_argument(
            "--clang-format-issue-per-line",
            dest="clang_format_issue_per_line",
            action="store_true",
        )

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    cftp = ClangFormatToolPlugin()
    if binary is not None:
        plugin_context.args.clang_format_bin = binary
    if use_plugin_context:
        cftp.set_plugin_context(plugin_context)
    return cftp
示例#25
0
def setup_clang_format_tool_plugin_non_default():
    """Initialize and return an instance of the clang-format plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")
    arg_parser.add_argument("--clang-format-bin", dest="clang_format_bin")
    arg_parser.add_argument("--clang-format-raise-exception",
                            dest="clang_format_raise_exception",
                            action="store_true", default=False)
    arg_parser.add_argument("--output-directory", dest="output_directory")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    cftp = ClangFormatToolPlugin()
    cftp.set_plugin_context(plugin_context)
    return cftp
def setup_chktex_tool_plugin():
    """Initialize and return an instance of the chktex plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument(
        "--show-tool-output",
        dest="show_tool_output",
        action="store_false",
        help="Show tool output",
    )

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")]
    )
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    ctp = ChktexToolPlugin()
    ctp.set_plugin_context(plugin_context)
    return ctp
示例#27
0
def setup_bandit_tool_plugin(binary=None):
    """Create an instance of the bandit plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--bandit-bin", dest="bandit_bin")
    arg_parser.add_argument(
        "--mapping-file-suffix", dest="mapping_file_suffix", type=str
    )

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")]
    )
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    btp = BanditToolPlugin()
    if binary:
        plugin_context.args.bandit_bin = binary
    btp.set_plugin_context(plugin_context)
    return btp
示例#28
0
def setup_uncrustify_tool_plugin(extra_path=None, use_plugin_context=True, binary=None):
    """Initialize and return an instance of the uncrustify plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--uncrustify-bin", dest="uncrustify_bin")

    paths = []
    if extra_path:
        paths.append(extra_path)
    paths.append(os.path.join(os.path.dirname(statick_tool.__file__), "plugins"))
    resources = Resources(paths)
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    utp = UncrustifyToolPlugin()
    if binary:
        plugin_context.args.uncrustify_bin = binary
    if use_plugin_context:
        utp.set_plugin_context(plugin_context)
    return utp
def setup_perlcritic_tool_plugin(binary=None):
    """Initialize and return a perlcritic plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--perlcritic-bin", dest="perlcritic_bin")
    arg_parser.add_argument("--mapping-file-suffix",
                            dest="mapping_file_suffix",
                            type=str)

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    pctp = PerlCriticToolPlugin()
    if binary:
        plugin_context.args.perlcritic_bin = binary
    pctp.set_plugin_context(plugin_context)
    return pctp
示例#30
0
def setup_xmllint_tool_plugin():
    """Create an instance of the xmllint plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument(
        "--show-tool-output",
        dest="show_tool_output",
        action="store_false",
        help="Show tool output",
    )

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    xltp = XmllintToolPlugin()
    xltp.set_plugin_context(plugin_context)
    return xltp