diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index e6bf7a9763..7ca8e837d0 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -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: diff --git a/common/lib/capa/capa/tests/test_responsetypes.py b/common/lib/capa/capa/tests/test_responsetypes.py index 50370a9586..1549dd277c 100644 --- a/common/lib/capa/capa/tests/test_responsetypes.py +++ b/common/lib/capa/capa/tests/test_responsetypes.py @@ -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%. diff --git a/common/lib/xmodule/xmodule/capa_base.py b/common/lib/xmodule/xmodule/capa_base.py index 53b87d659f..cb129538c3 100644 --- a/common/lib/xmodule/xmodule/capa_base.py +++ b/common/lib/xmodule/xmodule/capa_base.py @@ -1214,12 +1214,15 @@ class CapaMixin(ScorableXBlockMixin, CapaFields): # Too late. Cannot submit if self.closed(): - problem_location = text_type(self.location) - if 'HarvardX+MCB80.1x+3T2019' in problem_location: - log.info( - 'Problem %s closed, close date: %s, attempts: %s/%s, is_past_due: %s', - problem_location, self.close_date, self.attempts, self.max_attempts, self.is_past_due() - ) + log.error( + 'ProblemClosedError: Problem %s, close date: %s, due:%s, attempts: %s/%s, is_past_due: %s', + text_type(self.location), + self.close_date, + self.due, + self.is_past_due(), + self.attempts, + self.max_attempts, + ) event_info['failure'] = 'closed' self.track_function_unmask('problem_check_fail', event_info) raise NotFoundError(_("Problem is closed."))