diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_using.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py index 41b34ea..7f9f09c 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -780,6 +780,25 @@ class IteratorTestCase(unittest.TestCase): for i, obj in enumerate(objs): self.assertEqual(i % 5, obj.one) + def test_infinite_iterator_list_comprehension(self): + class TestObjectFactory(factory.Factory): + one = factory.InfiniteIterator([j * 3 for j in xrange(5)]) + + # Scope bleeding: j will end up in TestObjectFactory's scope. + + self.assertRaises(TypeError, TestObjectFactory.build) + + def test_infinite_iterator_list_comprehension_protected(self): + class TestObjectFactory(factory.Factory): + one = factory.InfiniteIterator([_j * 3 for _j in xrange(5)]) + + # Scope bleeding : _j will end up in TestObjectFactory's scope. + # But factory_boy ignores it, as a protected variable. + objs = TestObjectFactory.build_batch(20) + + for i, obj in enumerate(objs): + self.assertEqual(3 * (i % 5), obj.one) + def test_iterator_decorator(self): class TestObjectFactory(factory.Factory): @factory.iterator |