diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-03-11 22:28:43 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-03-11 22:28:43 +0100 |
commit | de3a552eab032cb980a2fb78976fc3dc8cd5f1c8 (patch) | |
tree | 1eb5e3cbc27f5abd9c9d4b1729c152a1db97c3ee | |
parent | e2ac08066fbc6b6412b713b42aba792c224067f5 (diff) | |
download | factory-boy-de3a552eab032cb980a2fb78976fc3dc8cd5f1c8.tar factory-boy-de3a552eab032cb980a2fb78976fc3dc8cd5f1c8.tar.gz |
Remove InfiniteIterator and infinite_iterator.
Use Iterator/iterator instead.
-rw-r--r-- | docs/changelog.rst | 1 | ||||
-rw-r--r-- | docs/reference.rst | 26 | ||||
-rw-r--r-- | factory/__init__.py | 2 | ||||
-rw-r--r-- | factory/declarations.py | 23 | ||||
-rw-r--r-- | tests/test_using.py | 65 |
5 files changed, 5 insertions, 112 deletions
diff --git a/docs/changelog.rst b/docs/changelog.rst index 1a82ecd..88107a4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,7 @@ ChangeLog *Removed:* - Remove associated class discovery + - Remove :class:`~factory.InfiniteIterator` and :func:`~factory.infinite_iterator` - Stop defaulting to Django's ``Foo.objects.create()`` when "creating" instances - Remove STRATEGY_* - Remove :meth:`~factory.Factory.set_building_function` / :meth:`~factory.Factory.set_creation_function` diff --git a/docs/reference.rst b/docs/reference.rst index 2b5ba11..27e2e14 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -830,32 +830,6 @@ use the :func:`iterator` decorator: yield line -InfiniteIterator -~~~~~~~~~~~~~~~~ - -.. class:: InfiniteIterator(iterable) - - Equivalent to ``factory.Iterator(iterable)``. - -.. deprecated:: 1.3.0 - Merged into :class:`Iterator`; will be removed in v2.0.0. - - Replace ``factory.InfiniteIterator(iterable)`` - with ``factory.Iterator(iterable)``. - - -.. function:: infinite_iterator(function) - - Equivalent to ``factory.iterator(func)``. - - -.. deprecated:: 1.3.0 - Merged into :func:`iterator`; will be removed in v2.0.0. - - Replace ``@factory.infinite_iterator`` with ``@factory.iterator``. - - - Post-generation hooks """"""""""""""""""""" diff --git a/factory/__init__.py b/factory/__init__.py index db88f4e..4b4857c 100644 --- a/factory/__init__.py +++ b/factory/__init__.py @@ -50,7 +50,6 @@ from .base import ( from .declarations import ( LazyAttribute, Iterator, - InfiniteIterator, Sequence, LazyAttributeSequence, SelfAttribute, @@ -63,7 +62,6 @@ from .declarations import ( lazy_attribute, iterator, - infinite_iterator, sequence, lazy_attribute_sequence, container_attribute, diff --git a/factory/declarations.py b/factory/declarations.py index efaadbe..1f64038 100644 --- a/factory/declarations.py +++ b/factory/declarations.py @@ -156,21 +156,6 @@ class Iterator(OrderedDeclaration): return self.getter(value) -class InfiniteIterator(Iterator): - """Same as Iterator, but make the iterator infinite by cycling at the end. - - Attributes: - iterator (iterable): the iterator, once made infinite. - """ - - def __init__(self, iterator): - warnings.warn( - "factory.InfiniteIterator is deprecated, and will be removed in the " - "future. Please use factory.Iterator instead.", - PendingDeprecationWarning, 2) - return super(InfiniteIterator, self).__init__(iterator, cycle=True) - - class Sequence(OrderedDeclaration): """Specific OrderedDeclaration to use for 'sequenced' fields. @@ -524,14 +509,6 @@ def iterator(func): """Turn a generator function into an iterator attribute.""" return Iterator(func()) -def infinite_iterator(func): - """Turn a generator function into an infinite iterator attribute.""" - warnings.warn( - "@factory.infinite_iterator is deprecated and will be removed in the " - "future. Please use @factory.iterator instead.", - PendingDeprecationWarning, 2) - return InfiniteIterator(func()) - def sequence(func): return Sequence(func) diff --git a/tests/test_using.py b/tests/test_using.py index 5287a6d..b617668 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -1137,50 +1137,24 @@ 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)) - - @tools.disable_warnings - def test_infinite_iterator(self): - class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject - - one = factory.InfiniteIterator(range(5)) - - objs = TestObjectFactory.build_batch(20) - - for i, obj in enumerate(objs): - self.assertEqual(i % 5, obj.one) - @unittest.skipUnless(is_python2, "Scope bleeding fixed in Python3+") @tools.disable_warnings - def test_infinite_iterator_list_comprehension_scope_bleeding(self): + def test_iterator_list_comprehension_scope_bleeding(self): class TestObjectFactory(factory.Factory): FACTORY_FOR = TestObject - one = factory.InfiniteIterator([j * 3 for j in range(5)]) + one = factory.Iterator([j * 3 for j in range(5)]) # Scope bleeding: j will end up in TestObjectFactory's scope. self.assertRaises(TypeError, TestObjectFactory.build) @tools.disable_warnings - def test_infinite_iterator_list_comprehension_protected(self): + def test_iterator_list_comprehension_protected(self): class TestObjectFactory(factory.Factory): FACTORY_FOR = TestObject - one = factory.InfiniteIterator([_j * 3 for _j in range(5)]) + one = factory.Iterator([_j * 3 for _j in range(5)]) # Scope bleeding : _j will end up in TestObjectFactory's scope. # But factory_boy ignores it, as a protected variable. @@ -1203,37 +1177,6 @@ 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)) - - @tools.disable_warnings - def test_infinite_iterator_decorator(self): - class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject - - @factory.infinite_iterator - def one(): - for i in range(5): - yield i - - objs = TestObjectFactory.build_batch(20) - - for i, obj in enumerate(objs): - self.assertEqual(i % 5, obj.one) - class PostGenerationTestCase(unittest.TestCase): def test_post_generation(self): |