diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-04-11 23:59:32 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-04-11 23:59:32 +0200 |
commit | 54971381fb31167d1f47b5e705480e044d702602 (patch) | |
tree | e5474cf88b5eca77515ee8fd72c84d87971b6494 /docs | |
parent | 8c1784e8c1eac65f66b4a1ecc4b8b0ddd5de9327 (diff) | |
download | factory-boy-54971381fb31167d1f47b5e705480e044d702602.tar factory-boy-54971381fb31167d1f47b5e705480e044d702602.tar.gz |
Add factory.fuzzy (Closes #41).
Diffstat (limited to 'docs')
-rw-r--r-- | docs/changelog.rst | 3 | ||||
-rw-r--r-- | docs/fuzzy.rst | 88 |
2 files changed, 89 insertions, 2 deletions
diff --git a/docs/changelog.rst b/docs/changelog.rst index 4b24797..100952c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,8 +4,6 @@ ChangeLog 2.0.0 (current) --------------- -.. note:: This section lists features planned for v2 of factory_boy. Changes announced here may not have been committed to the repository. - *New:* - Allow overriding the base factory class for :func:`~factory.make_factory` and friends. @@ -15,6 +13,7 @@ ChangeLog the associated class' constructor - Add support for ``get_or_create`` in :class:`~factory.DjangoModelFactory`, through :attr:`~factory.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE`. + - Add support for :mod:`~factory.fuzzy` attribute definitions. *Removed:* diff --git a/docs/fuzzy.rst b/docs/fuzzy.rst new file mode 100644 index 0000000..f1f4085 --- /dev/null +++ b/docs/fuzzy.rst @@ -0,0 +1,88 @@ +Fuzzy attributes +================ + +.. module:: factory.fuzzy + +Some tests may be interested in testing with fuzzy, random values. + +This is handled by the :mod:`factory.fuzzy` module, which provides a few +random declarations. + + +FuzzyAttribute +-------------- + + +.. class:: FuzzyAttribute + + The :class:`FuzzyAttribute` uses an arbitrary callable as fuzzer. + It is expected that successive calls of that function return various + values. + + .. attribute:: fuzzer + + The callable that generates random values + + +FuzzyChoice +----------- + + +.. class:: FuzzyChoice(choices) + + The :class:`FuzzyChoice` fuzzer yields random choices from the given + iterable. + + .. note:: The passed in :attr:`choices` will be converted into a list at + declaration time. + + .. attribute:: choices + + The list of choices to select randomly + + +FuzzyInteger +------------ + +.. class:: FuzzyInteger(low[, high]) + + The :class:`FuzzyInteger` 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 + + >>> FuzzyInteger(0, 42) + >>> fi.low, fi.high + 0, 42 + + >>> fi = FuzzyInteger(42) + >>> fi.low, fi.high + 0, 42 + + .. attribute:: low + + int, the inclusive lower bound of generated integers + + .. attribute:: high + + int, the inclusive higher bound of generated integers + + +Custom fuzzy fields +------------------- + +Alternate fuzzy fields may be defined. +They should inherit from the :class:`BaseFuzzyAttribute` class, and override its +:meth:`~BaseFuzzyAttribute.fuzz` method. + + +.. class:: BaseFuzzyAttribute + + Base class for all fuzzy attributes. + + .. method:: fuzz(self) + + The method responsible for generating random values. + *Must* be overridden in subclasses. |