forked from TRI-ML/dgp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add support for coverage and pytest (TRI-ML#47)
* 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
1 parent
dc3a88b
commit 8a3e914
Showing
9 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ coverage.xml | |
*.cover | ||
.hypothesis/ | ||
.pytest/* | ||
coverage_html_report/ | ||
|
||
# Translations | ||
*.mo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |