Merge "Move print statments over to py3 style."
diff --git a/.coveragerc b/.coveragerc
index b730a35..7d1f7ac 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -8,7 +8,8 @@
# omit file patterns must be listed one per line. */.local/* /usr/*
omit =
*_test.py
-
-[html]
-directory = htmlcov
-
+ *__init__.py
+ *public/acloud_kernel/*
+ # TODO: Remove the bottom 2 when the files are deleted.
+ *public/__main__.py
+ *setup.py
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index 1bc9a7e..734a94d 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -1,6 +1,2 @@
[Builtin Hooks]
pylint = true
-
-[Hook Scripts]
-# TODO: Migrate these python unittests to host-based unittests presubmit.
-acloud_unittests = ${REPO_ROOT}/tools/acloud/run_tests.sh
diff --git a/run_tests.sh b/run_tests.sh
index 58e1c08..347061b 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -5,24 +5,14 @@
GREEN='\033[0;32m'
NC='\033[0m' # No Color
-if [ -z "$ANDROID_BUILD_TOP" ]; then
- echo "Missing ANDROID_BUILD_TOP env variable. Run 'lunch' first."
- exit 1
-fi
-
-function helper() {
- echo "usage: $0 [options]"
- echo " options:"
- echo " coverage, test all unit tests with coverage report"
-}
-
function print_summary() {
local test_results=$1
- local coverage_run=$2
- if [[ $coverage_run == "coverage" ]]; then
- PYTHONPATH=$(get_python_path) coverage report -m
- PYTHONPATH=$(get_python_path) coverage html
- fi
+ local tmp_dir=$(mktemp -d)
+ local rc_file=${ACLOUD_DIR}/.coveragerc
+ PYTHONPATH=$(get_python_path) python -m coverage report -m
+ PYTHONPATH=$(get_python_path) python -m coverage html -d $tmp_dir --rcfile=$rc_file
+ echo "coverage report available at file://${tmp_dir}/index.html"
+
if [[ $test_results -eq 0 ]]; then
echo -e "${GREEN}All unittests pass${NC}!"
else
@@ -31,38 +21,43 @@
}
function run_unittests() {
- local coverage_run=$1
- local run_cmd="python"
local rc=0
- if [[ $coverage_run == "coverage" ]]; then
- # clear previously collected coverage data.
- PYTHONPATH=$(get_python_path) coverage erase
- run_cmd="coverage run --append"
- fi
+ local run_cmd="python -m coverage run --append"
+
+ # clear previously collected coverage data.
+ PYTHONPATH=$(get_python_path) python -m coverage erase
# Runs all unit tests under tools/acloud.
for t in $(find $ACLOUD_DIR -type f -name "*_test.py");
do
- if ! PYTHONPATH=$(get_python_path) $run_cmd $t; then
+ if ! PYTHONPATH=$(get_python_path):$PYTHONPATH $run_cmd $t; then
rc=1
echo -e "${RED}$t failed${NC}"
fi
done
- print_summary $rc $coverage_run
+ print_summary $rc
exit $rc
}
+function check_env() {
+ if [ -z "$ANDROID_BUILD_TOP" ]; then
+ echo "Missing ANDROID_BUILD_TOP env variable. Run 'lunch' first."
+ exit 1
+ fi
-case "$1" in
- 'help')
- helper
- ;;
- 'coverage')
- run_unittests "coverage"
- ;;
- *)
- run_unittests
- ;;
-esac
+ local missing_py_packages=false
+ for py_lib in {absl-py,coverage,mock};
+ do
+ if ! pip list --format=legacy | grep $py_lib &> /dev/null; then
+ echo "Missing required python package: $py_lib (pip install $py_lib)"
+ missing_py_packages=true
+ fi
+ done
+ if $missing_py_packages; then
+ exit 1
+ fi
+}
+check_env
+run_unittests