diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-04-24 07:23:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-24 07:23:59 (GMT) |
commit | 090721721b373c50544d297b56c217cf15992cbe (patch) | |
tree | eac831fb9a94fa4fec902c6dda217c60abfcc38d /Lib/test/test_asyncio | |
parent | b4e048411f4c62ad7343bca32c307f0bf5ef74b4 (diff) | |
download | cpython-090721721b373c50544d297b56c217cf15992cbe.zip cpython-090721721b373c50544d297b56c217cf15992cbe.tar.gz cpython-090721721b373c50544d297b56c217cf15992cbe.tar.bz2 |
Simplify testing the warning filename (GH-91868)
The context manager result has the "filename" attribute.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r-- | Lib/test/test_asyncio/test_events.py | 16 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_futures.py | 8 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_streams.py | 8 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 18 |
4 files changed, 25 insertions, 25 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index a30867e..05d9107 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -2712,12 +2712,12 @@ class GetEventLoopTestsMixin: with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(TestError): asyncio.get_event_loop() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) asyncio.set_event_loop(None) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(TestError): asyncio.get_event_loop() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) with self.assertRaisesRegex(RuntimeError, 'no running'): asyncio.get_running_loop() @@ -2734,13 +2734,13 @@ class GetEventLoopTestsMixin: with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(TestError): asyncio.get_event_loop() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) asyncio.set_event_loop(None) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(TestError): asyncio.get_event_loop() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) finally: asyncio.set_event_loop_policy(old_policy) @@ -2762,12 +2762,12 @@ class GetEventLoopTestsMixin: with self.assertWarns(DeprecationWarning) as cm: loop2 = asyncio.get_event_loop() self.addCleanup(loop2.close) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) asyncio.set_event_loop(None) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'no current'): asyncio.get_event_loop() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) with self.assertRaisesRegex(RuntimeError, 'no running'): asyncio.get_running_loop() @@ -2783,13 +2783,13 @@ class GetEventLoopTestsMixin: asyncio.set_event_loop(loop) with self.assertWarns(DeprecationWarning) as cm: self.assertIs(asyncio.get_event_loop(), loop) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) asyncio.set_event_loop(None) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'no current'): asyncio.get_event_loop() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) finally: asyncio.set_event_loop_policy(old_policy) diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py index cf677f6..f4a46ec 100644 --- a/Lib/test/test_asyncio/test_futures.py +++ b/Lib/test/test_asyncio/test_futures.py @@ -148,7 +148,7 @@ class BaseFutureTests: with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'There is no current event loop'): self._new_future() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) def test_constructor_use_running_loop(self): async def test(): @@ -163,7 +163,7 @@ class BaseFutureTests: self.addCleanup(asyncio.set_event_loop, None) with self.assertWarns(DeprecationWarning) as cm: f = self._new_future() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) self.assertIs(f._loop, self.loop) self.assertIs(f.get_loop(), self.loop) @@ -510,7 +510,7 @@ class BaseFutureTests: with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(RuntimeError): asyncio.wrap_future(f1) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) ex.shutdown(wait=True) def test_wrap_future_use_running_loop(self): @@ -534,7 +534,7 @@ class BaseFutureTests: f1 = ex.submit(run, 'oi') with self.assertWarns(DeprecationWarning) as cm: f2 = asyncio.wrap_future(f1) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) self.assertIs(self.loop, f2._loop) ex.shutdown(wait=True) diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index a7d1789..098a0da 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -813,7 +813,7 @@ os.close(fd) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'There is no current event loop'): asyncio.StreamReader() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) def test_streamreader_constructor_use_running_loop(self): # asyncio issue #184: Ensure that StreamReaderProtocol constructor @@ -832,7 +832,7 @@ os.close(fd) asyncio.set_event_loop(self.loop) with self.assertWarns(DeprecationWarning) as cm: reader = asyncio.StreamReader() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) self.assertIs(reader._loop, self.loop) @@ -841,7 +841,7 @@ os.close(fd) with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'There is no current event loop'): asyncio.StreamReaderProtocol(reader) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) def test_streamreaderprotocol_constructor_use_running_loop(self): # asyncio issue #184: Ensure that StreamReaderProtocol constructor @@ -861,7 +861,7 @@ os.close(fd) reader = mock.Mock() with self.assertWarns(DeprecationWarning) as cm: protocol = asyncio.StreamReaderProtocol(reader) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) self.assertIs(protocol._loop, self.loop) def test_drain_raises(self): diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 80afb27..6458859 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -211,7 +211,7 @@ class BaseTaskTests: with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'There is no current event loop'): asyncio.ensure_future(a) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) async def test(): return asyncio.ensure_future(notmuch()) @@ -226,7 +226,7 @@ class BaseTaskTests: self.addCleanup(asyncio.set_event_loop, None) with self.assertWarns(DeprecationWarning) as cm: t = asyncio.ensure_future(notmuch()) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) self.assertIs(t._loop, self.loop) self.loop.run_until_complete(t) self.assertTrue(t.done()) @@ -1449,7 +1449,7 @@ class BaseTaskTests: with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'There is no current event loop'): list(futs) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) def test_as_completed_coroutine_use_running_loop(self): loop = self.new_test_loop() @@ -1881,7 +1881,7 @@ class BaseTaskTests: with self.assertWarns(DeprecationWarning) as cm: with self.assertRaisesRegex(RuntimeError, 'There is no current event loop'): asyncio.shield(inner) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) def test_shield_coroutine_use_running_loop(self): async def coro(): @@ -1903,7 +1903,7 @@ class BaseTaskTests: self.addCleanup(asyncio.set_event_loop, None) with self.assertWarns(DeprecationWarning) as cm: outer = asyncio.shield(coro()) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) self.assertEqual(outer._loop, self.loop) res = self.loop.run_until_complete(outer) self.assertEqual(res, 42) @@ -2911,7 +2911,7 @@ class FutureGatherTests(GatherTestsBase, test_utils.TestCase): with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(RuntimeError): asyncio.gather() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) def test_constructor_empty_sequence_use_running_loop(self): async def gather(): @@ -2929,7 +2929,7 @@ class FutureGatherTests(GatherTestsBase, test_utils.TestCase): self.addCleanup(asyncio.set_event_loop, None) with self.assertWarns(DeprecationWarning) as cm: fut = asyncio.gather() - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) self.assertIsInstance(fut, asyncio.Future) self.assertIs(fut._loop, self.one_loop) self._run_loop(self.one_loop) @@ -3020,7 +3020,7 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase): with self.assertWarns(DeprecationWarning) as cm: with self.assertRaises(RuntimeError): asyncio.gather(gen1, gen2) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) def test_constructor_use_running_loop(self): async def coro(): @@ -3043,7 +3043,7 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase): gen2 = coro() with self.assertWarns(DeprecationWarning) as cm: fut = asyncio.gather(gen1, gen2) - self.assertEqual(cm.warnings[0].filename, __file__) + self.assertEqual(cm.filename, __file__) self.assertIs(fut._loop, self.other_loop) self.other_loop.run_until_complete(fut) |