diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-03-09 22:06:26 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-03-09 22:06:26 +0100 |
commit | 8879108f5595099785565cae35938a356bbbeced (patch) | |
tree | 1642a3650d85ad84be9d3e80e03faa79978532b0 /tests | |
parent | b1682f428d29ea947604447c328b1a09a79313c0 (diff) | |
download | factory-boy-8879108f5595099785565cae35938a356bbbeced.tar factory-boy-8879108f5595099785565cae35938a356bbbeced.tar.gz |
Add a couple of tests for scope bleeding with InfiniteIterator and list comprehensions (See #6).
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
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 |