1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

🔧 Stuff is actually working now?!

This commit is contained in:
Steffo 2021-03-31 16:13:21 +02:00
parent 3f589cdbe7
commit 869e98e798
Signed by: steffo
GPG key ID: 6965406171929D01
4 changed files with 60 additions and 9 deletions

4
poetry.lock generated
View file

@ -284,7 +284,7 @@ description = "A multipurpose bot framework"
category = "main" category = "main"
optional = false optional = false
python-versions = "^3.8" python-versions = "^3.8"
develop = true develop = false
[package.dependencies] [package.dependencies]
async-property = "^0.2.1" async-property = "^0.2.1"
@ -483,7 +483,7 @@ brotli = ["brotlipy (>=0.6.0)"]
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = "^3.8" python-versions = "^3.8"
content-hash = "43ee92bfde25cfaf2a425e3369da281a5cc1288dd5b4ccdac2fa0b1d230cf2e7" content-hash = "899653d0350658ba17c1f8bb15f6ef73874325558ba67a2e191590869a24b4db"
[metadata.files] [metadata.files]
alabaster = [ alabaster = [

View file

@ -30,6 +30,11 @@ pytest-asyncio = "^0.14.0"
sphinx = "^3.3.1" sphinx = "^3.3.1"
sphinx_rtd_theme = "^0.5.0" sphinx_rtd_theme = "^0.5.0"
[tool.pytest.ini_options]
minversion = "6.0"
log_cli = true
log_cli_level = "DEBUG"
[build-system] [build-system]
requires = ["poetry>=0.12"] requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api" build-backend = "poetry.masonry.api"

View file

@ -15,6 +15,7 @@ import getpass
import psutil import psutil
import royalnet.engineer as engi import royalnet.engineer as engi
import click import click
import async_property as ap
# Special global objects # Special global objects
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -48,22 +49,23 @@ class ConsoleUser(engi.User):
def __hash__(self) -> int: def __hash__(self) -> int:
return os.getuid() return os.getuid()
@ap.async_property
async def name(self) -> str: async def name(self) -> str:
return getpass.getuser() return getpass.getuser()
async def send_message(self, *, async def slide(self) -> "engi.Channel":
text: str = None, return ConsoleChannel()
files: t.List[t.BinaryIO] = None) -> engi.Message:
return await console_message(text=text, files=files)
class ConsoleChannel(engi.Channel): class ConsoleChannel(engi.Channel):
def __hash__(self) -> int: def __hash__(self) -> int:
return os.getpid() return os.getpid()
@ap.async_property
async def name(self) -> str: async def name(self) -> str:
return psutil.Process(os.getpid()).name() return psutil.Process(os.getpid()).name()
@ap.async_property
async def users(self) -> t.List[engi.User]: async def users(self) -> t.List[engi.User]:
return [ConsoleUser()] return [ConsoleUser()]
@ -86,16 +88,19 @@ class ConsoleMessage(engi.Message):
def __hash__(self) -> int: def __hash__(self) -> int:
return self._instance_number return self._instance_number
@ap.async_property
async def text(self) -> str: async def text(self) -> str:
return self._text return self._text
@ap.async_property
async def timestamp(self) -> datetime.datetime: async def timestamp(self) -> datetime.datetime:
return self._timestamp return self._timestamp
@ap.async_property
async def channel(self) -> engi.Channel: async def channel(self) -> engi.Channel:
return ConsoleChannel() return ConsoleChannel()
async def send_reply(self, *, async def reply(self, *,
text: str = None, text: str = None,
files: t.List[t.BinaryIO] = None) -> engi.Message: files: t.List[t.BinaryIO] = None) -> engi.Message:
return await console_message(text=text, files=files) return await console_message(text=text, files=files)
@ -113,6 +118,7 @@ class ConsoleMessageReceived(engi.MessageReceived):
def __hash__(self): def __hash__(self):
return return
@ap.async_property
async def message(self) -> ConsoleMessage: async def message(self) -> ConsoleMessage:
return self._msg return self._msg

View file

@ -1,5 +1,6 @@
import pytest import pytest
from royalnet_console.pda import ConsolePDA from royalnet_console.pda import ConsolePDA
from royalnet.engineer import PartialCommand, Sentry, Message
def test_construction(): def test_construction():
@ -10,3 +11,42 @@ def test_construction():
@pytest.fixture @pytest.fixture
def pda(): def pda():
return ConsolePDA() 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