Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions xblocks_contrib/problem/capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,10 @@ def get_display_progress(self):
progress = self.get_progress()
score, total = progress.frac() if progress else (0, 0)

# When the weight does not divide evenly between the questions, the score is a repeating
# fraction (e.g. 0.3333333333333333). This rounds it the same way `Progress.__str__` does.
score = round(score, 2)

# Withhold the score if hiding correctness
if not self.correctness_available():
score = None
Expand Down
18 changes: 18 additions & 0 deletions xblocks_contrib/problem/tests/test_capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,24 @@ def test_get_display_progress_show_correctness(self, show_correctness, is_correc
assert score == expected_score
assert total == 1

@ddt.data(
(1, 3, 0.33),
(2, 3, 0.67),
(1, 2, 0.5),
(3, 3, 1),
)
@ddt.unpack
def test_get_display_progress_rounds_the_score(self, raw_earned, raw_possible, expected_score):
"""
Check that the displayed score is rounded to at most two decimal places.
"""
block = CapaFactory.create(attempts=1)
block.weight = 1
block.score = Score(raw_earned=raw_earned, raw_possible=raw_possible)
score, total = block.get_display_progress()
assert score == expected_score
assert total == 1

def test_get_html(self):
"""
Check that get_html() calls get_progress() with no arguments.
Expand Down
Loading