summaryrefslogtreecommitdiff
path: root/tests/test_using.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-01 01:35:26 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-03 21:38:46 +0100
commitebdfb8cc5bab1e59b593a4ea60e55b9e7af455ef (patch)
tree893373eb7e207a9115d0df16922ee64508aaa22a /tests/test_using.py
parent050af55b77372b39fb6efecfb93bb6ee8ee425ed (diff)
downloadfactory-boy-ebdfb8cc5bab1e59b593a4ea60e55b9e7af455ef.tar
factory-boy-ebdfb8cc5bab1e59b593a4ea60e55b9e7af455ef.tar.gz
Improve Iterator and SubFactory declarations.
* Iterator now cycles by default * Iterator can be provided with a custom getter * SubFactory accepts a factory import path as well Deprecates: * InfiniteIterator * CircularSubFactory Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests/test_using.py')
-rw-r--r--tests/test_using.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py
index fb0e8b0..fb8c207 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -1076,6 +1076,21 @@ class IteratorTestCase(unittest.TestCase):
for i, obj in enumerate(objs):
self.assertEqual(i + 10, obj.one)
+ def test_infinite_iterator_deprecated(self):
+ with warnings.catch_warnings(record=True) as w:
+ __warningregistry__.clear()
+
+ warnings.simplefilter('always')
+ class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
+ foo = factory.InfiniteIterator(range(5))
+
+ self.assertEqual(1, len(w))
+ self.assertIn('InfiniteIterator', str(w[0].message))
+ self.assertIn('deprecated', str(w[0].message))
+
+ @disable_warnings
def test_infinite_iterator(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
@@ -1088,6 +1103,7 @@ class IteratorTestCase(unittest.TestCase):
self.assertEqual(i % 5, obj.one)
@unittest.skipUnless(is_python2, "Scope bleeding fixed in Python3+")
+ @disable_warnings
def test_infinite_iterator_list_comprehension_scope_bleeding(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
@@ -1098,6 +1114,7 @@ class IteratorTestCase(unittest.TestCase):
self.assertRaises(TypeError, TestObjectFactory.build)
+ @disable_warnings
def test_infinite_iterator_list_comprehension_protected(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
@@ -1125,6 +1142,23 @@ class IteratorTestCase(unittest.TestCase):
for i, obj in enumerate(objs):
self.assertEqual(i + 10, obj.one)
+ def test_infinite_iterator_decorator_deprecated(self):
+ with warnings.catch_warnings(record=True) as w:
+ __warningregistry__.clear()
+
+ warnings.simplefilter('always')
+ class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
+ @factory.infinite_iterator
+ def one():
+ return range(5)
+
+ self.assertEqual(1, len(w))
+ self.assertIn('infinite_iterator', str(w[0].message))
+ self.assertIn('deprecated', str(w[0].message))
+
+ @disable_warnings
def test_infinite_iterator_decorator(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject