mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 03:24:20 +00:00
⚗️ Fix the tests, even if i have no idea of how or why
This commit is contained in:
parent
b8705c59cd
commit
d6ad1301cb
4 changed files with 31 additions and 20 deletions
|
@ -63,7 +63,7 @@ class Blueprint(metaclass=abc.ABCMeta):
|
|||
.. code-block::
|
||||
|
||||
def print_msg(message: Message):
|
||||
message.requires(Message.text, Message.timestamp)
|
||||
message.requires("text", "timestamp")
|
||||
print(f"{message.timestamp().isoformat()}: {message.text()}")
|
||||
|
||||
:raises .exc.NeverAvailableError: If at least one of the fields raised a :exc:`.exc.NeverAvailableError`.
|
||||
|
@ -75,7 +75,7 @@ class Blueprint(metaclass=abc.ABCMeta):
|
|||
|
||||
for field in fields:
|
||||
try:
|
||||
field(self)
|
||||
self.__getattribute__(field)()
|
||||
except exc.NeverAvailableError as ex:
|
||||
exceptions.append(ex)
|
||||
except exc.NotAvailableError as ex:
|
||||
|
|
|
@ -8,7 +8,7 @@ from royalnet.royaltyping import *
|
|||
import functools
|
||||
import logging
|
||||
|
||||
from engineer import exc, blueprints
|
||||
from .. import exc, blueprints
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -155,7 +155,7 @@ class Filter:
|
|||
- the :class:`.blueprints.Blueprint` never has data for at least one of the fields,
|
||||
:exc:`.exc.NotAvailableError` is propagated upwards.
|
||||
|
||||
:param fields: The fields to test for.
|
||||
:param fields: The fields to test for, as strings.
|
||||
:param propagate_not_available: If :exc:`.exc.NotAvailableError` should be propagated
|
||||
instead of discarding the errored object.
|
||||
:param propagate_never_available: If :exc:`.exc.NeverAvailableError` should be propagated
|
||||
|
@ -166,11 +166,11 @@ class Filter:
|
|||
try:
|
||||
return obj.requires(*fields)
|
||||
except exc.NotAvailableError:
|
||||
if not propagate_not_available:
|
||||
if propagate_not_available:
|
||||
raise
|
||||
raise exc.Discard(obj, "Data is not available")
|
||||
except exc.NeverAvailableError:
|
||||
if not propagate_never_available:
|
||||
if propagate_never_available:
|
||||
raise
|
||||
raise exc.Discard(obj, "Data is never available")
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import pytest
|
|||
import asyncio
|
||||
import async_timeout
|
||||
import re
|
||||
from .. import sentry, exc, blueprints
|
||||
from royalnet.engineer import sentry, exc, blueprints
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -82,6 +82,7 @@ class TestFilter:
|
|||
async def test_filter(self, s: sentry.Sentry):
|
||||
await s.queue.put(None)
|
||||
await s.queue.put(None)
|
||||
await s.queue.put(None)
|
||||
|
||||
assert await s.f().filter(lambda x: x is None, "Is not None").get_single() is None
|
||||
|
||||
|
@ -147,28 +148,24 @@ class TestFilter:
|
|||
return 3
|
||||
|
||||
avmsg = AvailableMessage()
|
||||
namsg = NotAvailableMessage()
|
||||
nvmsg = NeverAvailableMessage()
|
||||
|
||||
await s.queue.put(avmsg)
|
||||
await s.queue.put(namsg)
|
||||
await s.queue.put(nvmsg)
|
||||
await s.queue.put(namsg)
|
||||
await s.queue.put(nvmsg)
|
||||
|
||||
assert await s.f().requires(blueprints.Message.text).get_single() is avmsg
|
||||
assert await s.f().requires("text").get_single() is avmsg
|
||||
|
||||
await s.queue.put(NotAvailableMessage())
|
||||
with pytest.raises(exc.Discard):
|
||||
await s.f().requires(blueprints.Message.text).get_single()
|
||||
await s.f().requires("text").get_single()
|
||||
|
||||
await s.queue.put(NeverAvailableMessage())
|
||||
with pytest.raises(exc.NeverAvailableError):
|
||||
await s.f().requires(blueprints.Message.text).get_single()
|
||||
await s.f().requires("text").get_single()
|
||||
|
||||
await s.queue.put(NotAvailableMessage())
|
||||
with pytest.raises(exc.NotAvailableError):
|
||||
await s.f().requires(blueprints.Message.text, propagate_not_available=True).get_single()
|
||||
await s.f().requires("text", propagate_not_available=True).get_single()
|
||||
|
||||
await s.queue.put(NeverAvailableMessage())
|
||||
with pytest.raises(exc.Discard):
|
||||
await s.f().requires(blueprints.Message.text, propagate_never_available=False).get_single()
|
||||
await s.f().requires("text", propagate_never_available=False).get_single()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_startswith(self, s: sentry.Sentry):
|
||||
|
|
14
royalnet/tests/test_pytest.py
Normal file
14
royalnet/tests/test_pytest.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import asyncio
|
||||
import pytest
|
||||
|
||||
|
||||
async def sleep_and_raise():
|
||||
await asyncio.sleep(0.001)
|
||||
raise Exception("Please except this gift!")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestAsyncio:
|
||||
async def test_exception(self):
|
||||
with pytest.raises(Exception):
|
||||
await sleep_and_raise()
|
Loading…
Reference in a new issue