File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed
official/utils/testing/scripts Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change
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}"
You can’t perform that action at this time.
0 commit comments