[Zodb-checkins]
SVN: ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/
Raise an exception if the value given as a parameter for the
order is not an integer type
Julien Anguenot
ja at nuxeo.com
Mon Aug 8 17:23:42 EDT 2005
Log message for revision 37798:
Raise an exception if the value given as a parameter for the order is not an integer type
Changed:
U ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/_transaction.py
U ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/tests/test_transaction.py
-=-
Modified: ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/_transaction.py
===================================================================
--- ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/_transaction.py 2005-08-08 21:01:42 UTC (rev 37797)
+++ ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/_transaction.py 2005-08-08 21:23:41 UTC (rev 37798)
@@ -415,7 +415,8 @@
def beforeCommitHookOrdered(self, hook, order, *args, **kws):
if not isinstance(order, IntType):
- order = 0
+ raise ValueError("An integer value is required "
+ "for the order argument")
index = 0
for o, h, a, k in self._before_commit:
if order < o:
Modified: ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/tests/test_transaction.py
===================================================================
--- ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/tests/test_transaction.py 2005-08-08 21:01:42 UTC (rev 37797)
+++ ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/tests/test_transaction.py 2005-08-08 21:23:41 UTC (rev 37798)
@@ -410,6 +410,34 @@
"""
+def hook():
+ pass
+
+class BeforeCommitHookTests(unittest.TestCase):
+
+ def test_01_beforecommithook_order_exceptions(self):
+ # string
+ t = transaction.Transaction()
+ self.assertRaises(ValueError, t.beforeCommitHookOrdered,
+ hook, 'string')
+
+ def test_02_beforecommithook_order_exceptions(self):
+ # float
+ t = transaction.Transaction()
+ self.assertRaises(ValueError, t.beforeCommitHookOrdered,
+ hook, 1.2)
+
+ def test_03_beforecommithook_order_exceptions(self):
+ # object
+ t = transaction.Transaction()
+ class foo:
+ pass
+ self.assertRaises(ValueError, t.beforeCommitHookOrdered,
+ hook, foo())
+
+ # XXX if the type check for whatever reasons gets more complex one
+ # day just add some more tests in here
+
def test_beforeCommitHook():
"""Test the beforeCommitHook.
@@ -624,28 +652,13 @@
('hook', ('3',), {})
('hook', ('5',), {})
- Try to register an hook with an order value different than an
- integer value. It will be replaced by the default order value (e.g
- : 0)
-
- >>> t.beforeCommitHookOrdered(hook, 'string_value', '7')
- >>> for hook, args, kws in t.getBeforeCommitHooks():
- ... print (hook.func_name, args, kws)
- ('hook', ('2',), {})
- ('hook', ('6',), {})
- ('hook', ('1',), {})
- ('hook', ('4',), {})
- ('hook', ('7',), {})
- ('hook', ('3',), {})
- ('hook', ('5',), {})
-
Ensure, the calls are made in the order of the registration
without taking the whole tuple while internal comparaison. For
instance bisect.insort() can't work in this case
-
+
>>> def hook2(arg='no_arg', kw1='no_kw1', kw2='no_kw2'):
... log.append("arg %r kw1 %r kw2 %r" % (arg, kw1, kw2))
-
+
>>> t.beforeCommitHookOrdered(hook2, 0, '8')
>>> for hook, args, kws in t.getBeforeCommitHooks():
... print (hook.func_name, args, kws)
@@ -653,7 +666,6 @@
('hook', ('6',), {})
('hook', ('1',), {})
('hook', ('4',), {})
- ('hook', ('7',), {})
('hook2', ('8',), {})
('hook', ('3',), {})
('hook', ('5',), {})
@@ -665,8 +677,8 @@
return unittest.TestSuite((
DocTestSuite(),
unittest.makeSuite(TransactionTests),
+ unittest.makeSuite(BeforeCommitHookTests),
))
-
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
More information about the Zodb-checkins
mailing list