diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-01-22 22:47:11 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-01-22 22:47:43 +0100 |
commit | 39383fea8bd5bd58b063d9c9fbb44301e781fd80 (patch) | |
tree | 82a42004c0ef1ad0f1e132399d426354b3ea080c /factory | |
parent | 8639d0f70b03acd0cd76f1c81207461e185f8615 (diff) | |
download | factory-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.py | 17 |
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.""" |