forked from aws/aws-encryption-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetCodeCoverage.py
46 lines (38 loc) · 1.7 KB
/
GetCodeCoverage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
import os
from xml.etree import ElementTree
ROOT_DIR = os.path.join("Test", "TestResults")
LINE_COVERAGE_MINIMUM = .80
BRANCH_COVERAGE_MINIMUM = .35
def check_coverage():
if float(get_overall_coverage_rate('line-rate')) < LINE_COVERAGE_MINIMUM:
print_overall_coverage_rate('line-rate')
raise Exception(f'Line code coverage does not meet minimum threshold of {LINE_COVERAGE_MINIMUM:f}')
if float(get_overall_coverage_rate('branch-rate')) < BRANCH_COVERAGE_MINIMUM:
print_overall_coverage_rate('branch-rate')
raise Exception(f'Branch code coverage does not meet minimum threshold of {BRANCH_COVERAGE_MINIMUM:f}')
def get_overall_coverage_rate(coverage_type):
"""
Return overall line/branch coverage rate of AWSEncryptionSDKTests
based on which type (line-rate/branch-rate) the user asked for.
"""
coverage = ElementTree.parse(os.path.join(ROOT_DIR, 'coverage.cobertura.xml'))
root = coverage.getroot()
for child in root.iter('package'):
if child.get('name') == 'AWSEncryptionSDKTests':
return child.get(coverage_type)
def print_overall_coverage_rate(coverage_type):
"""Print overall coverage rate to console"""
print(coverage_type, get_overall_coverage_rate(coverage_type))
def get_coverage_report():
"""Print code coverage summary to console."""
with open(os.path.join(ROOT_DIR, 'Summary.txt')) as file:
print(file.read())
def main():
get_coverage_report()
check_coverage()
print_overall_coverage_rate('line-rate')
print_overall_coverage_rate('branch-rate')
if __name__ == "__main__":
main()