bug: fix an edge case in capa problem tolerance
PROD-1586
This commit is contained in:
@@ -1551,7 +1551,7 @@ class NumericalResponse(LoncapaResponse):
|
||||
id=xml.get('id')
|
||||
)
|
||||
if tolerance_xml: # If it isn't an empty list...
|
||||
self.tolerance = contextualize_text(tolerance_xml[0], context)
|
||||
self.tolerance = contextualize_text(tolerance_xml[0].strip(), context)
|
||||
|
||||
def get_staff_ans(self, answer):
|
||||
"""
|
||||
@@ -3057,7 +3057,7 @@ class FormulaResponse(LoncapaResponse):
|
||||
id=xml.get('id')
|
||||
)
|
||||
if tolerance_xml: # If it isn't an empty list...
|
||||
self.tolerance = contextualize_text(tolerance_xml[0], context)
|
||||
self.tolerance = contextualize_text(tolerance_xml[0].strip(), context)
|
||||
|
||||
types = xml.get('type')
|
||||
if types is None:
|
||||
|
||||
@@ -1515,6 +1515,15 @@ class NumericalResponseTest(ResponseTest): # pylint: disable=missing-class-docs
|
||||
incorrect_responses = ["", "3.01", "-1.01"]
|
||||
self.assert_multiple_grade(problem, correct_responses, incorrect_responses)
|
||||
|
||||
def test_grade_percent_tolerance_with_spaces(self):
|
||||
"""
|
||||
Tests that system does not throw an error when tolerance data contains spaces before or after.
|
||||
"""
|
||||
problem = self.build_problem(answer=4, tolerance="10% ")
|
||||
correct_responses = ["4.0", "4.00", "4.39", "3.61"]
|
||||
incorrect_responses = ["", "4.41", "3.59", "0"]
|
||||
self.assert_multiple_grade(problem, correct_responses, incorrect_responses)
|
||||
|
||||
def test_floats(self):
|
||||
"""
|
||||
Default tolerance for all responsetypes is 1e-3%.
|
||||
|
||||
Reference in New Issue
Block a user