Skip to content

Commit

Permalink
coverage: Handle no modules
Browse files Browse the repository at this point in the history
If you run coverage and there are no modules documented, we currently
exit with a ZeroDivision error. Resolve this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
stephenfin committed Sep 5, 2023
1 parent 4f1b283 commit 31829a9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sphinx/ext/coverage.py
Expand Up @@ -362,11 +362,15 @@ def _write_py_statistics(self, op: TextIO) -> None:
value = 100.0

table.append([module, '%.2f%%' % value, '%d' % len(self.py_undocumented[module])])
table.append([
'TOTAL',
f'{100 * len(all_documented_objects) / len(all_objects):.2f}%',
f'{len(all_objects) - len(all_documented_objects)}',
])

if len(all_objects):
table.append([
'TOTAL',
f'{100 * len(all_documented_objects) / len(all_objects):.2f}%',
f'{len(all_objects) - len(all_documented_objects)}',
])
else:
table.append(['TOTAL', '100', '0'])

for line in _write_table(table):
op.write(f'{line}\n')
Expand Down

0 comments on commit 31829a9

Please sign in to comment.