From f549be826c0bc36808464e637da4388fd82cf0fc Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Fri, 31 Jan 2020 10:50:47 -0800 Subject: [PATCH 01/10] bump up pytest and others --- scripts/requirements.txt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/requirements.txt b/scripts/requirements.txt index d457a52dcf..0998c06fa8 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -2,25 +2,26 @@ coremltools==3.1 scipy==1.2.1 numpy==1.16.4 cython==0.29.10 -argparse==1.2.1 decorator==4.4.0 -mock==3.0.5 -pytest==4.6.3 pandas==0.24.2 pillow==6.2.0 prettytable==0.7.2 pytz==2019.1 resampy==0.2.1 -requests>=2.9.1 scikit-learn==0.20.3 -six==1.12.0 statsmodels==0.9.0 tensorflow==2.0.0 -wheel==0.29.0 UISoup==2.5.7 pyobjc==5.2; sys_platform == 'darwin' future==0.17.1 pyOpenSSL==19.0.0 ndg-httpsclient==0.5.1 pyasn1==0.4.5 -hypothesis==4.24.3 +########## >= ######### +argparse>=1.2.1 +mock==3.0.5 +pytest>=4.6.3 +hypothesis>=4.24.3 +wheel>=0.29.0 +six>=1.12.0 +requests>=2.9.1 From c931180a151903fa27318133a42ff6ccf6749c8f Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Fri, 31 Jan 2020 15:33:24 -0800 Subject: [PATCH 02/10] set range for hypothesis --- scripts/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 0998c06fa8..8c913babfd 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -21,7 +21,8 @@ pyasn1==0.4.5 argparse>=1.2.1 mock==3.0.5 pytest>=4.6.3 -hypothesis>=4.24.3 +hypothesis>=4.50,<5.0 wheel>=0.29.0 six>=1.12.0 requests>=2.9.1 +coverage>=5.0.2 From aa9384eea64e5a82c09f2711fd95d2e92c605721 Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Fri, 31 Jan 2020 15:37:03 -0800 Subject: [PATCH 03/10] skip doc --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3ec9eca67d..1cd81da0dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: - ccache -s # Download and install cmake - - curl -L https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz -o cmake-3.13.4-Linux-x86_64.tar.gz + - curl -L https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz -o cmake-3.13.4-Linux-x86_64.tar.gz - tar xf cmake-3.13.4-Linux-x86_64.tar.gz - export PATH=${PWD}/cmake-3.13.4-Linux-x86_64/bin:${PATH} @@ -66,9 +66,10 @@ script: # Remove style transfer unit test due to out-of-memory error. # Remove some additional tests temporarily to get under the two-hour timeout. - rm src/python/turicreate/test/test_style_transfer.py src/python/turicreate/test/test_object_detector.py src/python/turicreate/test/test_one_shot_object_detector.py - + # Build the wheel - - bash scripts/make_wheel.sh --build_number=$CI_PIPELINE_ID --num_procs=1 --debug --skip_cpp_test --skip_doc + - bash scripts/make_wheel.sh --build_number=$CI_PIPELINE_ID --num_procs=1 + --debug --skip_cpp_test # See the changes in ccache - ccache -s From 40da38be29a7ba2bb1b67b573b1fc20ef36f604a Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Fri, 31 Jan 2020 21:18:55 -0800 Subject: [PATCH 04/10] use pytest-cov plugin instead --- .coveragerc | 27 +++++++++++++++++++++++++++ .travis.yml | 4 +++- scripts/requirements.txt | 2 +- scripts/run_python_test.sh | 15 ++++++++------- scripts/test_wheel.sh | 27 ++++++++++++++------------- 5 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000000..8755eb4444 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,27 @@ +# https://coverage.readthedocs.io/en/latest/config.html + +[run] +source = src/python/turicreate/ +branch = True +parallel = True + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if False: + if __name__ == .__main__.: + +ignore_errors = True diff --git a/.travis.yml b/.travis.yml index 1cd81da0dd..91d948ca95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,7 +65,9 @@ script: # Remove style transfer unit test due to out-of-memory error. # Remove some additional tests temporarily to get under the two-hour timeout. - - rm src/python/turicreate/test/test_style_transfer.py src/python/turicreate/test/test_object_detector.py src/python/turicreate/test/test_one_shot_object_detector.py + - rm src/python/turicreate/test/test_style_transfer.py + src/python/turicreate/test/test_object_detector.py + src/python/turicreate/test/test_one_shot_object_detector.py # Build the wheel - bash scripts/make_wheel.sh --build_number=$CI_PIPELINE_ID --num_procs=1 diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 8c913babfd..113db827c7 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -25,4 +25,4 @@ hypothesis>=4.50,<5.0 wheel>=0.29.0 six>=1.12.0 requests>=2.9.1 -coverage>=5.0.2 +pytest-cov>=2.7.1 diff --git a/scripts/run_python_test.sh b/scripts/run_python_test.sh index 25f9be9e36..997624f145 100755 --- a/scripts/run_python_test.sh +++ b/scripts/run_python_test.sh @@ -18,9 +18,9 @@ WORKSPACE=${SCRIPT_DIR}/.. unset PYTHONPATH -cd $WORKSPACE +cd "$WORKSPACE" scripts/install_python_toolchain.sh -source scripts/python_env.sh $BUILD_TYPE +source scripts/python_env.sh "$BUILD_TYPE" # Make python unit tests print unity server log on exception export TURI_VERBOSE=1 @@ -34,7 +34,7 @@ pop_ld_library_path() { export LD_LIBRARY_PATH=$OLD_LIBRARY_PATH } push_ld_library_path -cd $TURI_BUILD_ROOT/src/python +cd "$TURI_BUILD_ROOT"/src/python make -j4 pop_ld_library_path @@ -44,15 +44,16 @@ if ! type "parallel" 2> /dev/null; then if [[ $OSTYPE != msys ]]; then cmd=${PYTHON_EXECUTABLE} fi - cmd="${cmd} ${PYTEST_EXECUTABLE} -v $PYTHONPATH/turicreate/test --junit-xml=alltests.pytest.xml" - echo $cmd + cmd="${cmd} ${PYTEST_EXECUTABLE} --cov -v $PYTHONPATH/turicreate/test \ + --junit-xml=alltests.pytest.xml" + echo "$cmd" $cmd else cmd="" if [[ $OSTYPE != msys ]]; then cmd=${PYTHON_EXECUTABLE} fi - cmd="${cmd} ${PYTEST_EXECUTABLE} -v -s --junit-xml={}.pytest.xml {}" + cmd="${cmd} ${PYTEST_EXECUTABLE} --cov -v -s --junit-xml={}.pytest.xml {}" echo "Tests are running in parallel. Output is buffered until job is done..." - find turicreate/test -name "*.py" | parallel --group -P 4 $cmd + find turicreate/test -name "*.py" | parallel --group -P 4 "$cmd" fi diff --git a/scripts/test_wheel.sh b/scripts/test_wheel.sh index e6ff707bb6..8d29c01007 100755 --- a/scripts/test_wheel.sh +++ b/scripts/test_wheel.sh @@ -7,8 +7,8 @@ SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) WORKSPACE=${SCRIPT_DIR}/.. # The build image version that will be used for testing -TC_BUILD_IMAGE_1404=$(bash $WORKSPACE/scripts/get_docker_image.sh --ubuntu=14.04) -TC_BUILD_IMAGE_1804=$(bash $WORKSPACE/scripts/get_docker_image.sh --ubuntu=18.04) +TC_BUILD_IMAGE_1404=$(bash "$WORKSPACE"/scripts/get_docker_image.sh --ubuntu=14.04) +TC_BUILD_IMAGE_1804=$(bash "$WORKSPACE"/scripts/get_docker_image.sh --ubuntu=18.04) unknown_option() { echo "Unknown option $1. Exiting." @@ -40,34 +40,34 @@ while [ $# -gt 0 ] --docker-python3.6) USE_DOCKER=1;DOCKER_PYTHON=3.6;; --docker-python3.7) USE_DOCKER=1;DOCKER_PYTHON=3.7;; --help) print_help ;; - *) unknown_option $1 ;; + *) unknown_option "$1" ;; esac shift done SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) WORKSPACE=${SCRIPT_DIR}/.. -cd ${WORKSPACE} +cd "${WORKSPACE}" # If we are going to run in Docker, # send this command into Docker and bail out of here when done. if [[ -n "${USE_DOCKER}" ]]; then # create the build and test images # (this should ideally be a no-op if the image exists and is current) - $WORKSPACE/scripts/create_docker_images.sh + "$WORKSPACE"/scripts/create_docker_images.sh # Run the tests inside Docker if [[ "${DOCKER_PYTHON}" == "2.7" ]] || [[ "${DOCKER_PYTHON}" == "3.5" ]]; then docker run --rm -m=8g \ - --mount type=bind,source=$WORKSPACE,target=/build,consistency=delegated \ + --mount type=bind,source="$WORKSPACE",target=/build,consistency=delegated \ -e "VIRTUALENV=virtualenv --python=python${DOCKER_PYTHON}" \ - ${TC_BUILD_IMAGE_1404} \ + "${TC_BUILD_IMAGE_1404}" \ /build/scripts/test_wheel.sh elif [[ "${DOCKER_PYTHON}" == "3.6" ]] || [[ "${DOCKER_PYTHON}" == "3.7" ]]; then docker run --rm -m=8g \ - --mount type=bind,source=$WORKSPACE,target=/build,consistency=delegated \ + --mount type=bind,source="$WORKSPACE",target=/build,consistency=delegated \ -e "VIRTUALENV=virtualenv --python=python${DOCKER_PYTHON}" \ - ${TC_BUILD_IMAGE_1804} \ + "${TC_BUILD_IMAGE_1804}" \ /build/scripts/test_wheel.sh else echo "Invalid docker python version detected: ${DOCKER_PYTHON}" @@ -77,7 +77,7 @@ if [[ -n "${USE_DOCKER}" ]]; then exit 0 fi -(test -d deps/env) || ./scripts/install_python_toolchain.sh +test -d deps/env || ./scripts/install_python_toolchain.sh source deps/env/bin/activate pip install target/turicreate-*.whl @@ -85,10 +85,11 @@ PYTHON="$PWD/deps/env/bin/python" PYTHON_MAJOR_VERSION=$(${PYTHON} -c 'import sys; print(sys.version_info.major)') PYTHON_MINOR_VERSION=$(${PYTHON} -c 'import sys; print(sys.version_info.minor)') PYTHON_VERSION="python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}" -cp -a src/python/turicreate/test deps/env/lib/${PYTHON_VERSION}/site-packages/turicreate/ -cd deps/env/lib/${PYTHON_VERSION}/site-packages/turicreate/test +cp -a src/python/turicreate/test deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/ +cd deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/test # run tests -${PYTHON} -m pytest -v --durations=100 --junit-xml=../../../../../../../pytest.xml +${PYTHON} -m pytest --cov -v --durations=100 \ + --junit-xml=../../../../../../../pytest.xml date From a9291465e8c4ae055426cf7ae3c482de976394a6 Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Fri, 31 Jan 2020 21:30:19 -0800 Subject: [PATCH 05/10] ignore files in codecov report --- .coveragerc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.coveragerc b/.coveragerc index 8755eb4444..a32b596ea1 100644 --- a/.coveragerc +++ b/.coveragerc @@ -25,3 +25,9 @@ exclude_lines = if __name__ == .__main__.: ignore_errors = True + +omit = + */__init__.py + src/python/turicreate/_cython/* + src/python/turicreate/test/* + src/python/turicreate/_deps/*_mock.py From 09f9fe9da2ee8b31685ff97c068baeb2b130f9e4 Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Mon, 3 Feb 2020 12:57:31 -0800 Subject: [PATCH 06/10] generate code --- scripts/.coveragerc-template | 35 +++++++++++++++++++++++++++++++++++ scripts/test_wheel.sh | 13 ++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 scripts/.coveragerc-template diff --git a/scripts/.coveragerc-template b/scripts/.coveragerc-template new file mode 100644 index 0000000000..92bbe9c428 --- /dev/null +++ b/scripts/.coveragerc-template @@ -0,0 +1,35 @@ +# https://coverage.readthedocs.io/en/latest/config.html + +[run] +source = {{ source }} +branch = True +parallel = True + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if False: + if __name__ == .__main__.: + +ignore_errors = True + +omit = + */__init__.py + {{ source }}/test/* + {{ source }}/meta/* + {{ source }}/_cython/* + {{ source }}/_deps/*_mock.py + {{ source }}/_connect/* diff --git a/scripts/test_wheel.sh b/scripts/test_wheel.sh index 8d29c01007..67d22ee2ba 100755 --- a/scripts/test_wheel.sh +++ b/scripts/test_wheel.sh @@ -85,8 +85,19 @@ PYTHON="$PWD/deps/env/bin/python" PYTHON_MAJOR_VERSION=$(${PYTHON} -c 'import sys; print(sys.version_info.major)') PYTHON_MINOR_VERSION=$(${PYTHON} -c 'import sys; print(sys.version_info.minor)') PYTHON_VERSION="python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}" + cp -a src/python/turicreate/test deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/ -cd deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/test + +TEST_DIR=deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/test +SOURCE_DIR=$(dirname "$TEST_DIR") + +$PYTHON -c "import sys; lines=sys.stdin.read(); \ + print(lines.replace('{{ source }}', \"$SOURCE_DIR\"))" \ + < scripts/.coveragerc-template \ + > "${TEST_DIR}"/.coveragerc + +cd "$TEST_DIR" + # run tests ${PYTHON} -m pytest --cov -v --durations=100 \ From ae0df4b9bb4b6abeabb357da0bee23bdaa210431 Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Mon, 3 Feb 2020 14:02:00 -0800 Subject: [PATCH 07/10] absolute path --- scripts/test_wheel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_wheel.sh b/scripts/test_wheel.sh index 67d22ee2ba..515a9d9bc6 100755 --- a/scripts/test_wheel.sh +++ b/scripts/test_wheel.sh @@ -88,7 +88,7 @@ PYTHON_VERSION="python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}" cp -a src/python/turicreate/test deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/ -TEST_DIR=deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/test +TEST_DIR="$PWD"/deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/test SOURCE_DIR=$(dirname "$TEST_DIR") $PYTHON -c "import sys; lines=sys.stdin.read(); \ From c52d104a40babb01d93cec67515198fbb530f82b Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Wed, 5 Feb 2020 11:06:13 -0800 Subject: [PATCH 08/10] improve code --- scripts/test_wheel.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/test_wheel.sh b/scripts/test_wheel.sh index 515a9d9bc6..4447ecc8a9 100755 --- a/scripts/test_wheel.sh +++ b/scripts/test_wheel.sh @@ -47,6 +47,9 @@ done SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) WORKSPACE=${SCRIPT_DIR}/.. + +# PWD is WORKSPACE + cd "${WORKSPACE}" # If we are going to run in Docker, @@ -81,14 +84,14 @@ test -d deps/env || ./scripts/install_python_toolchain.sh source deps/env/bin/activate pip install target/turicreate-*.whl -PYTHON="$PWD/deps/env/bin/python" +PYTHON="$WORKSPACE/deps/env/bin/python" PYTHON_MAJOR_VERSION=$(${PYTHON} -c 'import sys; print(sys.version_info.major)') PYTHON_MINOR_VERSION=$(${PYTHON} -c 'import sys; print(sys.version_info.minor)') PYTHON_VERSION="python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}" cp -a src/python/turicreate/test deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/ -TEST_DIR="$PWD"/deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/test +TEST_DIR="$WORKSPACE"/deps/env/lib/"${PYTHON_VERSION}"/site-packages/turicreate/test SOURCE_DIR=$(dirname "$TEST_DIR") $PYTHON -c "import sys; lines=sys.stdin.read(); \ @@ -98,9 +101,8 @@ $PYTHON -c "import sys; lines=sys.stdin.read(); \ cd "$TEST_DIR" - # run tests ${PYTHON} -m pytest --cov -v --durations=100 \ - --junit-xml=../../../../../../../pytest.xml + --junit-xml="$WORKSPACE"/pytest.xml date From 404921c7695bbe1ba90553972973270902b8ef7f Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Wed, 5 Feb 2020 14:16:40 -0800 Subject: [PATCH 09/10] remove redundant echo --- scripts/run_python_test.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/run_python_test.sh b/scripts/run_python_test.sh index 997624f145..8f75d72a94 100755 --- a/scripts/run_python_test.sh +++ b/scripts/run_python_test.sh @@ -46,7 +46,6 @@ if ! type "parallel" 2> /dev/null; then fi cmd="${cmd} ${PYTEST_EXECUTABLE} --cov -v $PYTHONPATH/turicreate/test \ --junit-xml=alltests.pytest.xml" - echo "$cmd" $cmd else cmd="" From 9524fe3cf6cd3c70851fc0733561728739a630d3 Mon Sep 17 00:00:00 2001 From: guihao_liang Date: Wed, 5 Feb 2020 14:25:46 -0800 Subject: [PATCH 10/10] prepare for merge --- .coveragerc | 4 +++- scripts/run_python_test.sh | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index a32b596ea1..3fe4575d3e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -28,6 +28,8 @@ ignore_errors = True omit = */__init__.py - src/python/turicreate/_cython/* src/python/turicreate/test/* + src/python/turicreate/meta/* + src/python/turicreate/_cython/* src/python/turicreate/_deps/*_mock.py + src/python/turicreate/_connect/* diff --git a/scripts/run_python_test.sh b/scripts/run_python_test.sh index 8f75d72a94..93feb8a60f 100755 --- a/scripts/run_python_test.sh +++ b/scripts/run_python_test.sh @@ -33,11 +33,14 @@ push_ld_library_path() { pop_ld_library_path() { export LD_LIBRARY_PATH=$OLD_LIBRARY_PATH } + push_ld_library_path cd "$TURI_BUILD_ROOT"/src/python make -j4 pop_ld_library_path +# back to WORKSPACE to use default .coveragerc +cd "$WORKSPACE" find . -name "*.xml" -delete if ! type "parallel" 2> /dev/null; then cmd=""