Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 7010883

Browse files
authored
Merge pull request #33 from dbluhm/tests/static-connection
Fix errors in send_and_await_reply
2 parents 04136e6 + 81bcfbd commit 7010883

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

aries_staticagent/static_connection.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def pack(
217217
def next(
218218
self,
219219
type_: str = None,
220-
cond: Callable[[Message], bool] = None):
220+
condition: Callable[[Message], bool] = None):
221221
"""
222222
Context manager to claim the next message matching condtion, allowing
223223
temporary bypass of regular dispatch.
@@ -226,28 +226,28 @@ def next(
226226
to consume more than one or two, consider using a standard message
227227
handler or overriding the default dispatching mechanism.
228228
"""
229-
if cond and type_:
229+
if condition and type_:
230230
raise ValueError('Expected type or condtion, not both.')
231-
if cond and not callable(cond):
232-
raise TypeError('cond must be Callable[[Message], bool]')
231+
if condition and not callable(condition):
232+
raise TypeError('condition must be Callable[[Message], bool]')
233233

234-
if not cond and not type_:
234+
if not condition and not type_:
235235
# Collect everything
236236
def _default(_msg):
237237
return True
238-
cond = _default
238+
condition = _default
239239

240240
if type_:
241241
def _matches_type(msg):
242242
return msg.type == type_
243-
cond = _matches_type
243+
condition = _matches_type
244244

245245
next_message = asyncio.Future()
246-
self._next[cond] = next_message
246+
self._next[condition] = next_message
247247

248248
yield next_message
249249

250-
del self._next[cond]
250+
del self._next[condition]
251251

252252
async def handle(self, packed_message: bytes):
253253
"""Unpack and dispatch message to handler."""
@@ -317,14 +317,15 @@ async def send_and_await_reply_async(
317317
self,
318318
msg: Union[dict, Message],
319319
*,
320+
type_: str = None,
320321
condition: Callable[[Message], bool] = None,
321322
return_route: str = "all",
322323
plaintext: bool = False,
323324
anoncrypt: bool = False,
324325
timeout: int = None) -> Message:
325326
"""Send a message and wait for a reply."""
326327

327-
with self.next(condition) as next_message:
328+
with self.next(type_=type_, condition=condition) as next_message:
328329
await self.send_async(
329330
msg,
330331
return_route=return_route,
@@ -347,7 +348,7 @@ async def await_message(
347348
as a result of an action taken prior to calling await_message, use the
348349
`next` context manager instead.
349350
"""
350-
with self.next(type_, cond=condition) as next_message:
351+
with self.next(type_, condition=condition) as next_message:
351352
return await asyncio.wait_for(next_message, timeout)
352353

353354
def send(self, *args, **kwargs):

tests/test_send.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ async def test_claim_next_messages(alice_gen, bob, dispatcher):
207207
async def test_next_raises_error_on_bad_condition(alice):
208208
"""Bad condition raises error."""
209209
with pytest.raises(TypeError):
210-
with alice.next(cond='asdf'):
210+
with alice.next(condition='asdf'):
211211
pass
212212

213213

@@ -216,7 +216,7 @@ async def test_next_condition(alice_gen, bob, dispatcher):
216216
"""Test hold condtions."""
217217
alice = alice_gen(dispatcher=dispatcher)
218218
with alice.next(
219-
cond=lambda msg: msg.type == MESSAGE.type
219+
condition=lambda msg: msg.type == MESSAGE.type
220220
) as message:
221221
await alice.handle(bob.pack(MESSAGE))
222222
assert dispatcher.dispatched is None

0 commit comments

Comments
 (0)