Commit c5e0ce50 by Nimisha Asthagiri Committed by GitHub

Merge pull request #16218 from edx/naa/fix-grade-zero-error

Grades: Fix ZeroDivisionError
parents 17d93360 811ab640
......@@ -141,7 +141,10 @@ class NonZeroSubsectionGrade(SubsectionGradeBase):
@property
def percent_graded(self):
if self.graded_total.possible > 0:
return self.graded_total.earned / self.graded_total.possible
else:
return 0.0
@staticmethod
def _compute_block_score(
......
......@@ -36,3 +36,13 @@ class SubsectionGradeTest(GradeTestBase):
read_grade.all_total.first_attempted = created_grade.all_total.first_attempted = None
self.assertEqual(created_grade.all_total, read_grade.all_total)
self.assertEqual(created_grade.percent_graded, 0.5)
def test_zero(self):
with mock_get_score(1, 0):
grade = CreateSubsectionGrade(
self.sequence,
self.course_structure,
self.subsection_grade_factory._submissions_scores,
self.subsection_grade_factory._csm_scores,
)
self.assertEqual(grade.percent_graded, 0.0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment