From acdf23379623cdbe7ae07a47ab660f6e48c85069 Mon Sep 17 00:00:00 2001 From: zhiltsov-max Date: Wed, 6 May 2020 21:02:16 +0300 Subject: [PATCH] Add coverage for python (#1483) --- .coveragerc | 39 +++++++++++++++++++++++++++++++++++ .gitignore | 1 + .travis.yml | 18 ++++++++++++---- cvat/requirements/testing.txt | 1 + docker-compose.ci.yml | 3 +++ 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..7804da58 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,39 @@ +[run] +branch = true + +source = + datumaro/datumaro/ + cvat/apps/ + utils/cli/ + +omit = + datumaro/datumaro/__main__.py + datumaro/datumaro/version.py + cvat/settings/* + */tests/* + */test_* + */_test_* + */migrations/* + +[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\s+[\w\.()]+\.isEnabledFor\(log\.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 __name__ == .__main__.: + +# don't fail on the code that can be found +ignore_errors = true + +skip_empty = true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 23872063..bc0260f9 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ docker-compose.override.yml __pycache__ *.pyc ._* +.coverage # Ignore development npm files node_modules diff --git a/.travis.yml b/.travis.yml index 9875fc6e..278ec6bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,21 @@ python: services: - docker +env: + - CONTAINER_COVERAGE_DATA_DIR="/coverage_data" + HOST_COVERAGE_DATA_DIR="${TRAVIS_BUILD_DIR}/coverage_data" + +install: + - gem install coveralls-lcov + - pip install coveralls + before_script: - docker-compose -f docker-compose.yml -f docker-compose.ci.yml build + - mkdir -m a=rwx -p ${HOST_COVERAGE_DATA_DIR} script: - - docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'python3 manage.py test cvat/apps utils/cli' - - docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'python3 manage.py test --pattern="_tests.py" cvat/apps/dataset_manager' - - docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'python3 manage.py test datumaro/' - - docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'cd cvat-data && npm install && cd ../cvat-core && npm install && npm run test && npm run coveralls' + - docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'coverage run -a manage.py test cvat/apps utils/cli && coverage run -a --source cvat/apps/ manage.py test --pattern="_tests.py" cvat/apps/dataset_manager && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}' + - docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'cd cvat-data && npm install && cd ../cvat-core && npm install && npm run test && mv ./reports/coverage/lcov.info ${CONTAINER_COVERAGE_DATA_DIR}' + +after_success: + - coveralls-lcov -v -n lcov.info > coverage.json && coveralls --merge=coverage.json \ No newline at end of file diff --git a/cvat/requirements/testing.txt b/cvat/requirements/testing.txt index f5f61eec..79c222a2 100644 --- a/cvat/requirements/testing.txt +++ b/cvat/requirements/testing.txt @@ -3,3 +3,4 @@ fakeredis==1.1.0 # Fix dependencies for fakeredis 1.1.0 # Pip will not reinstall six package if it is installed already six==1.12.0 +coveralls \ No newline at end of file diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index f6755912..ac3a7c54 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -15,3 +15,6 @@ services: TRAVIS_JOB_ID: TRAVIS_BRANCH: TRAVIS_PULL_REQUEST: + CONTAINER_COVERAGE_DATA_DIR: + volumes: + - ${HOST_COVERAGE_DATA_DIR}:${CONTAINER_COVERAGE_DATA_DIR}