summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_sock_lowlevel.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_asyncio/test_sock_lowlevel.py')
-rw-r--r--Lib/test/test_asyncio/test_sock_lowlevel.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/test/test_asyncio/test_sock_lowlevel.py b/Lib/test/test_asyncio/test_sock_lowlevel.py
index d8a5df8..ab022a3 100644
--- a/Lib/test/test_asyncio/test_sock_lowlevel.py
+++ b/Lib/test/test_asyncio/test_sock_lowlevel.py
@@ -23,24 +23,28 @@ class MyProto(asyncio.Protocol):
self.connected = loop.create_future()
self.done = loop.create_future()
+ def _assert_state(self, *expected):
+ if self.state not in expected:
+ raise AssertionError(f'state: {self.state!r}, expected: {expected!r}')
+
def connection_made(self, transport):
self.transport = transport
- assert self.state == 'INITIAL', self.state
+ self._assert_state('INITIAL')
self.state = 'CONNECTED'
if self.connected:
self.connected.set_result(None)
transport.write(b'GET / HTTP/1.0\r\nHost: example.com\r\n\r\n')
def data_received(self, data):
- assert self.state == 'CONNECTED', self.state
+ self._assert_state('CONNECTED')
self.nbytes += len(data)
def eof_received(self):
- assert self.state == 'CONNECTED', self.state
+ self._assert_state('CONNECTED')
self.state = 'EOF'
def connection_lost(self, exc):
- assert self.state in ('CONNECTED', 'EOF'), self.state
+ self._assert_state('CONNECTED', 'EOF')
self.state = 'CLOSED'
if self.done:
self.done.set_result(None)
@@ -451,7 +455,7 @@ class BaseSockTestsMixin:
else:
break
else:
- assert False, 'Can not create socket.'
+ self.fail('Can not create socket.')
f = self.loop.create_connection(
lambda: MyProto(loop=self.loop), sock=sock)