mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
🔧 Stuff is actually working now?!
This commit is contained in:
parent
3f589cdbe7
commit
869e98e798
4 changed files with 60 additions and 9 deletions
4
poetry.lock
generated
4
poetry.lock
generated
|
@ -284,7 +284,7 @@ description = "A multipurpose bot framework"
|
|||
category = "main"
|
||||
optional = false
|
||||
python-versions = "^3.8"
|
||||
develop = true
|
||||
develop = false
|
||||
|
||||
[package.dependencies]
|
||||
async-property = "^0.2.1"
|
||||
|
@ -483,7 +483,7 @@ brotli = ["brotlipy (>=0.6.0)"]
|
|||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.8"
|
||||
content-hash = "43ee92bfde25cfaf2a425e3369da281a5cc1288dd5b4ccdac2fa0b1d230cf2e7"
|
||||
content-hash = "899653d0350658ba17c1f8bb15f6ef73874325558ba67a2e191590869a24b4db"
|
||||
|
||||
[metadata.files]
|
||||
alabaster = [
|
||||
|
|
|
@ -30,6 +30,11 @@ pytest-asyncio = "^0.14.0"
|
|||
sphinx = "^3.3.1"
|
||||
sphinx_rtd_theme = "^0.5.0"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
minversion = "6.0"
|
||||
log_cli = true
|
||||
log_cli_level = "DEBUG"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry>=0.12"]
|
||||
build-backend = "poetry.masonry.api"
|
||||
|
|
|
@ -15,6 +15,7 @@ import getpass
|
|||
import psutil
|
||||
import royalnet.engineer as engi
|
||||
import click
|
||||
import async_property as ap
|
||||
|
||||
# Special global objects
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -48,22 +49,23 @@ class ConsoleUser(engi.User):
|
|||
def __hash__(self) -> int:
|
||||
return os.getuid()
|
||||
|
||||
@ap.async_property
|
||||
async def name(self) -> str:
|
||||
return getpass.getuser()
|
||||
|
||||
async def send_message(self, *,
|
||||
text: str = None,
|
||||
files: t.List[t.BinaryIO] = None) -> engi.Message:
|
||||
return await console_message(text=text, files=files)
|
||||
async def slide(self) -> "engi.Channel":
|
||||
return ConsoleChannel()
|
||||
|
||||
|
||||
class ConsoleChannel(engi.Channel):
|
||||
def __hash__(self) -> int:
|
||||
return os.getpid()
|
||||
|
||||
@ap.async_property
|
||||
async def name(self) -> str:
|
||||
return psutil.Process(os.getpid()).name()
|
||||
|
||||
@ap.async_property
|
||||
async def users(self) -> t.List[engi.User]:
|
||||
return [ConsoleUser()]
|
||||
|
||||
|
@ -86,18 +88,21 @@ class ConsoleMessage(engi.Message):
|
|||
def __hash__(self) -> int:
|
||||
return self._instance_number
|
||||
|
||||
@ap.async_property
|
||||
async def text(self) -> str:
|
||||
return self._text
|
||||
|
||||
@ap.async_property
|
||||
async def timestamp(self) -> datetime.datetime:
|
||||
return self._timestamp
|
||||
|
||||
@ap.async_property
|
||||
async def channel(self) -> engi.Channel:
|
||||
return ConsoleChannel()
|
||||
|
||||
async def send_reply(self, *,
|
||||
text: str = None,
|
||||
files: t.List[t.BinaryIO] = None) -> engi.Message:
|
||||
async def reply(self, *,
|
||||
text: str = None,
|
||||
files: t.List[t.BinaryIO] = None) -> engi.Message:
|
||||
return await console_message(text=text, files=files)
|
||||
|
||||
|
||||
|
@ -113,6 +118,7 @@ class ConsoleMessageReceived(engi.MessageReceived):
|
|||
def __hash__(self):
|
||||
return
|
||||
|
||||
@ap.async_property
|
||||
async def message(self) -> ConsoleMessage:
|
||||
return self._msg
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import pytest
|
||||
from royalnet_console.pda import ConsolePDA
|
||||
from royalnet.engineer import PartialCommand, Sentry, Message
|
||||
|
||||
|
||||
def test_construction():
|
||||
|
@ -10,3 +11,42 @@ def test_construction():
|
|||
@pytest.fixture
|
||||
def pda():
|
||||
return ConsolePDA()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def command():
|
||||
@PartialCommand.new(syntax="")
|
||||
async def test(*, _sentry: Sentry, _msg: Message, **__):
|
||||
"""
|
||||
Ah, non lo so io!
|
||||
"""
|
||||
await _msg.reply(text=r"test")
|
||||
|
||||
return test
|
||||
|
||||
|
||||
def test_registration(pda: ConsolePDA, command: PartialCommand):
|
||||
pda.register_partial(command, ["test"])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pda_with_command(pda: ConsolePDA, command: PartialCommand):
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue