Commits

Mike Bayer  committed 7308039 Merge

Merged in dairiki/dogpile.cache/ticket-57 (pull request #13)

coerce_string_conf: coerce floats too

  • Participants
  • Parent commits 9a24cb3, 824df52

Comments (0)

Files changed (2)

File dogpile/cache/util.py

         v = v.strip()
         if re.match(r'^[-+]?\d+$', v):
             result[k] = int(v)
+        elif re.match(r'^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$', v):
+            result[k] = float(v)
         elif v.lower() in ('false', 'true'):
             result[k] = v.lower() == 'true'
         elif v == 'None':

File tests/cache/test_utils.py

         settings = {'expiration_time': '+1'}
         coerced = util.coerce_string_conf(settings)
         self.assertEqual(coerced['expiration_time'], 1)
+        self.assertEqual(type(coerced['expiration_time']), int)
+
+        settings = {'arguments.lock_sleep': '0.1'}
+        coerced = util.coerce_string_conf(settings)
+        self.assertEqual(coerced['arguments.lock_sleep'], 0.1)
+
+        settings = {'arguments.lock_sleep': '-3.14e-10'}
+        coerced = util.coerce_string_conf(settings)
+        self.assertEqual(coerced['arguments.lock_sleep'], -3.14e-10)