From 873fa0483a7bfeafa5590b6d992ac52228d1b509 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sat, 27 Dec 2014 00:10:03 -0600 Subject: add reentrant tests --- pyramid/config/__init__.py | 11 ++++++---- pyramid/tests/test_config/test_init.py | 39 ++++++++++++++++++++++++++++++++++ 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 -- cgit v1.2.3