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

Fix the string representation of ServerDisconnectedError #4188

Merged
merged 2 commits into from
Oct 17, 2019
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
1 change: 1 addition & 0 deletions CHANGES/4175.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the string representation of `ServerDisconnectedError`.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Jake Davis
Jakob Ackermann
Jakub Wilk
Jashandeep Sohi
Jens Steinhauser
Jeongkyu Shin
Jeroen van der Heijden
Jesus Cea
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ class ServerDisconnectedError(ServerConnectionError):
"""Server disconnected."""

def __init__(self, message: Optional[str]=None) -> None:
self.message = message
if message is None:
self.args = ()
else:
self.args = (message,)
message = 'Server disconnected'

self.args = (message,)
self.message = message


class ServerTimeoutError(ServerConnectionError, asyncio.TimeoutError):
Expand Down
11 changes: 8 additions & 3 deletions tests/test_client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_str(self) -> None:
class TestServerDisconnectedError:
def test_ctor(self) -> None:
err = client.ServerDisconnectedError()
assert err.message is None
assert err.message == 'Server disconnected'

err = client.ServerDisconnectedError(message='No connection')
assert err.message == 'No connection'
Expand All @@ -194,7 +194,12 @@ def test_pickle(self) -> None:

def test_repr(self) -> None:
err = client.ServerDisconnectedError()
assert repr(err) == "ServerDisconnectedError()"
if sys.version_info < (3, 7):
assert repr(err) == ("ServerDisconnectedError"
"('Server disconnected',)")
else:
assert repr(err) == ("ServerDisconnectedError"
"('Server disconnected')")

err = client.ServerDisconnectedError(message='No connection')
if sys.version_info < (3, 7):
Expand All @@ -204,7 +209,7 @@ def test_repr(self) -> None:

def test_str(self) -> None:
err = client.ServerDisconnectedError()
assert str(err) == ''
assert str(err) == 'Server disconnected'

err = client.ServerDisconnectedError(message='No connection')
assert str(err) == 'No connection'
Expand Down
4 changes: 3 additions & 1 deletion tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2680,10 +2680,12 @@ async def handler(request):
app.router.add_get('/', handler)

client = await aiohttp_client(app)
with pytest.raises(aiohttp.ServerDisconnectedError):
with pytest.raises(aiohttp.ServerDisconnectedError) as excinfo:
resp = await client.get('/')
await resp.read()

assert str(excinfo.value) != ''


async def test_dont_close_explicit_connector(aiohttp_client) -> None:
async def handler(request):
Expand Down