diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-06-15 00:17:41 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-06-15 00:17:41 +0200 |
commit | fda40cb64041aacdb776e0b1f4f4a635bdc9d70b (patch) | |
tree | c0d30d702c6886e5f8542daffb7aef080137ed0b /tests/test_declarations.py | |
parent | 1ba20b0ed7b920fa2d161df94a0dda3d93b1e14b (diff) | |
download | factory-boy-fda40cb64041aacdb776e0b1f4f4a635bdc9d70b.tar factory-boy-fda40cb64041aacdb776e0b1f4f4a635bdc9d70b.tar.gz |
Add Iterator.reset() (Closes #63).
Diffstat (limited to 'tests/test_declarations.py')
-rw-r--r-- | tests/test_declarations.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_declarations.py b/tests/test_declarations.py index cd38dd2..9d54c59 100644 --- a/tests/test_declarations.py +++ b/tests/test_declarations.py @@ -107,6 +107,27 @@ class IteratorTestCase(unittest.TestCase): self.assertEqual(2, it.evaluate(1, None, False)) self.assertRaises(StopIteration, it.evaluate, 2, None, False) + def test_reset_cycle(self): + it = declarations.Iterator([1, 2]) + self.assertEqual(1, it.evaluate(0, None, False)) + self.assertEqual(2, it.evaluate(1, None, False)) + self.assertEqual(1, it.evaluate(2, None, False)) + self.assertEqual(2, it.evaluate(3, None, False)) + self.assertEqual(1, it.evaluate(4, None, False)) + it.reset() + self.assertEqual(1, it.evaluate(5, None, False)) + self.assertEqual(2, it.evaluate(6, None, False)) + + def test_reset_no_cycling(self): + it = declarations.Iterator([1, 2], cycle=False) + self.assertEqual(1, it.evaluate(0, None, False)) + self.assertEqual(2, it.evaluate(1, None, False)) + self.assertRaises(StopIteration, it.evaluate, 2, None, False) + it.reset() + self.assertEqual(1, it.evaluate(0, None, False)) + self.assertEqual(2, it.evaluate(1, None, False)) + self.assertRaises(StopIteration, it.evaluate, 2, None, False) + def test_getter(self): it = declarations.Iterator([(1, 2), (1, 3)], getter=lambda p: p[1]) self.assertEqual(2, it.evaluate(0, None, False)) |