Skip to content
Snippets Groups Projects
Commit 38a67d60 authored by inso's avatar inso
Browse files

Enhance exception catching + fix identities find

parent da29d706
No related branches found
No related tags found
No related merge requests found
...@@ -73,7 +73,7 @@ class IdentitiesRegistry: ...@@ -73,7 +73,7 @@ class IdentitiesRegistry:
except ClientError: except ClientError:
lookup_tries += 1 lookup_tries += 1
except NoPeerAvailable: except NoPeerAvailable:
pass return identity
if pubkey in self._instances: if pubkey in self._instances:
identity = self._instances[pubkey] identity = self._instances[pubkey]
...@@ -90,6 +90,7 @@ class IdentitiesRegistry: ...@@ -90,6 +90,7 @@ class IdentitiesRegistry:
except ValueError as e: except ValueError as e:
if '404' in str(e) or '400' in str(e): if '404' in str(e) or '400' in str(e):
yield from lookup() yield from lookup()
return identity
else: else:
tries += 1 tries += 1
except asyncio.TimeoutError: except asyncio.TimeoutError:
......
from .qapp import get_application from .qapp import get_application, unitttest_exception_handler
\ No newline at end of file \ No newline at end of file
...@@ -19,7 +19,7 @@ from cutecoin.core.app import Application ...@@ -19,7 +19,7 @@ from cutecoin.core.app import Application
from cutecoin.core import Account, Community, Wallet from cutecoin.core import Account, Community, Wallet
from cutecoin.core.net import Network, Node from cutecoin.core.net import Network, Node
from cutecoin.core.net.api.bma.access import BmaAccess from cutecoin.core.net.api.bma.access import BmaAccess
from cutecoin.tests import get_application from cutecoin.tests import get_application, unitttest_exception_handler
from ucoinpy.api import bma from ucoinpy.api import bma
...@@ -29,6 +29,7 @@ class TestCertificationDialog(unittest.TestCase): ...@@ -29,6 +29,7 @@ class TestCertificationDialog(unittest.TestCase):
QLocale.setDefault(QLocale("en_GB")) QLocale.setDefault(QLocale("en_GB"))
self.lp = quamash.QEventLoop(self.qapplication) self.lp = quamash.QEventLoop(self.qapplication)
asyncio.set_event_loop(self.lp) asyncio.set_event_loop(self.lp)
self.lp.set_exception_handler(lambda lp, ctx : unitttest_exception_handler(self, lp, ctx))
self.identities_registry = IdentitiesRegistry({}) self.identities_registry = IdentitiesRegistry({})
self.application = Application(self.qapplication, self.lp, self.identities_registry) self.application = Application(self.qapplication, self.lp, self.identities_registry)
......
...@@ -4,7 +4,6 @@ import asyncio ...@@ -4,7 +4,6 @@ import asyncio
import quamash import quamash
import logging import logging
import time import time
from ucoinpy.documents.peer import BMAEndpoint as PyBMAEndpoint
from PyQt5.QtWidgets import QDialog from PyQt5.QtWidgets import QDialog
from PyQt5.QtCore import QLocale, Qt, QPoint from PyQt5.QtCore import QLocale, Qt, QPoint
from PyQt5.QtTest import QTest from PyQt5.QtTest import QTest
...@@ -20,7 +19,7 @@ from cutecoin.core import Account, Community, Wallet ...@@ -20,7 +19,7 @@ from cutecoin.core import Account, Community, Wallet
from cutecoin.core.net import Network, Node from cutecoin.core.net import Network, Node
from ucoinpy.documents.peer import BMAEndpoint from ucoinpy.documents.peer import BMAEndpoint
from cutecoin.core.net.api.bma.access import BmaAccess from cutecoin.core.net.api.bma.access import BmaAccess
from cutecoin.tests import get_application from cutecoin.tests import get_application, unitttest_exception_handler
class TestIdentitiesTable(unittest.TestCase): class TestIdentitiesTable(unittest.TestCase):
...@@ -29,6 +28,7 @@ class TestIdentitiesTable(unittest.TestCase): ...@@ -29,6 +28,7 @@ class TestIdentitiesTable(unittest.TestCase):
QLocale.setDefault(QLocale("en_GB")) QLocale.setDefault(QLocale("en_GB"))
self.lp = quamash.QEventLoop(self.qapplication) self.lp = quamash.QEventLoop(self.qapplication)
asyncio.set_event_loop(self.lp) asyncio.set_event_loop(self.lp)
self.lp.set_exception_handler(lambda lp, ctx : unitttest_exception_handler(self, lp, ctx))
self.identities_registry = IdentitiesRegistry() self.identities_registry = IdentitiesRegistry()
self.application = Application(self.qapplication, self.lp, self.identities_registry) self.application = Application(self.qapplication, self.lp, self.identities_registry)
......
...@@ -15,7 +15,7 @@ from cutecoin.gui.process_cfg_community import ProcessConfigureCommunity ...@@ -15,7 +15,7 @@ from cutecoin.gui.process_cfg_community import ProcessConfigureCommunity
from cutecoin.gui.password_asker import PasswordAskerDialog from cutecoin.gui.password_asker import PasswordAskerDialog
from cutecoin.core.app import Application from cutecoin.core.app import Application
from cutecoin.core.account import Account from cutecoin.core.account import Account
from cutecoin.tests import get_application from cutecoin.tests import get_application, unitttest_exception_handler
class ProcessAddCommunity(unittest.TestCase): class ProcessAddCommunity(unittest.TestCase):
...@@ -24,6 +24,7 @@ class ProcessAddCommunity(unittest.TestCase): ...@@ -24,6 +24,7 @@ class ProcessAddCommunity(unittest.TestCase):
QLocale.setDefault(QLocale("en_GB")) QLocale.setDefault(QLocale("en_GB"))
self.lp = quamash.QEventLoop(self.qapplication) self.lp = quamash.QEventLoop(self.qapplication)
asyncio.set_event_loop(self.lp) asyncio.set_event_loop(self.lp)
self.lp.set_exception_handler(lambda lp, ctx : unitttest_exception_handler(self, lp, ctx))
self.identities_registry = IdentitiesRegistry({}) self.identities_registry = IdentitiesRegistry({})
self.application = Application(self.qapplication, self.lp, self.identities_registry) self.application = Application(self.qapplication, self.lp, self.identities_registry)
......
...@@ -19,7 +19,7 @@ from cutecoin.core import Account, Community, Wallet ...@@ -19,7 +19,7 @@ from cutecoin.core import Account, Community, Wallet
from cutecoin.core.net import Network, Node from cutecoin.core.net import Network, Node
from ucoinpy.documents.peer import BMAEndpoint from ucoinpy.documents.peer import BMAEndpoint
from cutecoin.core.net.api.bma.access import BmaAccess from cutecoin.core.net.api.bma.access import BmaAccess
from cutecoin.tests import get_application from cutecoin.tests import get_application, unitttest_exception_handler
from ucoinpy.api import bma from ucoinpy.api import bma
...@@ -29,6 +29,7 @@ class TestTransferDialog(unittest.TestCase): ...@@ -29,6 +29,7 @@ class TestTransferDialog(unittest.TestCase):
QLocale.setDefault(QLocale("en_GB")) QLocale.setDefault(QLocale("en_GB"))
self.lp = quamash.QEventLoop(self.qapplication) self.lp = quamash.QEventLoop(self.qapplication)
asyncio.set_event_loop(self.lp) asyncio.set_event_loop(self.lp)
self.lp.set_exception_handler(lambda lp, ctx : unitttest_exception_handler(self, lp, ctx))
self.identities_registry = IdentitiesRegistry({}) self.identities_registry = IdentitiesRegistry({})
self.application = Application(self.qapplication, self.lp, self.identities_registry) self.application = Application(self.qapplication, self.lp, self.identities_registry)
......
...@@ -19,7 +19,7 @@ from cutecoin.core.app import Application ...@@ -19,7 +19,7 @@ from cutecoin.core.app import Application
from cutecoin.core import Account, Community, Wallet from cutecoin.core import Account, Community, Wallet
from cutecoin.core.net import Network, Node from cutecoin.core.net import Network, Node
from cutecoin.core.net.api.bma.access import BmaAccess from cutecoin.core.net.api.bma.access import BmaAccess
from cutecoin.tests import get_application from cutecoin.tests import get_application, unitttest_exception_handler
class TestIdentitiesTable(unittest.TestCase): class TestIdentitiesTable(unittest.TestCase):
...@@ -28,6 +28,7 @@ class TestIdentitiesTable(unittest.TestCase): ...@@ -28,6 +28,7 @@ class TestIdentitiesTable(unittest.TestCase):
QLocale.setDefault(QLocale("en_GB")) QLocale.setDefault(QLocale("en_GB"))
self.lp = quamash.QEventLoop(self.qapplication) self.lp = quamash.QEventLoop(self.qapplication)
asyncio.set_event_loop(self.lp) asyncio.set_event_loop(self.lp)
self.lp.set_exception_handler(lambda lp, ctx : unitttest_exception_handler(self, lp, ctx))
self.identities_registry = IdentitiesRegistry() self.identities_registry = IdentitiesRegistry()
self.application = Application(self.qapplication, self.lp, self.identities_registry) self.application = Application(self.qapplication, self.lp, self.identities_registry)
......
...@@ -2,6 +2,32 @@ ...@@ -2,6 +2,32 @@
_application_ = [] _application_ = []
def unitttest_exception_handler(test, loop, context):
"""
An exception handler which exists the program if the exception
was not catch
:param loop: the asyncio loop
:param context: the exception context
"""
message = context.get('message')
if not message:
message = 'Unhandled exception in event loop'
try:
exception = context['exception']
except KeyError:
exc_info = False
else:
exc_info = (type(exception), exception, exception.__traceback__)
log_lines = [message]
for key in [k for k in sorted(context) if k not in {'message', 'exception'}]:
log_lines.append('{}: {!r}'.format(key, context[key]))
test.failureException('\n'.join(log_lines))
def get_application(): def get_application():
"""Get the singleton QApplication""" """Get the singleton QApplication"""
from quamash import QApplication from quamash import QApplication
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment