mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-04 08:24:20 +02:00
parent
bff240032d
commit
b379a2a0c3
11 changed files with 224 additions and 2 deletions
37
tests/test_plugins.py
Normal file
37
tests/test_plugins.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from click.testing import CliRunner
|
||||
import click
|
||||
import importlib
|
||||
from sqlite_utils import cli, hookimpl, plugins
|
||||
|
||||
|
||||
def test_register_commands():
|
||||
importlib.reload(cli)
|
||||
assert plugins.get_plugins() == []
|
||||
|
||||
class HelloWorldPlugin:
|
||||
__name__ = "HelloWorldPlugin"
|
||||
|
||||
@hookimpl
|
||||
def register_commands(self, cli):
|
||||
@cli.command(name="hello-world")
|
||||
def hello_world():
|
||||
"Print hello world"
|
||||
click.echo("Hello world!")
|
||||
|
||||
try:
|
||||
plugins.pm.register(HelloWorldPlugin(), name="HelloWorldPlugin")
|
||||
importlib.reload(cli)
|
||||
|
||||
assert plugins.get_plugins() == [
|
||||
{"name": "HelloWorldPlugin", "hooks": ["register_commands"]}
|
||||
]
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli.cli, ["hello-world"])
|
||||
assert result.exit_code == 0
|
||||
assert result.output == "Hello world!\n"
|
||||
|
||||
finally:
|
||||
plugins.pm.unregister(name="HelloWorldPlugin")
|
||||
importlib.reload(cli)
|
||||
assert plugins.get_plugins() == []
|
||||
Loading…
Add table
Add a link
Reference in a new issue