From a48f6482f21994a44da14dafdeff8e7e1237cec9 Mon Sep 17 00:00:00 2001 From: Raphaƫl Barrois Date: Sun, 21 Apr 2013 19:35:43 +0200 Subject: Add FuzzyDateTime/FuzzyNaiveDateTime. --- docs/fuzzy.rst | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/fuzzy.rst b/docs/fuzzy.rst index 7d56995..d88cb5a 100644 --- a/docs/fuzzy.rst +++ b/docs/fuzzy.rst @@ -94,7 +94,136 @@ FuzzyDate :class:`datetime.date`, the inclusive higher bound of generated dates - int, 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 -- cgit v1.2.3