mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
asyncio: Fix unix pipe transport 'repr' methods
Patch by Vincent Michel. See also https://github.com/python/asyncio/pull/326
This commit is contained in:
parent
32dae3d50f
commit
5dc093336f
2 changed files with 45 additions and 4 deletions
|
@ -1366,6 +1366,41 @@ class EventLoopTestsMixin:
|
|||
# extra info is available
|
||||
self.assertIsNotNone(proto.transport.get_extra_info('pipe'))
|
||||
|
||||
@unittest.skipUnless(sys.platform != 'win32',
|
||||
"Don't support pipes for Windows")
|
||||
def test_unclosed_pipe_transport(self):
|
||||
# This test reproduces the issue #314 on GitHub
|
||||
loop = self.create_event_loop()
|
||||
read_proto = MyReadPipeProto(loop=loop)
|
||||
write_proto = MyWritePipeProto(loop=loop)
|
||||
|
||||
rpipe, wpipe = os.pipe()
|
||||
rpipeobj = io.open(rpipe, 'rb', 1024)
|
||||
wpipeobj = io.open(wpipe, 'w', 1024)
|
||||
|
||||
@asyncio.coroutine
|
||||
def connect():
|
||||
read_transport, _ = yield from loop.connect_read_pipe(
|
||||
lambda: read_proto, rpipeobj)
|
||||
write_transport, _ = yield from loop.connect_write_pipe(
|
||||
lambda: write_proto, wpipeobj)
|
||||
return read_transport, write_transport
|
||||
|
||||
# Run and close the loop without closing the transports
|
||||
read_transport, write_transport = loop.run_until_complete(connect())
|
||||
loop.close()
|
||||
|
||||
# These 'repr' calls used to raise an AttributeError
|
||||
# See Issue #314 on GitHub
|
||||
self.assertIn('open', repr(read_transport))
|
||||
self.assertIn('open', repr(write_transport))
|
||||
|
||||
# Clean up (avoid ResourceWarning)
|
||||
rpipeobj.close()
|
||||
wpipeobj.close()
|
||||
read_transport._pipe = None
|
||||
write_transport._pipe = None
|
||||
|
||||
@unittest.skipUnless(sys.platform != 'win32',
|
||||
"Don't support pipes for Windows")
|
||||
# select, poll and kqueue don't support character devices (PTY) on Mac OS X
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue