raise helpful error in NumericalResponse when missing required "answer" attribute

This commit is contained in:
ichuang
2012-06-04 18:13:49 -04:00
parent 613ff49df9
commit b36d0dd907

View File

@@ -185,6 +185,10 @@ class OptionResponse(GenericResponse):
class NumericalResponse(GenericResponse):
def __init__(self, xml, context, system=None):
self.xml = xml
if not xml.get('answer'):
msg = "Error in problem specification: numericalresponse missing required answer attribute\n"
msg += "See XML source line %s" % getattr(xml,'sourceline','<unavailable>')
raise Exception,msg
self.correct_answer = contextualize_text(xml.get('answer'), context)
try:
self.tolerance_xml = xml.xpath('//*[@id=$id]//responseparam[@type="tolerance"]/@default',