summaryrefslogtreecommitdiff
path: root/docs/fuzzy.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/fuzzy.rst')
-rw-r--r--docs/fuzzy.rst220
1 files changed, 220 insertions, 0 deletions
diff --git a/docs/fuzzy.rst b/docs/fuzzy.rst
index f1f4085..b94dfa5 100644
--- a/docs/fuzzy.rst
+++ b/docs/fuzzy.rst
@@ -24,6 +24,35 @@ FuzzyAttribute
The callable that generates random values
+FuzzyText
+---------
+
+
+.. class:: FuzzyText(length=12, chars=string.ascii_letters, prefix='')
+
+ The :class:`FuzzyText` fuzzer yields random strings beginning with
+ the given :attr:`prefix`, followed by :attr:`length` charactes chosen
+ from the :attr:`chars` character set,
+ and ending with the given :attr:`suffix`.
+
+ .. attribute:: length
+
+ int, the length of the random part
+
+ .. attribute:: prefix
+
+ text, an optional prefix to prepend to the random part
+
+ .. attribute:: suffix
+
+ text, an optional suffix to append to the random part
+
+ .. attribute:: chars
+
+ char iterable, the chars to choose from; defaults to the list of ascii
+ letters and numbers.
+
+
FuzzyChoice
-----------
@@ -69,6 +98,197 @@ FuzzyInteger
int, the inclusive higher bound of generated integers
+FuzzyDecimal
+------------
+
+.. class:: FuzzyDecimal(low[, high])
+
+ The :class:`FuzzyDecimal` fuzzer generates random integers within a given
+ inclusive range.
+
+ The :attr:`low` bound may be omitted, in which case it defaults to 0:
+
+ .. code-block:: pycon
+
+ >>> FuzzyDecimal(0.5, 42.7)
+ >>> fi.low, fi.high
+ 0.5, 42.7
+
+ >>> fi = FuzzyDecimal(42.7)
+ >>> fi.low, fi.high
+ 0.0, 42.7
+
+ >>> fi = FuzzyDecimal(0.5, 42.7, 3)
+ >>> fi.low, fi.high, fi.precision
+ 0.5, 42.7, 3
+
+ .. attribute:: low
+
+ decimal, the inclusive lower bound of generated decimals
+
+ .. attribute:: high
+
+ decimal, the inclusive higher bound of generated decimals
+
+ .. attribute:: precision
+ int, the number of digits to generate after the dot. The default is 2 digits.
+
+
+FuzzyDate
+---------
+
+.. class:: FuzzyDate(start_date[, end_date])
+
+ The :class:`FuzzyDate` fuzzer generates random dates within a given
+ inclusive range.
+
+ The :attr:`end_date` bound may be omitted, in which case it defaults to the current date:
+
+ .. code-block:: pycon
+
+ >>> fd = FuzzyDate(datetime.date(2008, 1, 1))
+ >>> fd.start_date, fd.end_date
+ datetime.date(2008, 1, 1), datetime.date(2013, 4, 16)
+
+ .. attribute:: start_date
+
+ :class:`datetime.date`, the inclusive lower bound of generated dates
+
+ .. attribute:: end_date
+
+ :class:`datetime.date`, the inclusive higher bound of generated dates
+
+
+FuzzyDateTime
+-------------
+
+.. class:: FuzzyDateTime(start_dt[, end_dt], tz=UTC, force_year=None, force_month=None, force_day=None, force_hour=None, force_minute=None, force_second=None, force_microsecond=None)
+
+ The :class:`FuzzyDateTime` fuzzer generates random timezone-aware datetime within a given
+ inclusive range.
+
+ The :attr:`end_dt` bound may be omitted, in which case it defaults to ``datetime.datetime.now()``
+ localized into the UTC timezone.
+
+ .. code-block:: pycon
+
+ >>> fdt = FuzzyDateTime(datetime.datetime(2008, 1, 1, tzinfo=UTC))
+ >>> fdt.start_dt, fdt.end_dt
+ datetime.datetime(2008, 1, 1, tzinfo=UTC), datetime.datetime(2013, 4, 21, 19, 13, 32, 458487, tzinfo=UTC)
+
+
+ The ``force_XXX`` keyword arguments force the related value of generated datetimes:
+
+ .. code-block:: pycon
+
+ >>> fdt = FuzzyDateTime(datetime.datetime(2008, 1, 1, tzinfo=UTC), datetime.datetime(2009, 1, 1, tzinfo=UTC),
+ ... force_day=3, force_second=42)
+ >>> fdt.evaluate(2, None, False) # Actual code used by ``SomeFactory.build()``
+ datetime.datetime(2008, 5, 3, 12, 13, 42, 124848, tzinfo=UTC)
+
+
+ .. attribute:: start_dt
+
+ :class:`datetime.datetime`, the inclusive lower bound of generated datetimes
+
+ .. attribute:: end_dt
+
+ :class:`datetime.datetime`, the inclusive upper bound of generated datetimes
+
+
+ .. attribute:: force_year
+
+ int or None; if set, forces the :attr:`~datetime.datetime.year` of generated datetime.
+
+ .. attribute:: force_month
+
+ int or None; if set, forces the :attr:`~datetime.datetime.month` of generated datetime.
+
+ .. attribute:: force_day
+
+ int or None; if set, forces the :attr:`~datetime.datetime.day` of generated datetime.
+
+ .. attribute:: force_hour
+
+ int or None; if set, forces the :attr:`~datetime.datetime.hour` of generated datetime.
+
+ .. attribute:: force_minute
+
+ int or None; if set, forces the :attr:`~datetime.datetime.minute` of generated datetime.
+
+ .. attribute:: force_second
+
+ int or None; if set, forces the :attr:`~datetime.datetime.second` of generated datetime.
+
+ .. attribute:: force_microsecond
+
+ int or None; if set, forces the :attr:`~datetime.datetime.microsecond` of generated datetime.
+
+
+FuzzyNaiveDateTime
+------------------
+
+.. class:: FuzzyNaiveDateTime(start_dt[, end_dt], force_year=None, force_month=None, force_day=None, force_hour=None, force_minute=None, force_second=None, force_microsecond=None)
+
+ The :class:`FuzzyNaiveDateTime` fuzzer generates random naive datetime within a given
+ inclusive range.
+
+ The :attr:`end_dt` bound may be omitted, in which case it defaults to ``datetime.datetime.now()``:
+
+ .. code-block:: pycon
+
+ >>> fdt = FuzzyNaiveDateTime(datetime.datetime(2008, 1, 1))
+ >>> fdt.start_dt, fdt.end_dt
+ datetime.datetime(2008, 1, 1), datetime.datetime(2013, 4, 21, 19, 13, 32, 458487)
+
+
+ The ``force_XXX`` keyword arguments force the related value of generated datetimes:
+
+ .. code-block:: pycon
+
+ >>> fdt = FuzzyNaiveDateTime(datetime.datetime(2008, 1, 1), datetime.datetime(2009, 1, 1),
+ ... force_day=3, force_second=42)
+ >>> fdt.evaluate(2, None, False) # Actual code used by ``SomeFactory.build()``
+ datetime.datetime(2008, 5, 3, 12, 13, 42, 124848)
+
+
+ .. attribute:: start_dt
+
+ :class:`datetime.datetime`, the inclusive lower bound of generated datetimes
+
+ .. attribute:: end_dt
+
+ :class:`datetime.datetime`, the inclusive upper bound of generated datetimes
+
+
+ .. attribute:: force_year
+
+ int or None; if set, forces the :attr:`~datetime.datetime.year` of generated datetime.
+
+ .. attribute:: force_month
+
+ int or None; if set, forces the :attr:`~datetime.datetime.month` of generated datetime.
+
+ .. attribute:: force_day
+
+ int or None; if set, forces the :attr:`~datetime.datetime.day` of generated datetime.
+
+ .. attribute:: force_hour
+
+ int or None; if set, forces the :attr:`~datetime.datetime.hour` of generated datetime.
+
+ .. attribute:: force_minute
+
+ int or None; if set, forces the :attr:`~datetime.datetime.minute` of generated datetime.
+
+ .. attribute:: force_second
+
+ int or None; if set, forces the :attr:`~datetime.datetime.second` of generated datetime.
+
+ .. attribute:: force_microsecond
+
+ int or None; if set, forces the :attr:`~datetime.datetime.microsecond` of generated datetime.
+
Custom fuzzy fields
-------------------