Skip to content

Commit

Permalink
test: add support for coverage and pytest (TRI-ML#47)
Browse files Browse the repository at this point in the history
* test: add support for coverage and pytest

Update coverage.yml

test: add support for coverage and pytest

test: add support for coverage and pytest

Update requirements.txt

Add code coverage

Add source filtering

Update .gitignore

Create test_utils_colors.py

Colorbars testing with pytest

Update requirements.txt

Update test_utils_colors.py

Add coverage metrics

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update README.md

* test: add support for coverage and pytest

* test: fix support for coverage and pytest

Update coverage.svg

Update coverage.yml

Update coverage.yml

Update to feedback

Update coverage.yml

Update test params according to feedback

Update coverage.yml

Update coverage badge version

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Update coverage.yml

Create coverage.yml

Update coverage.yml

test: fix support for coverage and pytest

Update coverage.yml

Update workflow

Update coverage.yml
  • Loading branch information
sshusainTRI authored Nov 11, 2021
1 parent dc3a88b commit 8a3e914
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 3 deletions.
33 changes: 33 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# .coveragerc to control coverage.py
[run]
branch = True
source = dgp
omit =
# omit anything that is a auto-compiled protobuf
*/*_pb2.py
*/*_grpc.py
[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 __name__ == .__main__.:

# Don't complain about abstract methods, they aren't run:
@(abc\.)?abstractmethod

ignore_errors = True

[html]
directory = coverage_html_report
61 changes: 61 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: coverage
on:
pull_request:
branches:
- 'master'
push:
branches:
- 'master'
jobs:
build:
runs-on: ubuntu-18.04
env:
OS: ubuntu-18.04
PYTHON: '3.6'
COVERAGE_TOTAL: 24 #Coverage threshold percentage
steps:
- uses: actions/checkout@master
with:
fetch-depth: ‘2’ #Original commit + code cov badge commit
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.6
- name: Install dependencies
id: coverage-installer
run: |
python -m pip install --upgrade pip
pip install cython==0.29.21 numpy==1.19.4
sudo apt-get install jq
pip install -r requirements.txt
pip install coverage-badge
coverage run -m pytest
coverage-badge -f -o docs/coverage.svg
COVERAGE_SCORE=$(coverage json -o /dev/stdout | jq .totals.percent_covered)
echo "::set-output name=coverageScore::$COVERAGE_SCORE"
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v6
id: changed_files
with:
files: docs/coverage.svg
- name: Commit code coverage badge
if: ${{ steps.changed_files.outputs.files_changed == 'true' && github.event_name != 'pull_request'}}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add docs/coverage.svg
git commit -m "test: update coverage.svg"
git reset --soft HEAD~2 &&
git commit
- name: Push code coverage badge
if: ${{ steps.changed_files.outputs.files_changed == 'true' && github.event_name != 'pull_request'}}
uses: ad-m/github-push-action@master
with:
force: true
github_token: ${{ secrets.github_token }}
branch: ${{ github.event.pull_request.head.repo.full_name }}
- name: Coverage total fail - exit
if: ${{github.event_name == 'pull_request' && steps.coverage-installer.outputs.coverageScore < env.COVERAGE_TOTAL}}
run: |
echo "cov total fail ${{ steps.coverage-installer.outputs.coverageScore }}"
exit 1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest/*
coverage_html_report/

# Translations
*.mo
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ DOCKER_OPTS ?= \
--net=host --ipc=host

# Unit tests
UNITTEST ?= nosetests
UNITTEST_OPTS ?= --nologcapture -v -s
UNITTEST ?= pytest
UNITTEST_OPTS ?= -v

all: clean test

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![build-docker](https://github.com/TRI-ML/dgp/actions/workflows/build-docker.yml/badge.svg)](https://github.com/TRI-ML/dgp/actions/workflows/build-docker.yml)
[![license](https://img.shields.io/github/license/TRI-ML/dgp.svg)](https://github.com/TRI-ML/dgp/blob/master/LICENSE)
[![open-issues](https://isitmaintained.com/badge/open/TRI-ML/dgp.svg)](https://github.com/TRI-ML/dgp/issues)
![coverage badge](./docs/coverage.svg)
[![docs](https://img.shields.io/badge/documentation-beta-red)](https://tri-ml.github.io/dgp/)

To ensure the traceability, reproducibility and standardization for
Expand Down
2 changes: 1 addition & 1 deletion dgp/utils/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""This file contains definitions of predefined RGB colors, and color-related utility functions.
"""
import cv2
import matplotlib
import matplotlib.cm
import numpy as np

RED = (255, 0, 0)
Expand Down
21 changes: 21 additions & 0 deletions docs/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ awscli
boto3
botocore
Click>=7.1.2
coverage==6.0.2
diskcache>=4.1.0
grpcio==1.41.0
grpcio-tools==1.41.0
Expand All @@ -13,6 +14,7 @@ Pillow>=8.3.2
pycocotools>=2.0.0
pylint>=2.8.1
pyquaternion==0.9.5
pytest==6.2.5
rinohtype==0.5.3
Sphinx==4.2.0
torch>=1.8.1
Expand Down
23 changes: 23 additions & 0 deletions tests/utils/test_utils_colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest
from dgp.utils.colors import get_unique_colors


@pytest.mark.parametrize(
"num_colors,in_bgr,cmap,expected_map", [
(5, False, 'tab20', [
(31, 119, 180),
(174, 199, 232),
(255, 127, 14),
(255, 187, 120),
(44, 160, 44),
]),
(3, True, 'tab20', [(180, 119, 31), (232, 199, 174), (14, 127, 255)]),
(1, True, 'tab20', [(180, 119, 31)]),
(3, False, 'Paired', [(166, 206, 227), (31, 120, 180), (178, 223, 138)]),
]
)
def test_get_unique_colors(num_colors, in_bgr, cmap, expected_map):
'''
Uses parametrized testing to run multiple cases for colorbar retreival
'''
assert get_unique_colors(num_colors=num_colors, in_bgr=in_bgr, cmap=cmap) == expected_map

0 comments on commit 8a3e914

Please sign in to comment.