summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2014-12-27 00:10:03 -0600
committerMichael Merickel <michael@merickel.org>2014-12-27 00:10:03 -0600
commit873fa0483a7bfeafa5590b6d992ac52228d1b509 (patch)
tree79d9a355446d9be77c5c978ccb37610a9af71162
parentcf6e03bf042483283c2a7a51fec29a6d73887965 (diff)
downloadpyramid-873fa0483a7bfeafa5590b6d992ac52228d1b509.tar.gz
pyramid-873fa0483a7bfeafa5590b6d992ac52228d1b509.tar.bz2
pyramid-873fa0483a7bfeafa5590b6d992ac52228d1b509.zip
add reentrant tests
-rw-r--r--pyramid/config/__init__.py11
-rw-r--r--pyramid/tests/test_config/test_init.py39
2 files changed, 46 insertions, 4 deletions
diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py
index c35338826..e81ccee3f 100644
--- a/pyramid/config/__init__.py
+++ b/pyramid/config/__init__.py
@@ -1072,7 +1072,6 @@ class ActionState(object):
... output.append(('g', a, k))
>>> context.actions = [
... (1, f, (1,)),
- ... (2, f, (2,)),
... ]
>>> context.execute_actions()
>>> output
@@ -1114,7 +1113,8 @@ class ActionState(object):
# conflicts.
if self.actions:
# Only resolve the new actions against executed_actions
- # instead of everything to avoid redundant checks.
+ # and pending_actions instead of everything to avoid
+ # redundant checks.
# Assume ``actions = resolveConflicts([A, B, C])`` which
# after conflict checks, resulted in ``actions == [A]``
# then we know action A won out or a conflict would have
@@ -1123,9 +1123,12 @@ class ActionState(object):
# ``actions = resolveConflicts([A, D]) should drop the
# number of redundant checks down from O(n^2) closer to
# O(n lg n).
- pending_actions = resume(resolveConflicts(
- executed_actions + self.actions))
all_actions.extend(self.actions)
+ pending_actions = resume(resolveConflicts(
+ executed_actions
+ + list(pending_actions)
+ + self.actions
+ ))
self.actions = []
action = next(pending_actions, None)
diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py
index 1e58e4d0f..40cc83885 100644
--- a/pyramid/tests/test_config/test_init.py
+++ b/pyramid/tests/test_config/test_init.py
@@ -1503,6 +1503,45 @@ class TestActionState(unittest.TestCase):
self.assertRaises(ConfigurationExecutionError, c.execute_actions)
self.assertEqual(output, [('f', (1,), {}), ('f', (2,), {})])
+ def test_reentrant_action(self):
+ output = []
+ c = self._makeOne()
+ def f(*a, **k):
+ output.append(('f', a, k))
+ c.actions.append((3, g, (8,), {}))
+ def g(*a, **k):
+ output.append(('g', a, k))
+ c.actions = [
+ (1, f, (1,)),
+ ]
+ c.execute_actions()
+ self.assertEqual(output, [('f', (1,), {}), ('g', (8,), {})])
+
+ def test_reentrant_action_error(self):
+ from pyramid.exceptions import ConfigurationError
+ c = self._makeOne()
+ def f(*a, **k):
+ c.actions.append((3, g, (8,), {}, (), None, -1))
+ def g(*a, **k): pass
+ c.actions = [
+ (1, f, (1,)),
+ ]
+ self.assertRaises(ConfigurationError, c.execute_actions)
+
+ def test_reentrant_action_without_clear(self):
+ c = self._makeOne()
+ def f(*a, **k):
+ c.actions.append((3, g, (8,)))
+ def g(*a, **k): pass
+ c.actions = [
+ (1, f, (1,)),
+ ]
+ c.execute_actions(clear=False)
+ self.assertEqual(c.actions, [
+ (1, f, (1,)),
+ (3, g, (8,)),
+ ])
+
class Test_resolveConflicts(unittest.TestCase):
def _callFUT(self, actions):
from pyramid.config import resolveConflicts