Exemplo n.º 1
0
 def test_to_compressed_string(self):
   tests = [
     (None, None),
     ("", None),
     ("   ", None),
     ("a", "a"),
     (" a", "a"),
     ("a ", "a"),
     (" a  ", "a"),
     ("a b", "a b"),
     ("a  b c", "a b c"),
     ("  a  b   c d    ", "a b c d")
   ]
   for i, o in tests:
     self.assertEqual(cv.to_compressed_string(i), o)
   self.assertEqual(cv.to_compressed_string("  a  b cd ", 5), "a b c")
Exemplo n.º 2
0
 def reduce_value(cls, value):
   """Cleans the value by either compressing it if it is a string, or reducing it if it is a
   number.
   """
   if isinstance(value, str):
     return to_compressed_string(value)
   elif isinstance(value, bool):
     return value
   elif isinstance(value, Number):
     return reduce_number(value)
   else:
     return value