Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

add python codecov #2976

Merged
merged 13 commits into from
Feb 5, 2020
33 changes: 33 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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

omit =
*/__init__.py
src/python/turicreate/_cython/*
src/python/turicreate/test/*
src/python/turicreate/_deps/*_mock.py
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -65,10 +65,13 @@ 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 --debug --skip_cpp_test
- bash scripts/make_wheel.sh --build_number=$CI_PIPELINE_ID --num_procs=1
--debug --skip_cpp_test

# See the changes in ccache
- ccache -s
16 changes: 9 additions & 7 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ 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.50,<5.0
wheel>=0.29.0
six>=1.12.0
requests>=2.9.1
pytest-cov>=2.7.1
15 changes: 8 additions & 7 deletions scripts/run_python_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ WORKSPACE=${SCRIPT_DIR}/..

unset PYTHONPATH

cd $WORKSPACE
cd "$WORKSPACE"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "$WORKSPACE" the same as ${WORKSPACE}?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you use this tool called shellcheck along with pre-commit.

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
Expand All @@ -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

Expand All @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to remove this echo. Especially since set -x is included at the top of the script.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right! will do.

$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
27 changes: 14 additions & 13 deletions scripts/test_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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}"
Expand All @@ -77,18 +77,19 @@ 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

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