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_lock = threading.Lock()
client_exc_info = [None] 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): def handle_client_exception(exc, exc_info):
with client_lock: with client_lock:
client_exc_info[0] = exc_info client_exc_info[0] = exc_info
with cond: with cond:
cond.notify_all() cond.notify_all()
client = connection_type( @client.listener(packets.Packet, early=True)
addr, port, username='TestUser', allowed_versions=client_versions, def handle_incoming_packet(packet):
handle_exception=handle_client_exception) logging.debug('[ ->C] %s' % packet)
client.register_packet_listener(
lambda packet: logging.debug('[ ->C] %s' % packet), @client.listener(packets.Packet, early=True, outgoing=True)
packets.Packet, early=True) def handle_outgoing_packet(packet):
client.register_packet_listener( logging.debug('[C-> ] %s' % packet)
lambda packet: logging.debug('[C-> ] %s' % packet),
packets.Packet, early=True, outgoing=True)
server_thread = threading.Thread( server_thread = threading.Thread(
name='FakeServer', name='FakeServer',

View File

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