forked from goodboy/tractor
Fix `test_basic_payload_spec` bad msg matching
Expecting `Started` or `Return` with respective bad `.pld` values depending on what type of failure is test parametrized. This makes the suite run green it seems B)runtime_to_msgspec
parent
7ac730e326
commit
f7fd8278af
|
@ -6,30 +6,19 @@ related settings around IPC contexts.
|
||||||
'''
|
'''
|
||||||
from contextlib import (
|
from contextlib import (
|
||||||
asynccontextmanager as acm,
|
asynccontextmanager as acm,
|
||||||
contextmanager as cm,
|
|
||||||
)
|
|
||||||
# import typing
|
|
||||||
from typing import (
|
|
||||||
# Any,
|
|
||||||
TypeAlias,
|
|
||||||
# Union,
|
|
||||||
)
|
)
|
||||||
from contextvars import (
|
from contextvars import (
|
||||||
Context,
|
Context,
|
||||||
)
|
)
|
||||||
|
|
||||||
from msgspec import (
|
from msgspec import (
|
||||||
# structs,
|
|
||||||
# msgpack,
|
|
||||||
Struct,
|
Struct,
|
||||||
# ValidationError,
|
|
||||||
)
|
)
|
||||||
import pytest
|
import pytest
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
import tractor
|
import tractor
|
||||||
from tractor import (
|
from tractor import (
|
||||||
# _state,
|
|
||||||
MsgTypeError,
|
MsgTypeError,
|
||||||
current_ipc_ctx,
|
current_ipc_ctx,
|
||||||
Portal,
|
Portal,
|
||||||
|
@ -40,20 +29,9 @@ from tractor.msg import (
|
||||||
)
|
)
|
||||||
from tractor.msg import (
|
from tractor.msg import (
|
||||||
_codec,
|
_codec,
|
||||||
# _ctxvar_MsgCodec,
|
|
||||||
|
|
||||||
# NamespacePath,
|
|
||||||
# MsgCodec,
|
|
||||||
# mk_codec,
|
|
||||||
# apply_codec,
|
|
||||||
# current_codec,
|
|
||||||
)
|
)
|
||||||
from tractor.msg.types import (
|
from tractor.msg.types import (
|
||||||
log,
|
log,
|
||||||
# _payload_msgs,
|
|
||||||
# PayloadMsg,
|
|
||||||
# Started,
|
|
||||||
# mk_msg_spec,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,23 +42,10 @@ class PldMsg(Struct):
|
||||||
maybe_msg_spec = PldMsg|None
|
maybe_msg_spec = PldMsg|None
|
||||||
|
|
||||||
|
|
||||||
@cm
|
|
||||||
def custom_spec(
|
|
||||||
ctx: Context,
|
|
||||||
spec: TypeAlias,
|
|
||||||
) -> _codec.MsgCodec:
|
|
||||||
'''
|
|
||||||
Apply a custom payload spec, remove on exit.
|
|
||||||
|
|
||||||
'''
|
|
||||||
rx: msgops.PldRx = ctx._pld_rx
|
|
||||||
|
|
||||||
|
|
||||||
@acm
|
@acm
|
||||||
async def maybe_expect_raises(
|
async def maybe_expect_raises(
|
||||||
raises: BaseException|None = None,
|
raises: BaseException|None = None,
|
||||||
ensure_in_message: list[str]|None = None,
|
ensure_in_message: list[str]|None = None,
|
||||||
|
|
||||||
reraise: bool = False,
|
reraise: bool = False,
|
||||||
timeout: int = 3,
|
timeout: int = 3,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -271,6 +236,17 @@ def test_basic_payload_spec(
|
||||||
# since not opened yet.
|
# since not opened yet.
|
||||||
assert current_ipc_ctx() is None
|
assert current_ipc_ctx() is None
|
||||||
|
|
||||||
|
if invalid_started:
|
||||||
|
msg_type_str: str = 'Started'
|
||||||
|
bad_value_str: str = '10'
|
||||||
|
elif invalid_return:
|
||||||
|
msg_type_str: str = 'Return'
|
||||||
|
bad_value_str: str = "'yo'"
|
||||||
|
else:
|
||||||
|
# XXX but should never be used below then..
|
||||||
|
msg_type_str: str = ''
|
||||||
|
bad_value_str: str = ''
|
||||||
|
|
||||||
async with (
|
async with (
|
||||||
maybe_expect_raises(
|
maybe_expect_raises(
|
||||||
raises=MsgTypeError if (
|
raises=MsgTypeError if (
|
||||||
|
@ -279,8 +255,8 @@ def test_basic_payload_spec(
|
||||||
invalid_started
|
invalid_started
|
||||||
) else None,
|
) else None,
|
||||||
ensure_in_message=[
|
ensure_in_message=[
|
||||||
"invalid `Return` payload",
|
f"invalid `{msg_type_str}` payload",
|
||||||
"value: `'yo'` does not match type-spec: `Return.pld: PldMsg|NoneType`",
|
f"value: `{bad_value_str}` does not match type-spec: `{msg_type_str}.pld: PldMsg|NoneType`",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
p.open_context(
|
p.open_context(
|
||||||
|
|
Loading…
Reference in New Issue