Skip to content

Instantly share code, notes, and snippets.

@ilaif
Created April 16, 2019 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilaif/695673803fae63d7ff9cc2fa4c8ac869 to your computer and use it in GitHub Desktop.
Save ilaif/695673803fae63d7ff9cc2fa4c8ac869 to your computer and use it in GitHub Desktop.
instrument-everything-blog-calculate-coverage
def calculate_coverage(instrumentation_mappings, processed_logs):
"""
Given the parameters, returns a coverage object that contains the needed data for the report
:param dict instrumentation_mappings: a dictionary of
key: name, value: properties that includes instrumentation mappings
:param list processed_logs: a list of processed logs that contain the coverage information
:return dict: coverage object
"""
coverage_object = {}
files = {}
global_tested_line_count = 0
global_covered_line_count = 0
for name, vcl_mapping in instrumentation_mappings.items():
tested_line_count = vcl_mapping['tested_line_count']
original_content = vcl_mapping['original_content']
logs = logs_by_name_line[str(vcl_mapping['name_mapping'])]
covered_line_numbers = logs.keys()
covered_line_count = len(logs)
tested_line_numbers = vcl_mapping['tested_line_numbers']
uncovered_line_numbers = [line for line in tested_line_numbers if line not in covered_line_numbers]
files[name] = {
'name': name,
'coverage_line_percentage': calc_percentage(covered_line_count, tested_line_count),
'covered_line_count': covered_line_count,
'tested_line_count': tested_line_count,
'total_line_count': len(original_content.split('\n')),
'original_content': original_content,
'tested_line_numbers': tested_line_numbers,
'uncovered_line_numbers': uncovered_line_numbers,
'covered_line_numbers': covered_line_numbers
}
global_tested_line_count += tested_line_count
global_covered_line_count += covered_line_count
coverage_object['files'] = files
return coverage_object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment