1. Mike Bayer
  2. dogpile.cache

Commits

dairiki  committed 824df52

util.coerce_string_conf: coerce floats too (#57)

  • Participants
  • Parent commits 9a24cb3
  • Branches master

Comments (0)

Files changed (2)

File dogpile/cache/util.py

View file
  • Ignore whitespace
         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

View file
  • Ignore whitespace
         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)