Skip to content

Commit 79efc4d

Browse files
authored
Setup code coverage reporting (#45)
* See if we can use slipcover JSON with codecov * Clean up stray lines from codecov action example * Add wheel to dev requirements; only upload code coverage once * Try only running slipcover on python 3.9 * Fix invalid syntax in unit test github action * Revise conditional syntax, make codecov verbose * Switch to pytest-cov * Fix github actions syntax * Add code coverage files to gitignore * Add tests for not implemented error methods in base formatter * Add code coverage badge
1 parent 05404f2 commit 79efc4d

6 files changed

Lines changed: 41 additions & 2 deletions

File tree

.github/workflows/unit_tests.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
- 'tests/**'
1010
pull_request:
1111

12+
env:
13+
COV_PYTHON_VERSION: "3.9"
14+
1215
jobs:
1316
python-unit:
1417
runs-on: ubuntu-latest
@@ -32,5 +35,17 @@ jobs:
3235
pip install -e ".[dev]"
3336
python -m pip install tox tox-gh-actions
3437
if: steps.python-cache.outputs.cache-hit != 'true'
35-
- name: Run unit tests
38+
39+
# for all versions but the one we use for code coverage, run normally
40+
- name: Run unit tests normally
3641
run: tox
42+
if: ${{ matrix.python != env.COV_PYTHON_VERSION }}
43+
44+
# run code coverage in one version only
45+
- name: Run unit tests with code coverage reporting
46+
run: tox -e coverage
47+
if: ${{ matrix.python == env.COV_PYTHON_VERSION }}
48+
- name: Upload test coverage to Codecov
49+
uses: codecov/codecov-action@v3
50+
if: ${{ matrix.python == env.COV_PYTHON_VERSION }}
51+

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ venv/
3434
ENV/
3535
env.bak/
3636
venv.bak/
37+
38+
# code coverage
39+
.coverage
40+
coverage.xml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Repository for the DHTech 2022 Hackathon
44

55
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
66
[![unit tests](https://github.com/dh-tech/hackathon-2022/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/dh-tech/hackathon-2022/actions/workflows/unit_tests.yml)
7+
[![codecov](https://codecov.io/gh/dh-tech/hackathon-2022/branch/main/graph/badge.svg?token=GE7HZE8C9D)](https://codecov.io/gh/dh-tech/hackathon-2022)
78
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
89
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
910
[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-)

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ dev =
3939
tox
4040
sphinx
4141
twine
42-
test =
42+
wheel
43+
pytest-cov
44+
test =
4345
pytest>=7.2
4446

4547
[options.packages.find]

tests/test_dateformat/test_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from undate.dateformat.base import BaseDateFormat
24

35

@@ -26,3 +28,11 @@ def test_formatters_are_unique(self):
2628
# name = "ISO8601"
2729

2830
# assert len(BaseDateFormat.available_formatters()) != len(BaseDateFormat.__subclasses__())
31+
32+
def test_parse_not_implemented(self):
33+
with pytest.raises(NotImplementedError):
34+
BaseDateFormat().parse("foo bar baz")
35+
36+
def test_parse_to_string(self):
37+
with pytest.raises(NotImplementedError):
38+
BaseDateFormat().to_string(1991)

tox.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ deps =
2727
commands =
2828
flake8 --ignore=E501,E402,F401 src/undate/ tests/
2929

30+
[testenv:coverage]
31+
deps =
32+
pytest
33+
pytest-cov
34+
commands =
35+
pytest --cov=./ --cov-report=xml
36+
3037
[testenv:docs]
3138
description = invoke sphinx-build to build the HTML docs
3239
basepython = python3.10

0 commit comments

Comments
 (0)