Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2023-05-28 22:56:00 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-05-28 22:56:00 +0300
commit84f80b2a1dcb664d58938027926a73ed90460f5a (patch)
tree7a9f96cb844eba14a0521dea288e91cb860c8738
parent84742678227a6153120393366bca6af67f09ac25 (diff)
new: Tests: Add decorator to catch all exceptions
-rw-r--r--test/lib/util.py27
-rw-r--r--test/unit/test_http.py3
2 files changed, 29 insertions, 1 deletions
diff --git a/test/lib/util.py b/test/lib/util.py
index 2bb3b26..18f27e6 100644
--- a/test/lib/util.py
+++ b/test/lib/util.py
@@ -1,3 +1,4 @@
+import sys
import unittest
from unittest.mock import Mock
@@ -18,3 +19,29 @@ class StanzaHandlerTest(unittest.TestCase):
self.dispatcher.reset_parser()
self.dispatcher.process_data(STREAM_START)
+
+
+def raise_all_exceptions(func):
+ # Exceptions which are raised from async callbacks
+ # in GLib or GTK do not bubble up to the unittest
+ # This decorator catches all exceptions and raises them
+ # after the unittest
+ def func_wrapper(self, *args, **kwargs):
+
+ exceptions = []
+
+ def on_hook(type_, value, tback):
+ exceptions.append((type_, value, tback))
+
+ orig_excepthook = sys.excepthook
+ sys.excepthook = on_hook
+ try:
+ result = func(self)
+ finally:
+ sys.excepthook = orig_excepthook
+ if exceptions:
+ tp, value, tb = exceptions[0]
+ raise tp(value).with_traceback(tb)
+
+ return result
+ return func_wrapper
diff --git a/test/unit/test_http.py b/test/unit/test_http.py
index fc22624..f0a4a39 100644
--- a/test/unit/test_http.py
+++ b/test/unit/test_http.py
@@ -9,6 +9,7 @@ from gi.repository import Soup
from nbxmpp.const import HTTPRequestError
from nbxmpp.http import HTTPSession
+from test.lib.util import raise_all_exceptions
SMALL_FILE_URL = 'https://gajim.org/downloads/ci/unittest_small_file' # 200 KB
@@ -236,6 +237,7 @@ class HTTP(unittest.TestCase):
self.assertTrue(request4.is_finished())
self.assertTrue(request4.is_complete())
+ @raise_all_exceptions
def test_content_overflow(self):
mainloop = GLib.MainLoop()
@@ -243,7 +245,6 @@ class HTTP(unittest.TestCase):
session = HTTPSession()
request = session.create_request()
-
def _on_starting(req) -> None:
req._received_size = 100000000000