Skip to content

Commit 358e538

Browse files
authored
Added code-coverage.yml using codecov (pytorch#1665)
* Create code-coverage.yml * Update code-coverage.yml * Update code-coverage.yml * Update code-coverage.yml * Update code-coverage.yml * update test * fixed python code coverage * push * push * test * push' * Update code-coverage.yml * changed naming * Update modelarchiver_utils.py * Update frontend_utils.py * Update code-coverage.yml * Update frontend_utils.py * Update frontend_utils.py * put coverage in GPU CI action * codecov.yml * Update ci_cpu.yml * removed deprecated install file * Update backend_utils.py * Update backend_utils.py
1 parent dc3ce2c commit 358e538

7 files changed

+37
-40
lines changed

.github/workflows/ci_cpu.yml

+8
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,13 @@ jobs:
4040
python torchserve_sanity.py
4141
- name: mvn install
4242
run: cd serving-sdk/ && mvn clean install -q && cd ../
43+
44+
# Any coverage.xml will be picked up by this step
45+
# Just make sure each coverage.xml is in a different folder
46+
- name: Upload codecov
47+
run : |
48+
curl -Os https://uploader.codecov.io/latest/linux/codecov
49+
chmod +x codecov
50+
./codecov
4351
4452

.github/workflows/ci_gpu.yml

+8
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,11 @@ jobs:
4444
- name: mvn install
4545
run: cd serving-sdk/ && mvn clean install -q && cd ../
4646

47+
# Any coverage.xml will be picked up by this step
48+
# Just make sure each coverage.xml is in a different folder
49+
- name: Upload codecov
50+
run : |
51+
curl -Os https://uploader.codecov.io/latest/linux/codecov
52+
chmod +x codecov
53+
./codecov
54+

codecov.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage:
2+
range: 42..100
3+
round: down
4+
precision: 2

ts_scripts/backend_utils.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ def test_torchserve():
66
# Lint Test
77
print("## Started torchserve linting")
88
ts_dir = os.path.join("ts", ".")
9-
rc_file_path = os.path.join(".", "ts", "tests", "pylintrc")
10-
py_lint_cmd = f"pylint -rn --rcfile={rc_file_path} {ts_dir}"
11-
print(f"## In directory: {os.getcwd()} | Executing command: {py_lint_cmd}")
12-
py_lint_exit_code = os.system(py_lint_cmd)
139

1410
# Execute python tests
1511
print("## Started torchserve pytests")
1612
test_dir = os.path.join("ts", "tests", "unit_tests")
1713
coverage_dir = os.path.join("ts")
18-
results_dir_name = "result_units"
19-
py_test_cmd = f"python -m pytest --cov-report html:{results_dir_name} --cov={coverage_dir} {test_dir}"
20-
print(f"## In directory: {os.getcwd()} | Executing command: {py_test_cmd}")
21-
py_test_exit_code = os.system(py_test_cmd)
14+
report_output_dir = os.path.join(test_dir, "coverage.xml")
2215

23-
if py_lint_exit_code != 0:
24-
print("## TorchServe Linting Failed !")
25-
if py_test_exit_code != 0:
16+
ts_test_cmd = f"python -m pytest --cov-report xml:{report_output_dir} --cov={coverage_dir} {test_dir}"
17+
print(f"## In directory: {os.getcwd()} | Executing command: {ts_test_cmd}")
18+
ts_test_error_code = os.system(ts_test_cmd)
19+
20+
if ts_test_error_code != 0:
2621
sys.exit("## TorchServe Pytests Failed !")

ts_scripts/install_utils

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,4 @@ run_markdown_link_checker(){
304304
done
305305
set -e
306306
exit $STATUS
307-
}
307+
}

ts_scripts/modelarchiver_utils.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
import os
22
import sys
33

4-
54
REPO_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
65
sys.path.append(REPO_ROOT)
76

87

98
def test_modelarchiver():
109
os.chdir("model-archiver")
1110

12-
# Lint test
13-
print("## Started model archiver linting")
14-
ma_dir = os.path.join("model_archiver", ".")
15-
rc_file_path = os.path.join(".", "model_archiver", "tests", "pylintrc")
16-
py_lint_cmd = f"pylint -rn --rcfile={rc_file_path} {ma_dir}"
17-
print(f"## In directory: {os.getcwd()} | Executing command: {py_lint_cmd}")
18-
py_lint_exit_code = os.system(py_lint_cmd)
19-
2011
# Execute python unit tests
2112
print("## Started model archiver pytests - unit tests")
2213
ut_dir = os.path.join("model_archiver", "tests", "unit_tests")
2314
coverage_dir = os.path.join(".")
24-
results_dir_name = "result_units"
25-
py_units_cmd = f"python -m pytest --cov-report html:{results_dir_name} --cov={coverage_dir} {ut_dir}"
15+
report_output_dir = os.path.join(ut_dir, "coverage.xml")
16+
17+
py_units_cmd = f"python -m pytest --cov-report xml:{report_output_dir} --cov={coverage_dir} {ut_dir}"
2618
print(f"## In directory: {os.getcwd()} | Executing command: {py_units_cmd}")
2719
py_units_exit_code = os.system(py_units_cmd)
2820

2921
# Execute integration tests
3022
print("## Started model archiver pytests - integration tests")
3123
it_dir = os.path.join("model_archiver", "tests", "integ_tests")
32-
py_integ_cmd = f"python -m pytest {it_dir}" # ToDo - Report for Integration tests ?
24+
report_output_dir = os.path.join(it_dir, "coverage.xml")
25+
26+
py_integ_cmd = f"python -m pytest --cov-report xml:{report_output_dir} --cov={coverage_dir} {it_dir}"
3327
print(f"## In directory: {os.getcwd()} | Executing command: {py_integ_cmd}")
3428
py_integ_exit_code = os.system(py_integ_cmd)
3529

36-
if py_lint_exit_code != 0:
37-
print("## Model archiver Linting Failed !")
3830
if py_units_exit_code != 0:
3931
sys.exit("## Model archiver Unit Pytests Failed !")
4032
if py_integ_exit_code != 0:

ts_scripts/workflow_archiver_utils.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
11
import os
22
import sys
33

4-
54
REPO_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
65
sys.path.append(REPO_ROOT)
76

87

98
def test_workflow_archiver():
109
os.chdir("workflow-archiver")
1110

12-
# Lint test
13-
print("## Started model archiver linting")
14-
workflow_archiver_dir = os.path.join("workflow_archiver", ".")
15-
rc_file_path = os.path.join(".", "workflow_archiver", "tests", "pylintrc")
16-
py_lint_cmd = f"pylint -rn --rcfile={rc_file_path} {workflow_archiver_dir}"
17-
print(f"## In directory: {os.getcwd()} | Executing command: {py_lint_cmd}")
18-
py_lint_exit_code = os.system(py_lint_cmd)
19-
2011
# Execute python unit tests
2112
print("## Started workflow archiver pytests - unit tests")
2213
ut_dir = os.path.join("workflow_archiver", "tests", "unit_tests")
2314
coverage_dir = os.path.join(".")
24-
results_dir_name = "result_units"
25-
py_units_cmd = f"python -m pytest --cov-report html:{results_dir_name} --cov={coverage_dir} {ut_dir}"
15+
report_output_dir = os.path.join(ut_dir, "coverage.xml")
16+
py_units_cmd = f"python -m pytest --cov-report xml:{report_output_dir} --cov={coverage_dir} {ut_dir}"
2617
print(f"## In directory: {os.getcwd()} | Executing command: {py_units_cmd}")
2718
py_units_exit_code = os.system(py_units_cmd)
2819

2920
# Execute integration tests
3021
print("## Started workflow archiver pytests - integration tests")
3122
it_dir = os.path.join("workflow_archiver", "tests", "integ_tests")
32-
py_integ_cmd = f"python -m pytest {it_dir}" # ToDo - Report for Integration tests ?
23+
report_output_dir = os.path.join(it_dir, "coverage.xml")
24+
py_integ_cmd = f"python -m pytest --cov-report xml:{report_output_dir} --cov={coverage_dir} {it_dir}"
3325
print(f"## In directory: {os.getcwd()} | Executing command: {py_integ_cmd}")
3426
py_integ_exit_code = os.system(py_integ_cmd)
3527

36-
if py_lint_exit_code != 0:
37-
print("## Workflow archiver Linting Failed !")
3828
if py_units_exit_code != 0:
3929
sys.exit("## Workflow archiver Unit Pytests Failed !")
4030
if py_integ_exit_code != 0:

0 commit comments

Comments
 (0)