Simplify testing the warning filename (GH-91868)

The context manager result has the "filename" attribute.
This commit is contained in:
Serhiy Storchaka 2022-04-24 10:23:59 +03:00 committed by GitHub
parent b4e048411f
commit 090721721b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 43 deletions

View file

@ -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):