1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/royalnet_console/tests/test_pda.py

50 lines
1 KiB
Python
Raw Normal View History

2021-03-31 03:01:40 +00:00
import pytest
from royalnet_console.pda import ConsolePDA
2021-03-31 21:49:01 +00:00
import royalnet.engineer as engi
2021-03-31 03:01:40 +00:00
def test_construction():
pda = ConsolePDA()
assert pda is not None
@pytest.fixture
def pda():
return ConsolePDA()
2021-03-31 14:13:21 +00:00
@pytest.fixture
def command():
2021-03-31 21:49:01 +00:00
@engi.PartialCommand.new(syntax="")
async def test(*, _sentry: engi.Sentry, _msg: engi.Message, **__):
2021-03-31 14:13:21 +00:00
await _msg.reply(text=r"test")
return test
2021-03-31 21:49:01 +00:00
def test_registration(pda: ConsolePDA, command: engi.PartialCommand):
2021-03-31 14:13:21 +00:00
pda.register_partial(command, ["test"])
@pytest.fixture
2021-03-31 21:49:01 +00:00
def pda_with_command(pda: ConsolePDA, command: engi.PartialCommand):
2021-03-31 14:13:21 +00:00
pda.register_partial(command, ["test"])
return pda
@pytest.mark.asyncio
async def test_run(pda_with_command: ConsolePDA, monkeypatch):
check = False
def trigger(text):
assert text == "test"
nonlocal check
check = True
monkeypatch.setattr("click.prompt", lambda *_, **__: "test")
monkeypatch.setattr("click.echo", trigger)
await pda_with_command.run(cycles=1)
assert check is True