Adding objectives validator

This commit is contained in:
John Donaldson 2019-08-14 23:55:37 +01:00
parent a99bc15c88
commit 470e01b437
1 changed files with 18 additions and 0 deletions

View File

@ -144,6 +144,24 @@ class MothValidator:
if ksa_re.match(ksa) is None: if ksa_re.match(ksa) is None:
raise MothValidationError("Unrecognized KSA format (%s)" % (ksa,)) raise MothValidationError("Unrecognized KSA format (%s)" % (ksa,))
@staticmethod
def check_success(puzzle):
"""Check if success criteria are defined"""
if not hasattr(puzzle, "success"):
raise MothValidationError("Success not defined")
criteria = ["acceptable", "mastery"]
missing_criteria = []
for criterion in criteria:
if criterion not in puzzle.success.keys() or \
puzzle.success[criterion] is None or \
len(puzzle.success[criterion]) == 0:
missing_criteria.append(criterion)
if len(missing_criteria) > 0:
raise MothValidationError("Missing success criteria (%s)" % (", ".join(missing_criteria)))
def output_json(data): def output_json(data):
"""Output results in JSON format""" """Output results in JSON format"""