Commit 3b30727c authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[trac926] spec check for python

parent bf635ee4
......@@ -229,7 +229,7 @@ def _check_item_spec(config_item):
item_type = config_item["item_type"]
if type(item_type) != str:
raise ModuleSpecError("item_type in " + item_name + " is not a string: " + str(type(item_type)))
if item_type not in ["integer", "real", "boolean", "string", "list", "map", "any"]:
if item_type not in ["integer", "real", "boolean", "string", "list", "map", "named_map", "any"]:
raise ModuleSpecError("unknown item_type in " + item_name + ": " + item_type)
if "item_optional" in config_item:
if type(config_item["item_optional"]) != bool:
......@@ -293,6 +293,10 @@ def _validate_type(spec, value, errors):
if errors != None:
errors.append(str(value) + " should be a map")
return False
elif data_type == "named_map" and type(value) != dict:
if errors != None:
errors.append(str(value) + " should be a map")
return False
else:
return True
......@@ -308,8 +312,16 @@ def _validate_item(spec, full, data, errors):
if not _validate_item(list_spec, full, data_el, errors):
return False
elif type(data) == dict:
if not _validate_spec_list(spec['map_item_spec'], full, data, errors):
return False
if 'map_item_spec' in spec:
if not _validate_spec_list(spec['map_item_spec'], full, data, errors):
return False
else:
named_map_spec = spec['named_map_item_spec']
for data_el in data.values():
if not _validate_type(named_map_spec, data_el, errors):
return False
if not _validate_item(named_map_spec, full, data_el, errors):
return False
return True
def _validate_spec(spec, full, data, errors):
......
......@@ -98,6 +98,9 @@ class TestModuleSpec(unittest.TestCase):
self.assertEqual(True, self.validate_data("spec22.spec", "data22_6.data"))
self.assertEqual(True, self.validate_data("spec22.spec", "data22_7.data"))
self.assertEqual(False, self.validate_data("spec22.spec", "data22_8.data"))
self.assertEqual(True, self.validate_data("spec32.spec", "data32_1.data"))
self.assertEqual(False, self.validate_data("spec32.spec", "data32_2.data"))
self.assertEqual(False, self.validate_data("spec32.spec", "data32_3.data"))
def validate_command_params(self, specfile_name, datafile_name, cmd_name):
dd = self.read_spec_file(specfile_name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment