diff --git a/tests/test_connection.py b/tests/test_connection.py index 326a133..0837aa5 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -31,6 +31,7 @@ ''' from __future__ import annotations +import copy from functools import partial, wraps import re import ssl @@ -1205,3 +1206,16 @@ async def server(): async with trio.open_nursery() as nursery: nursery.start_soon(server) nursery.start_soon(client) + + +def test_copy_exceptions(): + # test that exceptions are copy- and pickleable + copy.copy(HandshakeError()) + copy.copy(ConnectionTimeout()) + copy.copy(DisconnectionTimeout()) + assert copy.copy(ConnectionClosed("foo")).reason == "foo" + + rej_copy = copy.copy(ConnectionRejected(404, (("a", "b"),), b"c")) + assert rej_copy.status_code == 404 + assert rej_copy.headers == (("a", "b"),) + assert rej_copy.body == b"c" diff --git a/trio_websocket/_impl.py b/trio_websocket/_impl.py index 62c7ff7..5f3a9d4 100644 --- a/trio_websocket/_impl.py +++ b/trio_websocket/_impl.py @@ -608,7 +608,7 @@ def __init__(self, reason): :param reason: :type reason: CloseReason ''' - super().__init__() + super().__init__(reason) self.reason = reason def __repr__(self): @@ -628,7 +628,7 @@ def __init__(self, status_code, headers, body): :param reason: :type reason: CloseReason ''' - super().__init__() + super().__init__(status_code, headers, body) #: a 3 digit HTTP status code self.status_code = status_code #: a tuple of 2-tuples containing header key/value pairs