Example #1
0
    def test_split_alphanumeric_string(self):
        """Test the alpha-numeric split function."""
        s = "4 GiB"

        expected = ["4 ", "GiB"]
        result = list(common_utils.split_alphanumeric_string(s))
        self.assertEqual(result, expected)
Example #2
0
 def _process_memory_value(self, data):
     """Parse out value and unit from memory strings."""
     if "memory" in data and data["memory"] is not None:
         unit = None
         try:
             memory = float(data["memory"])
         except ValueError:
             memory = None
             # Memory can come as a single number or a number with a unit
             # e.g. "1", "1GB", "1 Gb" so it gets special cased.
             memory_list = list(split_alphanumeric_string(data["memory"]))
             if memory_list:
                 memory = memory_list[0]
                 if len(memory_list) > 1:
                     unit = memory_list[1]
         try:
             memory = float(memory)
         except (ValueError, TypeError):
             memory = None
             unit = None
         data["memory"] = memory
         data["memory_unit"] = unit
     return data