bpo-23819: Get rid of assert statements in test_asyncio (GH-30212) (GH-30213)

To keep checks even if run tests with optimized Python.

Either use special assertion methods like assertEqual() or
raise an AssertionError explicitly.
(cherry picked from commit 6ca78affc8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2021-12-20 04:50:45 -08:00 committed by GitHub
parent 0c0bd78ccf
commit 95948169d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 102 additions and 63 deletions

View file

@ -36,25 +36,29 @@ def __init__(self, loop=None, close_after=0):
self.data = bytearray()
self.close_after = close_after
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)
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)
def data_received(self, data):
assert self.state == 'CONNECTED', self.state
self._assert_state('CONNECTED')
self.nbytes += len(data)
self.data.extend(data)
super().data_received(data)