[Pkg-bitcoin-commits] [python-quamash] 159/269: Test exception handling in more executors

Jonas Smedegaard dr at jones.dk
Fri Nov 24 11:26:27 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 93e98dde7d0447195d6466bfbf3ba49827d73026
Author: Mark Harviston <mark.harviston at gmail.com>
Date:   Sun Dec 14 02:40:32 2014 -0800

    Test exception handling in more executors
    
    had to mark multiprocessing executor as xfail (if --runxfail it will
    timeout, not hang! (yay?))
---
 tests/test_qeventloop.py | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index db97a91..2c076a5 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -71,12 +71,18 @@ def executor(request):
 	return exc
 
 
+ at pytest.fixture
+def TestException():
+	class TestException(Exception): pass
+	return TestException
+
 class TestCanRunTasksInExecutor:
 	"""
 	This needs to be a class because pickle can't serialize closures,
 	but can serialize bound methods.
 	multiprocessing can only handle pickleable functions.
 	"""
+
 	def test_can_run_tasks_in_executor(self, loop, executor):
 		"""Verify that tasks can be run in an executor."""
 		logging.debug('Loop: {!r}'.format(loop))
@@ -90,6 +96,21 @@ class TestCanRunTasksInExecutor:
 
 		assert was_invoked.value == 1
 
+	def test_can_handle_exception_in_executor(self, TestException, loop, executor):
+		if isinstance(executor, ProcessPoolExecutor):
+			pytest.xfail("can't catch ProcessPoolExecutor exceptions (yet)")
+
+		with pytest.raises(TestException) as excinfo:
+			loop.run_until_complete(asyncio.wait_for(
+				loop.run_in_executor(executor, self.blocking_failure, TestException),
+				timeout=3.0,
+			))
+		
+		assert str(excinfo.value) == 'Testing'
+
+	def blocking_failure(self, TestException):
+		raise TestException('Testing')
+
 	def blocking_func(self, was_invoked):
 		logging.debug('start blocking_func()')
 		was_invoked.value = 1
@@ -103,15 +124,6 @@ class TestCanRunTasksInExecutor:
 		logging.debug('start blocking task()')
 
 
-def test_can_handle_exception_in_default_executor(loop):
-	"""Verify that exceptions from tasks run in default (threaded) executor are handled."""
-	def blocking_func():
-		raise Exception('Testing')
-
-	with pytest.raises(Exception) as excinfo:
-		loop.run_until_complete(loop.run_in_executor(None, blocking_func))
-
-	assert str(excinfo.value) == 'Testing'
 
 
 def test_can_execute_subprocess(loop):

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