[Checkins] SVN: transaction/branches/sphinx/ Coverage for TransactionManager.attempts.
Tres Seaver
cvs-admin at zope.org
Mon Dec 17 22:09:14 UTC 2012
Log message for revision 128725:
Coverage for TransactionManager.attempts.
Note that we now raise ValueError if passed a non-positive count, rather
than asserting.
Changed:
_U transaction/branches/sphinx/
U transaction/branches/sphinx/CHANGES.txt
U transaction/branches/sphinx/transaction/_manager.py
U transaction/branches/sphinx/transaction/tests/test__manager.py
-=-
Modified: transaction/branches/sphinx/CHANGES.txt
===================================================================
--- transaction/branches/sphinx/CHANGES.txt 2012-12-17 22:09:13 UTC (rev 128724)
+++ transaction/branches/sphinx/CHANGES.txt 2012-12-17 22:09:14 UTC (rev 128725)
@@ -4,6 +4,9 @@
1.3.1 (unreleased)
------------------
+- Raise ValueError from ``TransactionManager.attempts`` if passed a
+ non-positive value (rather than using ``assert``).
+
- Raise ValueError from ``TransactionManager.free`` if passed a foreign
transaction (rather tna using ``assert``).
Modified: transaction/branches/sphinx/transaction/_manager.py
===================================================================
--- transaction/branches/sphinx/transaction/_manager.py 2012-12-17 22:09:13 UTC (rev 128724)
+++ transaction/branches/sphinx/transaction/_manager.py 2012-12-17 22:09:14 UTC (rev 128725)
@@ -127,7 +127,8 @@
return self.get().savepoint(optimistic)
def attempts(self, number=3):
- assert number > 0
+ if number <= 0:
+ raise ValueError("number must be positive")
while number:
number -= 1
if number:
Modified: transaction/branches/sphinx/transaction/tests/test__manager.py
===================================================================
--- transaction/branches/sphinx/transaction/tests/test__manager.py 2012-12-17 22:09:13 UTC (rev 128724)
+++ transaction/branches/sphinx/transaction/tests/test__manager.py 2012-12-17 22:09:14 UTC (rev 128725)
@@ -209,6 +209,28 @@
tm.savepoint(True)
self.assertTrue(txn._sp)
+ def test_attempts_w_invalid_count(self):
+ tm = self._makeOne()
+ self.assertRaises(ValueError, list, tm.attempts(0))
+ self.assertRaises(ValueError, list, tm.attempts(-1))
+ self.assertRaises(ValueError, list, tm.attempts(-10))
+
+ def test_attempts_w_valid_count(self):
+ tm = self._makeOne()
+ found = list(tm.attempts(1))
+ self.assertEqual(len(found), 1)
+ self.assertTrue(found[0] is tm)
+
+ def test_attempts_w_default_count(self):
+ from transaction._manager import Attempt
+ tm = self._makeOne()
+ found = list(tm.attempts())
+ self.assertEqual(len(found), 3)
+ for attempt in found[:-1]:
+ self.assertTrue(isinstance(attempt, Attempt))
+ self.assertTrue(attempt.manager is tm)
+ self.assertTrue(found[-1] is tm)
+
# basic tests with two sub trans jars
# really we only need one, so tests for
# sub1 should identical to tests for sub2
More information about the checkins
mailing list