Let fake server tests override the default client exception handler

This can by done by adding an exception handler with `early=True'
in the `_start_client' method of a subclass of
`fake_server._FakeServerTest'.
This commit is contained in:
joo 2020-12-04 15:36:06 +01:00
parent 252e60a6e2
commit 7693961fb9
2 changed files with 12 additions and 10 deletions

View File

@ -541,21 +541,23 @@ class _FakeServerTest(unittest.TestCase):
client_lock = threading.Lock()
client_exc_info = [None]
client = connection_type(
addr, port, username='TestUser', allowed_versions=client_versions)
@client.exception_handler()
def handle_client_exception(exc, exc_info):
with client_lock:
client_exc_info[0] = exc_info
with cond:
cond.notify_all()
client = connection_type(
addr, port, username='TestUser', allowed_versions=client_versions,
handle_exception=handle_client_exception)
client.register_packet_listener(
lambda packet: logging.debug('[ ->C] %s' % packet),
packets.Packet, early=True)
client.register_packet_listener(
lambda packet: logging.debug('[C-> ] %s' % packet),
packets.Packet, early=True, outgoing=True)
@client.listener(packets.Packet, early=True)
def handle_incoming_packet(packet):
logging.debug('[ ->C] %s' % packet)
@client.listener(packets.Packet, early=True, outgoing=True)
def handle_outgoing_packet(packet):
logging.debug('[C-> ] %s' % packet)
server_thread = threading.Thread(
name='FakeServer',

View File

@ -352,7 +352,7 @@ class HandleExceptionTest(ConnectTest):
def handle_login_success(_packet):
raise Exception(message)
@client.exception_handler()
@client.exception_handler(early=True)
def handle_exception(exc, _exc_info):
assert isinstance(exc, Exception) and exc.args == (message,)
raise fake_server.FakeServerTestSuccess