[Pkg-bitcoin-commits] [python-quamash] 238/269: improve tests

Jonas Smedegaard dr at jones.dk
Fri Nov 24 11:26:37 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 df3d78b82ad2776d1a82138a1996319ffa1072d7
Author: Mark Harviston <Mark.T.Harviston.-ND at disney.com>
Date:   Wed Jul 1 13:18:24 2015 -0700

    improve tests
    
    the _simple tests passes, but the one that actually uses a raised
    Exception does not because a reference to the future is kept by
    Task._step (task is a subclass of Future in this case)
---
 tests/test_qeventloop.py | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index 67b8532..38df522 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -694,23 +694,43 @@ def test_exception_handler(application):
 	handler_called = False
 	coro_run = False
 	loop = quamash.QEventLoop(application)
+	loop.set_debug(True)
 	asyncio.set_event_loop(loop)
 
 	@asyncio.coroutine
 	def future_except():
 		nonlocal coro_run
 		coro_run = True
+		loop.stop()
 		raise ExceptionTester()
 
 	def exct_handler(loop, data):
 		nonlocal handler_called
 		handler_called = True
 
-	try:
-		loop.set_exception_handler(exct_handler)
-		asyncio.async(future_except())
-		loop.run_until_complete(asyncio.sleep(.1))
-	finally:
-		asyncio.set_event_loop(None)
+	loop.set_exception_handler(exct_handler)
+	fut = asyncio.async(future_except())
+	loop.run_forever()
+
 	assert coro_run
 	assert handler_called
+
+
+def test_exception_handler_simple(application):
+	handler_called = False
+	loop = quamash.QEventLoop(application)
+	loop.set_debug(True)
+	asyncio.set_event_loop(loop)
+
+	def exct_handler(loop, data):
+		nonlocal handler_called
+		handler_called = True
+
+	loop.set_exception_handler(exct_handler)
+	fut1 = asyncio.Future()
+	fut1.set_exception(ExceptionTester())
+	asyncio.async(fut1)
+	del fut1
+	loop.call_later(0.1, loop.stop)
+	loop.run_forever()
+	assert handler_called

-- 
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