Skip to content

Commit 03bf0d3

Browse files
authored
Add testing script for local lint and python test. (#3797)
* Add presubmit testing script for local testing. * Update the test script to be more modularized. 1. Check the script file location and cd into repo root dir. 2. Allow caller to call differnt tests.
1 parent 684a161 commit 03bf0d3

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# Presubmit script that run tests and lint under local environment.
4+
# Make sure that tensorflow and pylint is installed.
5+
# usage: models >: ./official/utils/testing/scripts/presubmit.sh
6+
# usage: models >: ./official/utils/testing/scripts/presubmit.sh lint py2_test py3_test
7+
set +x
8+
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
cd "$SCRIPT_DIR/../../../.."
11+
MODEL_ROOT="$(pwd)"
12+
13+
export PYTHONPATH="$PYTHONPATH:${MODEL_ROOT}"
14+
15+
cd official
16+
17+
lint() {
18+
local exit_code=0
19+
20+
RC_FILE="utils/testing/pylint.rcfile"
21+
22+
echo "===========Running lint test============"
23+
for file in `find . -name '*.py' ! -name '*test.py' -print`
24+
do
25+
echo "Linting ${file}"
26+
pylint --rcfile="${RC_FILE}" "${file}" || exit_code=$?
27+
done
28+
29+
# More lenient for test files.
30+
for file in `find . -name '*test.py' -print`
31+
do
32+
echo "Linting ${file}"
33+
pylint --rcfile="${RC_FILE}" --disable=missing-docstring,protected-access "${file}" || exit_code=$?
34+
done
35+
36+
return "${exit_code}"
37+
}
38+
39+
py_test() {
40+
local PY_BINARY="$1"
41+
local exit_code=0
42+
43+
echo "===========Running Python test============"
44+
45+
for test_file in `find . -name '*test.py' -print`
46+
do
47+
echo "Testing ${test_file}"
48+
${PY_BINARY} "${test_file}" || exit_code=$?
49+
done
50+
51+
return "${exit_code}"
52+
}
53+
54+
py2_test() {
55+
local PY_BINARY=$(which python2)
56+
return $(py_test "${PY_BINARY}")
57+
}
58+
59+
py3_test() {
60+
local PY_BINARY=$(which python3)
61+
return $(py_test "${PY_BINARY}")
62+
}
63+
64+
test_result=0
65+
66+
if [ "$#" -eq 0 ]; then
67+
TESTS="lint py2_test py3_test"
68+
else
69+
TESTS="$@"
70+
fi
71+
72+
for t in "${TESTS}"; do
73+
${t} || test_result=$?
74+
done
75+
76+
exit "${test_result}"

0 commit comments

Comments
 (0)