Skip to content

Commit 811825b

Browse files
author
Chris Elion
authored
enforce min coverage % (#3642)
1 parent c888713 commit 811825b

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

.yamato/com.unity.ml-agents-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ test_editors:
22
- version: 2018.4
33
# 2018.4 doesn't support code-coverage
44
coverageOptions:
5+
minCoveragePct: 0
56
- version: 2019.3
67
coverageOptions: --enable-code-coverage --code-coverage-options 'generateHtmlReport;assemblyFilters:+Unity.ML-Agents'
8+
minCoveragePct: 72
79
- version: 2020.1
810
coverageOptions: --enable-code-coverage --code-coverage-options 'generateHtmlReport;assemblyFilters:+Unity.ML-Agents'
11+
minCoveragePct: 72
912
test_platforms:
1013
- name: win
1114
type: Unity::VM
@@ -32,6 +35,7 @@ test_{{ platform.name }}_{{ editor.version }}:
3235
commands:
3336
- npm install upm-ci-utils@stable -g --registry https://api.bintray.com/npm/unity/unity-npm
3437
- upm-ci package test -u {{ editor.version }} --package-path com.unity.ml-agents {{ editor.coverageOptions }}
38+
- python ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ editor.minCoveragePct }}
3539
artifacts:
3640
logs:
3741
paths:
@@ -42,6 +46,7 @@ test_{{ platform.name }}_{{ editor.version }}:
4246
changes:
4347
only:
4448
- "com.unity.ml-agents/**"
49+
- "ml-agents/tests/yamato/**"
4550
- ".yamato/com.unity.ml-agents-test.yml"
4651

4752
{% endfor %}

com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public StackingSensor(ISensor wrapped, int numStackedObservations)
6464

6565
public int Write(WriteAdapter adapter)
6666
{
67-
// First, call the wrapped sensor's write method. Make sure to use our own adapater, not the passed one.
67+
// First, call the wrapped sensor's write method. Make sure to use our own adapter, not the passed one.
6868
var wrappedShape = m_WrappedSensor.GetObservationShape();
6969
m_LocalAdapter.SetTarget(m_StackedObservations[m_CurrentIndex], wrappedShape, 0);
7070
m_WrappedSensor.Write(m_LocalAdapter);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from __future__ import print_function
2+
import sys
3+
import os
4+
5+
SUMMARY_XML_FILENAME = "Summary.xml"
6+
7+
# Note that this is python2 compatible, since that's currently what's installed on most CI images.
8+
9+
10+
def check_coverage(root_dir, min_percentage):
11+
# Walk the root directory looking for the summary file that
12+
# is output by ther code coverage checks. It's possible that
13+
# we'll need to refine this later in case there are multiple
14+
# such files.
15+
summary_xml = None
16+
for dirpath, _, filenames in os.walk(root_dir):
17+
if SUMMARY_XML_FILENAME in filenames:
18+
summary_xml = os.path.join(dirpath, SUMMARY_XML_FILENAME)
19+
break
20+
if not summary_xml:
21+
print("Couldn't find {} in root directory".format(SUMMARY_XML_FILENAME))
22+
sys.exit(1)
23+
24+
with open(summary_xml) as f:
25+
# Rather than try to parse the XML, just look for a line of the form
26+
# <Linecoverage>73.9</Linecoverage>
27+
lines = f.readlines()
28+
for l in lines:
29+
if "Linecoverage" in l:
30+
pct = l.replace("<Linecoverage>", "").replace("</Linecoverage>", "")
31+
pct = float(pct)
32+
if pct < min_percentage:
33+
print(
34+
"Coverage {} is below the min percentage of {}.".format(
35+
pct, min_percentage
36+
)
37+
)
38+
sys.exit(1)
39+
else:
40+
print(
41+
"Coverage {} is above the min percentage of {}.".format(
42+
pct, min_percentage
43+
)
44+
)
45+
sys.exit(0)
46+
47+
# Couldn't find the results in the file.
48+
print("Couldn't find Linecoverage in summary file")
49+
sys.exit(1)
50+
51+
52+
def main():
53+
root_dir = sys.argv[1]
54+
min_percent = float(sys.argv[2])
55+
if min_percent > 0:
56+
# This allows us to set 0% coverage on 2018.4
57+
check_coverage(root_dir, min_percent)
58+
59+
60+
if __name__ == "__main__":
61+
main()

0 commit comments

Comments
 (0)