[Pkg-bitcoin-commits] [python-quamash] 205/269: Fixes #24 - Exceptions in callbacks will make tests fail now.

Jonas Smedegaard dr at jones.dk
Fri Nov 24 11:26:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository python-quamash.

commit 790d84747e8b1b45ed7c372a4d228cc90609baf9
Author: Mark Harviston <mark.harviston at gmail.com>
Date:   Thu Jan 15 16:41:48 2015 -0800

    Fixes #24 - Exceptions in callbacks will make tests fail now.
---
 tests/test_qeventloop.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index 8425ab4..c7529e8 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -40,6 +40,8 @@ def loop(request, application):
 	lp = quamash.QEventLoop(application)
 	asyncio.set_event_loop(lp)
 
+	additional_exceptions = []
+
 	def fin():
 		sys.excepthook = orig_excepthook
 
@@ -48,12 +50,19 @@ def loop(request, application):
 		finally:
 			asyncio.set_event_loop(None)
 
+		if additional_exceptions:
+			raise additional_exceptions[0]['exception']
+
+	def except_handler(loop, ctx):
+		additional_exceptions.append(ctx)
+
 	def excepthook(type, *args):
 		lp.stop()
 		orig_excepthook(type, *args)
 
 	orig_excepthook = sys.excepthook
 	sys.excepthook = excepthook
+	lp.set_exception_handler(except_handler)
 
 	request.addfinalizer(fin)
 	return lp
@@ -203,6 +212,15 @@ def test_can_terminate_subprocess(loop):
 	assert transport.get_returncode() != 0
 
 
+ at pytest.mark.raises(TestException)
+def test_loop_callback_exceptions_bubble_up(loop):
+	"""Verify that test exceptions raised in event loop callbacks bubble up."""
+	def raise_test_exception():
+		raise TestException("Test Message")
+	loop.call_soon(raise_test_exception)
+	loop.run_until_complete(asyncio.sleep(.1))
+
+
 def test_loop_running(loop):
 	"""Verify that loop.is_running returns True when running."""
 	@asyncio.coroutine

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/python-quamash.git



More information about the Pkg-bitcoin-commits mailing list