Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-35394: Add empty slots to abstract asyncio protocols #10889

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/asyncio/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class BaseProtocol:
write-only transport like write pipe
"""

__slots__ = ()

def connection_made(self, transport):
"""Called when a connection is made.

Expand Down Expand Up @@ -87,6 +89,8 @@ class Protocol(BaseProtocol):
* CL: connection_lost()
"""

__slots__ = ()

def data_received(self, data):
"""Called when some data is received.

Expand Down Expand Up @@ -130,6 +134,8 @@ class BufferedProtocol(BaseProtocol):
* CL: connection_lost()
"""

__slots__ = ()

def get_buffer(self, sizehint):
"""Called to allocate a new receive buffer.

Expand Down Expand Up @@ -160,6 +166,8 @@ def eof_received(self):
class DatagramProtocol(BaseProtocol):
"""Interface for datagram protocol."""

__slots__ = ()

def datagram_received(self, data, addr):
"""Called when some datagram is received."""

Expand All @@ -173,6 +181,8 @@ def error_received(self, exc):
class SubprocessProtocol(BaseProtocol):
"""Interface for protocol for subprocess calls."""

__slots__ = ()

def pipe_data_received(self, fd, data):
"""Called when the subprocess writes data into stdout/stderr pipe.

Expand Down
24 changes: 0 additions & 24 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2486,30 +2486,6 @@ async def inner():
loop.close()


class ProtocolsAbsTests(unittest.TestCase):

def test_empty(self):
f = mock.Mock()
p = asyncio.Protocol()
self.assertIsNone(p.connection_made(f))
self.assertIsNone(p.connection_lost(f))
self.assertIsNone(p.data_received(f))
self.assertIsNone(p.eof_received())

dp = asyncio.DatagramProtocol()
self.assertIsNone(dp.connection_made(f))
self.assertIsNone(dp.connection_lost(f))
self.assertIsNone(dp.error_received(f))
self.assertIsNone(dp.datagram_received(f, f))

sp = asyncio.SubprocessProtocol()
self.assertIsNone(sp.connection_made(f))
self.assertIsNone(sp.connection_lost(f))
self.assertIsNone(sp.pipe_data_received(1, f))
self.assertIsNone(sp.pipe_connection_lost(1, f))
self.assertIsNone(sp.process_exited())


class PolicyTests(unittest.TestCase):

def test_event_loop_policy(self):
Expand Down
57 changes: 57 additions & 0 deletions Lib/test/test_asyncio/test_protocols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import unittest
from unittest import mock

import asyncio


class ProtocolsAbsTests(unittest.TestCase):

def test_base_protocol(self):
f = mock.Mock()
p = asyncio.BaseProtocol()
self.assertIsNone(p.connection_made(f))
self.assertIsNone(p.connection_lost(f))
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertFalse(hasattr(p, '__dict__'))

def test_protocol(self):
f = mock.Mock()
p = asyncio.Protocol()
self.assertIsNone(p.connection_made(f))
self.assertIsNone(p.connection_lost(f))
self.assertIsNone(p.data_received(f))
self.assertIsNone(p.eof_received())
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertFalse(hasattr(p, '__dict__'))

def test_buffered_protocol(self):
f = mock.Mock()
p = asyncio.BufferedProtocol()
self.assertIsNone(p.connection_made(f))
self.assertIsNone(p.connection_lost(f))
self.assertIsNone(p.get_buffer(100))
self.assertIsNone(p.buffer_updated(150))
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertFalse(hasattr(p, '__dict__'))

def test_datagram_protocol(self):
f = mock.Mock()
dp = asyncio.DatagramProtocol()
self.assertIsNone(dp.connection_made(f))
self.assertIsNone(dp.connection_lost(f))
self.assertIsNone(dp.error_received(f))
self.assertIsNone(dp.datagram_received(f, f))
self.assertFalse(hasattr(dp, '__dict__'))

def test_subprocess_protocol(self):
f = mock.Mock()
sp = asyncio.SubprocessProtocol()
self.assertIsNone(sp.connection_made(f))
self.assertIsNone(sp.connection_lost(f))
self.assertIsNone(sp.pipe_data_received(1, f))
self.assertIsNone(sp.pipe_connection_lost(1, f))
self.assertIsNone(sp.process_exited())
self.assertFalse(hasattr(sp, '__dict__'))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add empty slots to asyncio abstract protocols.