Skip to content

Commit ae9f847

Browse files
committed
deprecation
1 parent 3c48bf7 commit ae9f847

4 files changed

Lines changed: 38 additions & 31 deletions

File tree

tests/interop/__init__.py

Whitespace-only changes.

tests/interop/test_calls.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from tests import aiotest
66
from functools import partial
77
import sys
8+
from .. import utils
89

910

1011
class Seen:
@@ -306,7 +307,8 @@ async def dly_asyncio():
306307
await asyncio.sleep(0.01, loop=loop)
307308
yield 2
308309

309-
res = await async_gen_to_list(loop.wrap_generator(dly_asyncio))
310+
with utils.deprecate(self):
311+
res = await async_gen_to_list(loop.wrap_generator(dly_asyncio))
310312
assert res == [1, 2]
311313

312314
@pytest.mark.trio
@@ -316,8 +318,9 @@ async def dly_asyncio():
316318
raise RuntimeError("I has an owie")
317319
yield 2
318320

319-
with pytest.raises(RuntimeError) as err:
320-
await async_gen_to_list(loop.wrap_generator(dly_asyncio))
321+
with utils.deprecate(self):
322+
with pytest.raises(RuntimeError) as err:
323+
await async_gen_to_list(loop.wrap_generator(dly_asyncio))
321324
assert err.value.args[0] == "I has an owie"
322325

323326
@pytest.mark.trio
@@ -334,9 +337,10 @@ async def cancel_soon(nursery):
334337
hold = asyncio.Event(loop=loop)
335338
seen = Seen()
336339

337-
async with trio.open_nursery() as nursery:
338-
nursery.start_soon(async_gen_to_list, loop.wrap_generator(dly_asyncio, hold, seen))
339-
nursery.start_soon(cancel_soon, nursery)
340+
with utils.deprecate(self):
341+
async with trio.open_nursery() as nursery:
342+
nursery.start_soon(async_gen_to_list, loop.wrap_generator(dly_asyncio, hold, seen))
343+
nursery.start_soon(cancel_soon, nursery)
340344
assert nursery.cancel_scope.cancel_called
341345
assert seen.flag == 1
342346

tests/python/test_locks.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,6 @@
1616
)
1717
RGX_REPR = re.compile(STR_RGX_REPR)
1818

19-
if sys.version_info >= (3, 7):
20-
21-
def deprecate(self):
22-
return self.assertWarns(DeprecationWarning)
23-
24-
else:
25-
26-
class deprecate:
27-
def __init__(self, tc):
28-
pass
29-
30-
def __enter__(self):
31-
return self
32-
33-
def __exit__(self, *tb):
34-
pass
35-
36-
3719
class LockTests(test_utils.TestCase):
3820
def setUp(self):
3921
super().setUp()
@@ -59,7 +41,7 @@ def test_repr(self):
5941

6042
@asyncio.coroutine
6143
def acquire_lock():
62-
with deprecate(self):
44+
with test_utils.deprecate(self, (3, 7)):
6345
yield from lock
6446

6547
self.loop.run_until_complete(acquire_lock())
@@ -71,7 +53,7 @@ def test_lock(self):
7153

7254
@asyncio.coroutine
7355
def acquire_lock():
74-
with deprecate(self):
56+
with test_utils.deprecate(self, (3, 7)):
7557
return (yield from lock)
7658

7759
res = self.loop.run_until_complete(acquire_lock())
@@ -230,7 +212,7 @@ def test_context_manager(self):
230212

231213
@asyncio.coroutine
232214
def acquire_lock():
233-
with deprecate(self):
215+
with test_utils.deprecate(self, (3, 7)):
234216
return (yield from lock)
235217

236218
with self.loop.run_until_complete(acquire_lock()):
@@ -243,7 +225,7 @@ def test_context_manager_cant_reuse(self):
243225

244226
@asyncio.coroutine
245227
def acquire_lock():
246-
with deprecate(self):
228+
with test_utils.deprecate(self, (3, 7)):
247229
return (yield from lock)
248230

249231
# This spells "yield from lock" outside a generator.
@@ -675,7 +657,7 @@ def test_context_manager(self):
675657

676658
@asyncio.coroutine
677659
def acquire_cond():
678-
with deprecate(self):
660+
with test_utils.deprecate(self, (3, 7)):
679661
return (yield from cond)
680662

681663
with self.loop.run_until_complete(acquire_cond()):
@@ -759,7 +741,7 @@ def test_semaphore(self):
759741

760742
@asyncio.coroutine
761743
def acquire_lock():
762-
with deprecate(self):
744+
with test_utils.deprecate(self, (3, 7)):
763745
return (yield from sem)
764746

765747
res = self.loop.run_until_complete(acquire_lock())
@@ -899,7 +881,7 @@ def test_context_manager(self):
899881

900882
@asyncio.coroutine
901883
def acquire_lock():
902-
with deprecate(self):
884+
with test_utils.deprecate(self, (3, 7)):
903885
return (yield from sem)
904886

905887
with self.loop.run_until_complete(acquire_lock()):

tests/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import time
1616
import unittest
1717
import weakref
18+
import pytest
1819

1920
from unittest import mock
2021

@@ -580,3 +581,23 @@ def get_function_source(func):
580581
if source is None:
581582
raise ValueError("unable to get the source of %r" % (func,))
582583
return source
584+
585+
586+
587+
def deprecate(tc, vers=None):
588+
if vers is None or sys.version_info >= vers:
589+
return pytest.deprecated_call()
590+
591+
class _deprecate:
592+
def __init__(self, tc):
593+
pass
594+
595+
def __enter__(self):
596+
return self
597+
598+
def __exit__(self, *tb):
599+
pass
600+
601+
return _deprecate(tc)
602+
603+

0 commit comments

Comments
 (0)