diff --git a/src/validate.py b/src/validate.py index c8b1b3d..125adb5 100644 --- a/src/validate.py +++ b/src/validate.py @@ -56,27 +56,27 @@ def validate(unvalidated): # they need to appear in the template for arg in run["args"]: if arg not in t["args"]: - return None + raise Exception("Argument '{}' was not in the template {}'s arguments: {}".format(arg, run["template_type"], t["args"])) # and if the arg isn't in the run, # it needs to have a default for arg in t["args"]: if arg not in run["args"] and arg not in t["default_props"]: - return None + raise Exception("Argument '{}' did not have a default from template {}".format(arg, run["template_type"])) # for each template, - for template in d["TemplateData"].values(): + for name, template in d["TemplateData"].items(): # all of the translations need to refer to # arguments specified by the user if "translations" in template: for translation in template["translations"]: if translation not in template["args"]: - return None + raise Exception("Translation '{}' for template '{}' doesn't have an associated argument".format(translation, name)) # all of the annotations need to refer to # arguments specified by the user if "annotations" in template: for annotation in template["annotations"]: if annotation not in template["args"]: - return None + raise Exception("Annotation '{}' for template '{}' doesn't have an associated argument".format(annotation, name)) return d diff --git a/tests/test_validate.py b/tests/test_validate.py index db97e35..b4927d7 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -17,17 +17,18 @@ def test_invalid_config_does_not_validate(self): self.assertFalse(validate(j)) def test_TemplateData_with_extra_translations_dont_validate(self): - self.assertFalse(validate({ - "TemplateData": { - "example": { - "args": [], - "translations": { - "arg1": "someValue", + with self.assertRaises(Exception): + validate({ + "TemplateData": { + "example": { + "args": [], + "translations": { + "arg1": "someValue", + }, }, }, - }, - "RunList": [], - })) + "RunList": [], + }) def test_there_should_be_TemplateData_if_there_are_RunList(self): with self.assertRaises(Exception): @@ -42,64 +43,67 @@ def test_there_should_be_TemplateData_if_there_are_RunList(self): })) def test_RunList_with_extra_args_fail_to_validate(self): - self.assertFalse(validate({ - "TemplateData": { - "example": { - "args": [], - "translations": { - "arg1": "someValue", + with self.assertRaises(Exception): + validate({ + "TemplateData": { + "example": { + "args": [], + "translations": { + "arg1": "someValue", + }, }, }, - }, - "RunList": [ - { - "template_type": "example", - "args": { - "a": "b", - "arg1": 5, - }, - } - ], - })) + "RunList": [ + { + "template_type": "example", + "args": { + "a": "b", + "arg1": 5, + }, + } + ], + }) def test_RunList_with_ommitted_with_no_defaults_fail_to_validate(self): - self.assertFalse(validate({ - "TemplateData": { - "example": { - "args": [ - "arg1", - "noDefaults", - ], - "translations": { - "arg1": "someValue", - }, - "default_props": { - "arg1": "defaultvalue", + with self.assertRaises(Exception): + validate({ + "TemplateData": { + "example": { + "args": [ + "arg1", + "noDefaults", + ], + "translations": { + "arg1": "someValue", + }, + "default_props": { + "arg1": "defaultvalue", + }, }, }, - }, - "RunList": [ - { - "template_type": "example", - "args": { - "arg1": 5, - }, - } - ], - })) + "RunList": [ + { + "template_type": "example", + "args": { + "arg1": 5, + }, + } + ], + }) def test_RunList_with_extra_annotations_fail_to_validate(self): - self.assertFalse(validate({ - "TemplateData": { - "example": { - "args": [ - "arg1", - ], - "annotations": { - "arg1": "someValue", - "extraAnnotation": "someValue", + with self.assertRaises(Exception): + validate({ + "TemplateData": { + "example": { + "args": [ + "arg1", + ], + "annotations": { + "arg1": "someValue", + "extraAnnotation": "someValue", + }, }, }, - }, - "RunList": [] - })) + "RunList": [] + })