Skip to content

Commit 002555a

Browse files
committed
fix up tests
1 parent 4ebfc42 commit 002555a

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

‎paths_cli/cli.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# import click_completion
1414
# click_completion.init()
1515

16-
from .plugin_management import FilePluginLoader, NamespacePluginLoader
16+
from .plugin_management import (FilePluginLoader, NamespacePluginLoader,
17+
OPSCommandPlugin)
1718

1819
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
1920

@@ -31,10 +32,10 @@ def app_dir_plugins(posix):
3132
).resolve() / 'cli-plugins')
3233

3334
self.plugin_loaders = [
34-
FilePluginLoader(commands),
35-
FilePluginLoader(app_dir_plugins(posix=False)),
36-
FilePluginLoader(app_dir_plugins(posix=True)),
37-
NamespacePluginLoader('paths_cli_plugins')
35+
FilePluginLoader(commands, OPSCommandPlugin),
36+
FilePluginLoader(app_dir_plugins(posix=False), OPSCommandPlugin),
37+
FilePluginLoader(app_dir_plugins(posix=True), OPSCommandPlugin),
38+
NamespacePluginLoader('paths_cli_plugins', OPSCommandPlugin)
3839
]
3940

4041
plugins = sum([loader() for loader in self.plugin_loaders], [])

‎paths_cli/plugin_management.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ class FilePluginLoader(CLIPluginLoader):
161161
search_path : str
162162
path to the directory that contains plugins (OS-dependent format)
163163
"""
164-
def __init__(self, search_path):
165-
super().__init__(plugin_type="file", search_path=search_path)
164+
def __init__(self, search_path, plugin_class):
165+
super().__init__(plugin_type="file", search_path=search_path,
166+
plugin_class=plugin_class)
166167

167168
def _find_candidates(self):
168169
def is_plugin(filename):
@@ -202,8 +203,9 @@ class NamespacePluginLoader(CLIPluginLoader):
202203
search_path : str
203204
namespace (dot-separated) where plugins can be found
204205
"""
205-
def __init__(self, search_path):
206-
super().__init__(plugin_type="namespace", search_path=search_path)
206+
def __init__(self, search_path, plugin_class):
207+
super().__init__(plugin_type="namespace", search_path=search_path,
208+
plugin_class=plugin_class)
207209

208210
def _find_candidates(self):
209211
# based on https://packaging.python.org/guides/creating-and-discovering-plugins/#using-namespace-packages

‎paths_cli/tests/test_plugin_management.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def test_find_candidates(self, command):
6161
def test_make_nsdict(self, command):
6262
candidate = self._make_candidate(command)
6363
nsdict = self.loader._make_nsdict(candidate)
64-
assert nsdict['SECTION'] == self.expected_section[command]
65-
assert isinstance(nsdict['CLI'], click.Command)
64+
plugin = nsdict['PLUGIN']
65+
assert plugin.section == self.expected_section[command]
66+
assert isinstance(plugin.command, click.Command)
6667

6768
@pytest.mark.parametrize('command', ['pathsampling', 'contents'])
6869
def test_call(self, command):
@@ -82,7 +83,7 @@ def setup(self):
8283
# use our own commands dir as a file-based plugin
8384
cmds_init = pathlib.Path(paths_cli.commands.__file__).resolve()
8485
self.commands_dir = cmds_init.parent
85-
self.loader = FilePluginLoader(self.commands_dir)
86+
self.loader = FilePluginLoader(self.commands_dir, OPSCommandPlugin)
8687
self.plugin_type = 'file'
8788

8889
def _make_candidate(self, command):
@@ -99,15 +100,15 @@ class TestNamespacePluginLoader(PluginLoaderTest):
99100
def setup(self):
100101
super().setup()
101102
self.namespace = "paths_cli.commands"
102-
self.loader = NamespacePluginLoader(self.namespace)
103+
self.loader = NamespacePluginLoader(self.namespace, OPSCommandPlugin)
103104
self.plugin_type = 'namespace'
104105

105106
def _make_candidate(self, command):
106107
name = self.namespace + "." + command
107108
return importlib.import_module(name)
108109

109110
def test_get_command_name(self):
110-
loader = NamespacePluginLoader('foo.bar')
111+
loader = NamespacePluginLoader('foo.bar', OPSCommandPlugin)
111112
candidate = MagicMock(__name__="foo.bar.baz_qux")
112113
expected = "baz-qux"
113114
assert loader._get_command_name(candidate) == expected

0 commit comments

Comments
 (0)