From e0d2fe6712eef00800ae7a9494b32be6f04f6752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Fri, 2 Sep 2022 16:45:21 +0200 Subject: [PATCH] Deprecate FuzzyInteger in favor of pyint --- docs/changelog.rst | 10 ++++++++++ docs/conf.py | 4 ++++ docs/fuzzy.rst | 13 +++++++++++++ factory/fuzzy.py | 5 +++++ tests/test_fuzzy.py | 17 +++++++++++++++++ 5 files changed, 49 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 94fe8699..66d51a2e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -45,6 +45,16 @@ ChangeLog - override :class:`~factory.django.DjangoModelFactory._after_postgeneration` to :meth:`~django.db.models.Model.save` the instance. + - :class:`~factory.fuzzy.FuzzyInteger` is deprecated. Use :meth:`~faker.providers.python.Provider.pyint` instead: + + .. code-block:: python + + class PersonFactory(factory.Factory): + age = factory.Faker('pyint', min_value=1, max_value=100, step=5) + + class Meta: + model = Person + *Removed:* - Drop support for Django 2.2 diff --git a/docs/conf.py b/docs/conf.py index f636c01b..bbf487da 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -84,6 +84,10 @@ 'https://docs.djangoproject.com/en/dev/', 'https://docs.djangoproject.com/en/dev/_objects/', ), + 'faker': ( + 'https://faker.readthedocs.io/en/master/', + 'https://faker.readthedocs.io/en/master/objects.inv', + ), 'sqlalchemy': ( 'https://docs.sqlalchemy.org/en/latest/', 'https://docs.sqlalchemy.org/en/latest/objects.inv', diff --git a/docs/fuzzy.rst b/docs/fuzzy.rst index 898bae85..33ba26dd 100644 --- a/docs/fuzzy.rst +++ b/docs/fuzzy.rst @@ -92,6 +92,19 @@ FuzzyChoice FuzzyInteger ------------ +.. warning:: This attribute is deprecated. + +.. deprecated:: 3.3 + Use :meth:`~faker.providers.python.Provider.pyint` instead: + + .. code-block:: python + + class PersonFactory(factory.Factory): + age = factory.Faker('pyint', min_value=1, max_value=100, step=5) + + class Meta: + model = Person + .. class:: FuzzyInteger(low[, high[, step]]) The :class:`FuzzyInteger` fuzzer generates random integers within a given diff --git a/factory/fuzzy.py b/factory/fuzzy.py index ce89d7f7..40475401 100644 --- a/factory/fuzzy.py +++ b/factory/fuzzy.py @@ -104,6 +104,11 @@ class FuzzyInteger(BaseFuzzyAttribute): """Random integer within a given range.""" def __init__(self, low, high=None, step=1): + warnings.warn( + f"{self.__class__.__name__} will be removed in the next major version. " + "Use Faker.pyint() instead.", + DeprecationWarning, + ) if high is None: high = low low = 0 diff --git a/tests/test_fuzzy.py b/tests/test_fuzzy.py index 67cf7030..7b50dace 100644 --- a/tests/test_fuzzy.py +++ b/tests/test_fuzzy.py @@ -80,6 +80,11 @@ def test_getter(self): class FuzzyIntegerTestCase(unittest.TestCase): + def run(self, result=None): + with warnings.catch_warnings(record=False): + warnings.simplefilter("ignore") + return super().run(result=result) + def test_definition(self): """Tests all ways of defining a FuzzyInteger.""" fuzz = fuzzy.FuzzyInteger(2, 3) @@ -122,6 +127,13 @@ def test_biased_with_step(self): self.assertEqual((5 + 8 + 1) * 3, res) + def test_warning(self): + with self.assertWarnsRegex( + DeprecationWarning, + r"^FuzzyInteger will be removed in the next major version. Use Faker.pyint\(\) instead\.$" + ): + fuzzy.FuzzyInteger(1, 5) + class FuzzyDecimalTestCase(unittest.TestCase): def test_definition(self): @@ -589,6 +601,11 @@ def options(): class FuzzyRandomTestCase(unittest.TestCase): + def run(self, result=None): + with warnings.catch_warnings(record=False): + warnings.simplefilter("ignore") + return super().run(result=result) + def test_seeding(self): fuzz = fuzzy.FuzzyInteger(1, 1000)