Commit d788cea5 authored by Tres Seaver's avatar Tres Seaver

Coverage for TransactionManager.attempts.

Note that we now raise ValueError if passed a non-positive count, rather
than asserting.
parent f87c10cb
...@@ -4,6 +4,9 @@ Changes ...@@ -4,6 +4,9 @@ Changes
1.3.1 (unreleased) 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 - Raise ValueError from ``TransactionManager.free`` if passed a foreign
transaction (rather tna using ``assert``). transaction (rather tna using ``assert``).
......
...@@ -127,7 +127,8 @@ class TransactionManager(object): ...@@ -127,7 +127,8 @@ class TransactionManager(object):
return self.get().savepoint(optimistic) return self.get().savepoint(optimistic)
def attempts(self, number=3): def attempts(self, number=3):
assert number > 0 if number <= 0:
raise ValueError("number must be positive")
while number: while number:
number -= 1 number -= 1
if number: if number:
......
...@@ -209,6 +209,28 @@ class TransactionManagerTests(unittest.TestCase): ...@@ -209,6 +209,28 @@ class TransactionManagerTests(unittest.TestCase):
tm.savepoint(True) tm.savepoint(True)
self.assertTrue(txn._sp) 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 # basic tests with two sub trans jars
# really we only need one, so tests for # really we only need one, so tests for
# sub1 should identical to tests for sub2 # sub1 should identical to tests for sub2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment