From f9615543769ba5437fd2fe9ce7fd94d5ea423906 Mon Sep 17 00:00:00 2001 From: Elchanan Shuky Shukrun Date: Sun, 8 Aug 2021 23:11:35 +0300 Subject: [PATCH] fix divide by zero exception (#17) Fix bug where a value (e.g. enum) was specified with --kind but did not exist within the code. since p_total and l_total are 0 in this case, the divition rise exception. --- coverxygen/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coverxygen/__init__.py b/coverxygen/__init__.py index f52a2cf..a464bad 100644 --- a/coverxygen/__init__.py +++ b/coverxygen/__init__.py @@ -319,7 +319,7 @@ def calculate_totals(p_symbolKindCounts): return { "documented_symbol_count": l_totalDocumented, "symbol_count" : l_total, - "coverage_rate" : l_totalDocumented / l_total + "coverage_rate" : 0 if l_total == 0 else l_totalDocumented / l_total } @staticmethod @@ -419,7 +419,7 @@ def determine_first_column_width(p_symbolsKindCountsList): @staticmethod def print_summary_line(p_stream, p_header, p_headerWidth, p_count, p_total): - l_percentage = (p_count / p_total) * 100.0 + l_percentage = 0 if p_total == 0 else (p_count / p_total) * 100.0 p_stream.write("%s: %5.1f%% (%d/%d)\n" % (("%%-%ds" % (p_headerWidth)) % p_header, l_percentage, p_count, p_total))