Skip to content

Commit 9123c07

Browse files
remove simple test loop
1 parent caf3bbc commit 9123c07

File tree

3 files changed

+9
-39
lines changed

3 files changed

+9
-39
lines changed

unittests/test_functools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import asyncstdlib as a
66
from asyncstdlib.functools import CachedProperty
77

8-
from .utility import Lock, Schedule, Switch, asyncify, multi_sync, sync
8+
from .utility import Lock, Schedule, Switch, asyncify, sync
99

1010

1111
@sync
@@ -44,7 +44,7 @@ async def bar(self):
4444
Foo().bar
4545

4646

47-
@multi_sync
47+
@sync
4848
async def test_cache_property_order():
4949
class Value:
5050
def __init__(self, value):
@@ -66,7 +66,7 @@ async def check_increment(to):
6666
assert (await val.cached) == 1337 # last value fetched
6767

6868

69-
@multi_sync
69+
@sync
7070
async def test_cache_property_lock_order():
7171
class Value:
7272
def __init__(self, value):
@@ -87,7 +87,7 @@ async def check_cached(to, expected):
8787
assert (await val.cached) == 5 # first value fetched
8888

8989

90-
@multi_sync
90+
@sync
9191
async def test_cache_property_lock_deletion():
9292
class Value:
9393
def __init__(self, value):
@@ -300,7 +300,7 @@ async def pingpong(arg):
300300

301301

302302
@pytest.mark.parametrize("size", [16, None])
303-
@multi_sync
303+
@sync
304304
async def test_lru_cache_concurrent(size):
305305
current = 0
306306

unittests/test_itertools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import asyncstdlib as a
88

9-
from .utility import sync, asyncify, awaitify, multi_sync, Schedule, Switch, Lock
9+
from .utility import sync, asyncify, awaitify, Schedule, Switch, Lock
1010

1111

1212
@sync
@@ -314,7 +314,7 @@ async def test_tee():
314314
assert await a.list(iterator) == iterable
315315

316316

317-
@multi_sync
317+
@sync
318318
async def test_tee_concurrent_locked():
319319
"""Test that properly uses a lock for synchronisation"""
320320
items = [1, 2, 3, -5, 12, 78, -1, 111]
@@ -344,7 +344,7 @@ async def test_peer(peer_tee):
344344
platform.python_implementation() != "CPython",
345345
reason="async generators only protect against concurrent access on CPython",
346346
)
347-
@multi_sync
347+
@sync
348348
async def test_tee_concurrent_unlocked():
349349
"""Test that tee does not prevent concurrency without a lock"""
350350
items = list(range(12))

unittests/utility.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,6 @@ async def inside_loop() -> bool:
6464
return await signal is signal
6565

6666

67-
def sync(test_case: Callable[..., Coroutine[None, Any, Any]]) -> Callable[..., None]:
68-
"""
69-
Mark an ``async def`` test case to be run synchronously
70-
71-
This emulates a primitive "event loop" which only responds
72-
to the :py:class:`PingPong` by sending it back. This loop
73-
is appropriate for tests that do not check concurrency.
74-
"""
75-
76-
@wraps(test_case)
77-
def run_sync(*args: Any, **kwargs: Any) -> None:
78-
coro = test_case(*args, **kwargs)
79-
try:
80-
event = None
81-
while True:
82-
event = coro.send(event)
83-
if not isinstance(event, PingPong): # pragma: no cover
84-
raise RuntimeError(
85-
f"test case {test_case} yielded an unexpected event {event}"
86-
)
87-
except StopIteration as e:
88-
result = e.args[0] if e.args else None
89-
assert result is None, f"got '{result!r}' expected 'None'"
90-
return result
91-
92-
return run_sync
93-
94-
9567
class Schedule:
9668
r"""
9769
Signal to the event loop to adopt and run new coroutines
@@ -159,9 +131,7 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any):
159131
self._owned = False
160132

161133

162-
def multi_sync(
163-
test_case: Callable[..., Coroutine[None, Any, Any]], /
164-
) -> Callable[..., None]:
134+
def sync(test_case: Callable[..., Coroutine[None, Any, Any]], /) -> Callable[..., None]:
165135
"""
166136
Mark an ``async def`` test case to be run synchronously with children
167137

0 commit comments

Comments
 (0)