blob: 4d06fda6cc8d8ff77babf6c6d20a543e7b8032a9 (
plain)
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
|
#!/usr/bin/python
import os
import re
from io import open
reportPath = os.getcwd() + "/platform/android/MapboxGLAndroidSDK/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"
with open(reportPath, 'r', encoding='utf-8') as jacocoReport:
line = jacocoReport.readline().strip()
# find the last INSTRUCTION coverage report which is a sum of all separate ones
instructionIndex = line.rfind('type="INSTRUCTION"')
startIndex = line.find('missed', instructionIndex)
endIndex = line.find('/>', startIndex)
# find the missed and covered lines counts
numbers = re.match(r'missed="(\d+)" covered="(\d+)"', line[startIndex:endIndex])
missed = int(numbers.group(1))
covered = int(numbers.group(2))
# calculate the code coverage percentage
percentage = round(covered * 100.0 / (missed + covered), 2)
print("Android tests code coverage: %s%%" % (str(percentage)))
# invoke the script that send the data to s3
testEnvironment = "LOCAL"
if os.environ.get('IS_LOCAL_DEVELOPMENT').lower()=='false':
testEnvironment = "CI"
cmd = os.getcwd() + ("/scripts/code-coverage.sh %.2f %s %s" % (percentage, "Android", testEnvironment))
os.system(cmd)
|