mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-11 11:04:10 +02:00
parent
bff240032d
commit
b379a2a0c3
11 changed files with 224 additions and 2 deletions
|
|
@ -8,6 +8,12 @@ create table Gosh2 (c1 text, c2 text, c3 text);
|
|||
"""
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
import sys
|
||||
|
||||
sys._called_from_test = True
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fresh_db():
|
||||
return Database(memory=True)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ recipes_re = re.compile(r"r\.(\w+)\(")
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def documented_commands():
|
||||
rst = (docs_path / "cli.rst").read_text()
|
||||
rst = ""
|
||||
for doc in ("cli.rst", "plugins.rst"):
|
||||
rst += (docs_path / doc).read_text()
|
||||
return {
|
||||
command
|
||||
for command in commands_re.findall(rst)
|
||||
|
|
|
|||
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