summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2018-09-25 16:48:25 -0500
committerJason Madden <jamadden@gmail.com>2018-09-25 16:48:25 -0500
commit13ffadc2f097bc463a597f577fc932ced13fa3b7 (patch)
treee32eab5e85789d0b05da043429208fd378d739f8 /src
parent6fa6e4824182f63e23d0ee36c06f4af2d5af50b2 (diff)
downloadzope-configuration-13ffadc2f097bc463a597f577fc932ced13fa3b7.tar.gz
Allow customization of which exceptions should pass through ConfigurationMachine.issue10
Fixes #10.
Diffstat (limited to 'src')
-rw-r--r--src/zope/configuration/config.py15
-rw-r--r--src/zope/configuration/tests/test_config.py22
2 files changed, 33 insertions, 4 deletions
diff --git a/src/zope/configuration/config.py b/src/zope/configuration/config.py
index 774b265..61c37a8 100644
--- a/src/zope/configuration/config.py
+++ b/src/zope/configuration/config.py
@@ -333,6 +333,14 @@ class ConfigurationMachine(ConfigurationAdapterRegistry, ConfigurationContext):
includepath = ()
info = ''
+ #: These exceptions are allowed to be raised from `execute_actions`
+ #: without being re-wrapped into a `ConfigurationExecutionError`.
+ #: Users of instances of this class may modify this before calling `execute_actions`
+ #: if they need to propagate specific exceptions.
+ #:
+ #: .. versionadded:: 4.2.0
+ pass_through_exceptions = (KeyboardInterrupt, SystemExit)
+
def __init__(self):
super(ConfigurationMachine, self).__init__()
self.actions = []
@@ -367,6 +375,9 @@ class ConfigurationMachine(ConfigurationAdapterRegistry, ConfigurationContext):
This calls the action callables after resolving conflicts.
"""
+ pass_through_exceptions = self.pass_through_exceptions
+ if testing:
+ pass_through_exceptions = BaseException
try:
for action in resolveConflicts(self.actions):
callable = action['callable']
@@ -377,11 +388,9 @@ class ConfigurationMachine(ConfigurationAdapterRegistry, ConfigurationContext):
info = action['info']
try:
callable(*args, **kw)
- except (KeyboardInterrupt, SystemExit): # pragma: no cover
+ except pass_through_exceptions:
raise
except:
- if testing:
- raise
t, v, tb = sys.exc_info()
try:
reraise(ConfigurationExecutionError(t, v, info),
diff --git a/src/zope/configuration/tests/test_config.py b/src/zope/configuration/tests/test_config.py
index 4835df9..42e7e2b 100644
--- a/src/zope/configuration/tests/test_config.py
+++ b/src/zope/configuration/tests/test_config.py
@@ -766,10 +766,30 @@ class ConfigurationMachineTests(_ConformsToIConfigurationContext,
cm.action(None, _err)
with self.assertRaises(ConfigurationExecutionError) as exc:
cm.execute_actions()
- self.assertTrue(exc.exception.etype is ValueError)
+ self.assertIs(exc.exception.etype, ValueError)
self.assertEqual(str(exc.exception.evalue), "XXX")
self.assertEqual(exc.exception.info, "INFO")
+ def _check_execute_actions_w_errors_wo_testing(self, ex_kind):
+ ex = ex_kind('XXX')
+ def _err(*args, **kw):
+ raise ex
+ cm = self._makeOne()
+ cm.info = 'INFO'
+ cm.action(None, _err)
+ with self.assertRaises(ex_kind) as exc:
+ cm.execute_actions()
+
+ self.assertIs(exc.exception, ex)
+
+ def test_execute_actions_w_errors_wo_testing_SystemExit(self):
+ # It gets passed through as-is
+ self._check_execute_actions_w_errors_wo_testing(SystemExit)
+
+ def test_execute_actions_w_errors_wo_testing_KeyboardInterrupt(self):
+ # It gets passed through as-is
+ self._check_execute_actions_w_errors_wo_testing(KeyboardInterrupt)
+
def test_keyword_handling(self):
# This is really an integraiton test.
from zope.configuration.config import metans