Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add function plugin concept and decorator
- Loading branch information
Showing
7 changed files
with
150 additions
and
13 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,10 @@ | ||
import pytest | ||
|
||
from plugin.discovery import ModuleScanningPluginFinder | ||
from tests.plugins import sample_plugins | ||
|
||
|
||
@pytest.fixture | ||
def sample_plugin_finder(): | ||
finder = ModuleScanningPluginFinder(modules=[sample_plugins]) | ||
yield finder |
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,22 @@ | ||
from plugin import PluginManager | ||
|
||
|
||
def test_load_functional_plugins(sample_plugin_finder): | ||
manager = PluginManager("namespace_3", finder=sample_plugin_finder) | ||
|
||
plugins = manager.load_all() | ||
assert len(plugins) == 2 | ||
|
||
assert plugins[0].name in ["plugin_3", "plugin_4"] | ||
assert plugins[1].name in ["plugin_3", "plugin_4"] | ||
|
||
if plugins[0].name == "plugin_3": | ||
plugin_3 = plugins[0] | ||
plugin_4 = plugins[1] | ||
else: | ||
plugin_3 = plugins[1] | ||
plugin_4 = plugins[0] | ||
|
||
# function plugins are callable directly | ||
assert plugin_3() == "foobar" | ||
assert plugin_4() == "another" |