Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def report_coverage(lcov_filename):
with open(lcov_filename, "r") as file_obj:
contents = file_obj.read()
converter = lcov_cobertura.LcovCobertura(contents)
cobertura_xml = converter.convert()
with tempfile.NamedTemporaryFile(mode="w+") as file_obj:
file_obj.write(cobertura_xml)
file_obj.seek(0)
report = file_obj.name
cobertura = pycobertura.Cobertura(report)
reporter = pycobertura.TextReporter(cobertura)
print(reporter.generate())
# The status code will be the number of files under the
# threshold.
return sum(
cobertura.line_rate(source_file) < THRESHOLD
for source_file in cobertura.files()
)