Browse Source

Py2.6: Decimal(float(f)) must be Decimal(str(float(f))

Ask Solem 11 years ago
parent
commit
f856a41e56
1 changed files with 10 additions and 2 deletions
  1. 10 2
      celery/tests/events/test_state.py

+ 10 - 2
celery/tests/events/test_state.py

@@ -20,6 +20,14 @@ from celery.five import range
 from celery.utils import uuid
 from celery.tests.case import AppCase, patch
 
+try:
+    Decimal(2.6)
+except TypeError:  # pragma: no cover
+    # Py2.6: Must first convert float to str
+    _float_to_decimal = str
+else:
+    _float_to_decimal = lambda f: f  # noqa
+
 
 class replay(object):
 
@@ -174,12 +182,12 @@ class test_Worker(AppCase):
 
     def test_compatible_with_Decimal(self):
         w = Worker('george@vandelay.com')
-        timestamp, local_received = Decimal(time()), time()
+        timestamp, local_received = Decimal(_float_to_decimal(time())), time()
         w.event('worker-online', timestamp, local_received, fields={
             'hostname': 'george@vandelay.com',
             'timestamp': timestamp,
             'local_received': local_received,
-            'freq': Decimal(5.6335431),
+            'freq': Decimal(_float_to_decimal(5.6335431)),
         })
         self.assertTrue(w.alive)