Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_cobertura(xml=SOURCE_FILE, *args, **kwargs):
from pycobertura import Cobertura
cobertura = Cobertura(xml, *args, **kwargs)
return cobertura
def test_parse_path():
from pycobertura import Cobertura
xml_path = 'foo.xml'
with mock.patch('pycobertura.cobertura.os.path.exists', return_value=True):
with mock.patch('pycobertura.cobertura.ET.parse') as mock_parse:
cobertura = Cobertura(xml_path)
assert cobertura.xml is mock_parse.return_value.getroot.return_value
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()
)