Skip to content
Prev Previous commit
Next Next commit
fully remove old OPSPlugin from tests
  • Loading branch information
dwhswenson committed Jul 25, 2021
commit f7d923a9a876fe6dfc95b0e0954928207f5e6a2d
5 changes: 0 additions & 5 deletions paths_cli/plugin_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import importlib
import os

# TODO: this should be removed
OPSPlugin = collections.namedtuple(
"OPSPlugin", ['name', 'location', 'func', 'section', 'plugin_type']
)

class PluginRegistrationError(RuntimeError):
pass

Expand Down
16 changes: 8 additions & 8 deletions paths_cli/tests/null_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import click

from paths_cli.plugin_management import FilePluginLoader, OPSPlugin
from paths_cli.plugin_management import FilePluginLoader, OPSCommandPlugin

@click.command(
'null-command',
Expand All @@ -11,17 +11,17 @@ def null_command():
logger = logging.getLogger(__name__)
logger.info("Running null command")

CLI = null_command
SECTION = "Workflow"
PLUGIN = OPSCommandPlugin(
command=null_command,
section="Workflow"
)

class NullCommandContext(object):
"""Context that registers/deregisters the null command (for tests)"""
def __init__(self, cli):
self.plugin = OPSPlugin(name="null-command",
location=__file__,
func=CLI,
section=SECTION,
plugin_type="file")
self.plugin = PLUGIN
self.plugin.attach_metadata(location=__file__,
plugin_type='file')

cli._register_plugin(self.plugin)
self.cli = cli
Expand Down
35 changes: 22 additions & 13 deletions paths_cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,40 @@
from click.testing import CliRunner

from paths_cli.cli import *
from paths_cli.plugin_management import OPSPlugin
# from paths_cli.plugin_management import OPSPlugin
from .null_command import NullCommandContext


class TestOpenPathSamplingCLI(object):
def setup(self):
def make_mock(name, helpless=False):
mock = MagicMock(return_value=name)
def make_mock(name, helpless=False, return_val=None):
if return_val is None:
return_val = name
mock = MagicMock(return_value=return_val)
mock.name = name
if helpless:
mock.short_help = None
else:
mock.short_help = name + " help"
return mock

foo_plugin = OPSCommandPlugin(
command=make_mock('foo'),
section="Simulation"
)
foo_plugin.attach_metadata(location="foo.py",
plugin_type='file')
foobar_plugin = OPSCommandPlugin(
command=make_mock('foo-bar', helpless=True,
return_val='foobar'),
section="Miscellaneous"
)
foobar_plugin.attach_metadata(location='foo_bar.py',
plugin_type='file')

self.plugin_dict = {
'foo': OPSPlugin(name='foo',
location='foo.py',
func=make_mock('foo'),
section='Simulation',
plugin_type='file'),
'foo-bar': OPSPlugin(name='foo-bar',
location='foo_bar.py',
func=make_mock('foobar', helpless=True),
section='Miscellaneous',
plugin_type="file")
'foo': foo_plugin,
'foo-bar': foobar_plugin,
}
self.plugins = list(self.plugin_dict.values())
self.cli = OpenPathSamplingCLI()
Expand Down