-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By default auto discover files of any type, and run any applicable to…
- Loading branch information
Showing
12 changed files
with
285 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Do nothing, this is primarily useful for testing purposes.""" | ||
from typing import List, Optional | ||
|
||
from statick_tool.issue import Issue | ||
from statick_tool.package import Package | ||
from statick_tool.tool_plugin import ToolPlugin | ||
|
||
|
||
class DoNothingToolPlugin(ToolPlugin): | ||
"""Do nothing, this is primarily useful for testing purposes.""" | ||
|
||
def get_name(self) -> str: | ||
"""Get name of tool.""" | ||
return "do_nothing" | ||
|
||
def get_file_types(self) -> List[str]: | ||
"""Return a list of file types the plugin can scan.""" | ||
return [] | ||
|
||
def process_files( | ||
self, package: Package, level: str, files: List[str], user_flags: List[str] | ||
) -> Optional[List[str]]: | ||
"""Run tool and gather output.""" | ||
return [] | ||
|
||
def parse_output( | ||
self, total_output: List[str], package: Optional[Package] = None | ||
) -> List[Issue]: | ||
"""Parse tool output and report issues.""" | ||
return [] |
3 changes: 3 additions & 0 deletions
3
statick_tool/plugins/tool/do_nothing_tool_plugin.yapsy-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[Core] | ||
Name = Do Nothing Tool Plugin | ||
Module = do_nothing_tool_plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
levels: | ||
discovery_only: | ||
reporting: | ||
print_to_console: | ||
tool: | ||
do_nothing: | ||
|
||
sei_cert: | ||
reporting: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
default: sei_cert | ||
default: default | ||
|
||
packages: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
tests/plugins/tool/do_nothing_tool_plugin/test_do_nothing_tool_plugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""Unit tests for the do nothing tool plugin.""" | ||
import os | ||
|
||
from yapsy.PluginManager import PluginManager | ||
|
||
import statick_tool | ||
from statick_tool.package import Package | ||
from statick_tool.plugins.tool.do_nothing_tool_plugin import DoNothingToolPlugin | ||
from statick_tool.tool_plugin import ToolPlugin | ||
|
||
|
||
def setup_do_nothing_tool_plugin(): | ||
"""Create and return an instance of the do nothing plugin.""" | ||
plugin = DoNothingToolPlugin() | ||
return plugin | ||
|
||
|
||
def test_do_nothing_tool_plugin_found(): | ||
"""Test that the plugin manager finds the do nothing tool plugin.""" | ||
manager = PluginManager() | ||
# Get the path to statick_tool/__init__.py, get the directory part, and | ||
# add 'plugins' to that to get the standard plugins dir | ||
manager.setPluginPlaces( | ||
[os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] | ||
) | ||
manager.setCategoriesFilter( | ||
{ | ||
"Tool": ToolPlugin, | ||
} | ||
) | ||
manager.collectPlugins() | ||
assert any( | ||
plugin_info.plugin_object.get_name() == "do_nothing" | ||
for plugin_info in manager.getPluginsOfCategory("Tool") | ||
) | ||
assert any( | ||
plugin_info.name == "Do Nothing Tool Plugin" | ||
for plugin_info in manager.getPluginsOfCategory("Tool") | ||
) | ||
|
||
|
||
def test_do_nothing_tool_plugin_get_file_types(): | ||
"""Integration test: Make sure the do_nothing output hasn't changed.""" | ||
plugin = setup_do_nothing_tool_plugin() | ||
assert not plugin.get_file_types() | ||
|
||
|
||
def test_do_nothing_tool_plugin_process_files(): | ||
"""Integration test: Make sure the do_nothing output hasn't changed.""" | ||
plugin = setup_do_nothing_tool_plugin() | ||
package = Package( | ||
"valid_package", os.path.join(os.path.dirname(__file__), "valid_package") | ||
) | ||
package["python_src"] = [ | ||
os.path.join(os.path.dirname(__file__), "valid_package", "basic.py") | ||
] | ||
output = plugin.process_files(package, "level", package["python_src"], []) | ||
assert not output | ||
|
||
|
||
def test_do_nothing_tool_plugin_parse_output(): | ||
"""Verify that we can parse the normal output of do_nothing.""" | ||
plugin = setup_do_nothing_tool_plugin() | ||
output = "would reformat /home/user/valid_package/basic.py" | ||
issues = plugin.parse_output([output]) | ||
assert not issues |
1 change: 1 addition & 0 deletions
1
tests/plugins/tool/do_nothing_tool_plugin/valid_package/basic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import subprocess # NOQA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ levels: | |
custom: | ||
discovery: | ||
- cmake | ||
tool: | ||
- do_nothing |
Oops, something went wrong.