aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2016-02-10 00:07:32 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2016-02-10 00:07:32 +0100
commit8269885f9a71850838ee003627bcfd6d6d53e2ee (patch)
treefdac4f0e88872496842e6578044d87e5f18a9ac1 /tests
parent2eb8242a31f303d36c15b4644c54afb2cef8257e (diff)
downloadfactory-boy-8269885f9a71850838ee003627bcfd6d6d53e2ee.tar
factory-boy-8269885f9a71850838ee003627bcfd6d6d53e2ee.tar.gz
fuzzy: Fix decimal.FloatOperation warning (Closes #261)
Under Python 2.7+, the previous versions was directly casting fuzzy Decimal values into a float, which led to warnings in code trying to avoid such conversions in its tested code. Since we're just building random values, that behavior led to false positives or required jumping through weird hoops whenever a FuzzyDecimal was used. We now go trough a ``str()`` call to avoid such warnings.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_fuzzy.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/test_fuzzy.py b/tests/test_fuzzy.py
index 3f9c434..d83f3dd 100644
--- a/tests/test_fuzzy.py
+++ b/tests/test_fuzzy.py
@@ -189,6 +189,18 @@ class FuzzyDecimalTestCase(unittest.TestCase):
self.assertEqual(decimal.Decimal('8.001').quantize(decimal.Decimal(10) ** -3), res)
+ def test_no_approximation(self):
+ """We should not go through floats in our fuzzy calls unless actually needed."""
+ fuzz = fuzzy.FuzzyDecimal(0, 10)
+
+ decimal_context = decimal.getcontext()
+ old_traps = decimal_context.traps[decimal.FloatOperation]
+ try:
+ decimal_context.traps[decimal.FloatOperation] = True
+ fuzz.evaluate(2, None, None)
+ finally:
+ decimal_context.traps[decimal.FloatOperation] = old_traps
+
class FuzzyDateTestCase(unittest.TestCase):
@classmethod