summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2014-01-22 22:47:11 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2014-01-22 22:47:43 +0100
commit39383fea8bd5bd58b063d9c9fbb44301e781fd80 (patch)
tree82a42004c0ef1ad0f1e132399d426354b3ea080c /factory
parent8639d0f70b03acd0cd76f1c81207461e185f8615 (diff)
downloadfactory-boy-39383fea8bd5bd58b063d9c9fbb44301e781fd80.tar
factory-boy-39383fea8bd5bd58b063d9c9fbb44301e781fd80.tar.gz
fuzzy: Add FuzzyFloat (Closes #124).
As suggested by @savingschampion
Diffstat (limited to 'factory')
-rw-r--r--factory/fuzzy.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/factory/fuzzy.py b/factory/fuzzy.py
index 2ea544a..94599b7 100644
--- a/factory/fuzzy.py
+++ b/factory/fuzzy.py
@@ -141,6 +141,23 @@ class FuzzyDecimal(BaseFuzzyAttribute):
return base.quantize(decimal.Decimal(10) ** -self.precision)
+class FuzzyFloat(BaseFuzzyAttribute):
+ """Random float within a given range."""
+
+ def __init__(self, low, high=None, **kwargs):
+ if high is None:
+ high = low
+ low = 0
+
+ self.low = low
+ self.high = high
+
+ super(FuzzyFloat, self).__init__(**kwargs)
+
+ def fuzz(self):
+ return random.uniform(self.low, self.high)
+
+
class FuzzyDate(BaseFuzzyAttribute):
"""Random date within a given date range."""