Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 13 additions & 0 deletions docs/fuzzy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions factory/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/test_fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down