Skip to content

Commit d64f266

Browse files
author
jitsuineccles
authored
100% test coverage with bad pylint (#15)
* 100% test coverage with bad pylint * Run QC on any push or pull_request event * Create about.py during QC action * Correct bad pylint - QC should pass * black does not rase error if fie is reforatted * Fail QC if any files need formatting by black * File reformatted by black - QC should pass * Coverage fail_under set - QC should fail * Coverage is 100% - QC should pass
1 parent cc8d6fd commit d64f266

13 files changed

Lines changed: 109 additions & 22 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33

44
name: Python Quality Control
55

6-
on:
7-
push:
8-
branches: [ master ]
9-
pull_request:
10-
branches: [ master ]
6+
on: [push, pull_request]
117

128
jobs:
139
build:
@@ -30,7 +26,14 @@ jobs:
3026
python3 -m pip install -r requirements-dev.txt
3127
- name: Run integrity checks
3228
run: |
29+
./scripts/version.sh
3330
pycodestyle --format=pylint archivist unittests examples
3431
python3 -m pylint --rcfile=pylintrc archivist unittests examples
3532
black archivist examples unittests
33+
modified=$(git status -s | wc -l)
34+
if [ $modified -gt 0 ]
35+
then
36+
echo "there are $modified files that must be reformatted"
37+
exit 1
38+
fi
3639
./scripts/unittests.sh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ htmlcov/
99
.pylint.d/
1010
.cache/
1111
.eggs/
12+
.task/

Taskfile.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ version: '3'
22

33
tasks:
44

5+
about:
6+
desc: Generate about.py
7+
cmds:
8+
- ./scripts/version.sh
9+
status:
10+
- test -s archivist/about.py
11+
512
builder:
613
desc: Build a docker environment with the right dependencies and utilities
714
cmds:
815
- docker build --no-cache -f Dockerfile-builder -t jitsuin-archivist-python-builder .
916

1017
check:
1118
desc: Check the style, bug and quality of the code
19+
deps: [about]
1220
cmds:
1321
- ./scripts/builder.sh pycodestyle --format=pylint archivist unittests examples
1422
- ./scripts/builder.sh python3 -m pylint --rcfile=pylintrc archivist unittests examples
@@ -19,25 +27,29 @@ tasks:
1927
- find -name '*,cover' -type f -delete
2028
- git clean -fdX
2129

22-
unittests:
23-
desc: Run unittests
24-
cmds:
25-
- ./scripts/builder.sh ./scripts/unittests.sh
26-
30+
format:
31+
desc: Format code using black
32+
deps: [about]
33+
cmds:
34+
- ./scripts/builder.sh black archivist examples unittests
35+
2736
publish:
2837
desc: pubish wheel package (will require username and password)
38+
deps: [about]
2939
cmds:
3040
- ./scripts/builder.sh python3 -m twine upload --repository pypi dist/*
3141

42+
unittests:
43+
desc: Run unittests
44+
deps: [about]
45+
cmds:
46+
- ./scripts/builder.sh ./scripts/unittests.sh
47+
3248
wheel:
3349
desc: Builds python wheel package
50+
deps: [about]
3451
cmds:
3552
- rm -rf *egg-info
3653
- rm -rf build
3754
- rm -f dist/*
3855
- python3 setup.py bdist_wheel
39-
40-
format:
41-
desc: Format code using black
42-
cmds:
43-
- ./scripts/builder.sh black archivist examples unittests

archivist/logger.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import logging
55

6-
# pragma: no cover
76

87
# base logger from which all loggers are propagated
98
LOGGER = logging.getLogger()
@@ -17,8 +16,8 @@ def set_logger(level):
1716
Setup logger
1817
Also used by unittests
1918
"""
20-
LOGGER.setLevel(level)
21-
if not LOGGER.hasHandlers():
19+
LOGGER.setLevel(level) # pragma: no cover
20+
if not LOGGER.hasHandlers(): # pragma: no cover
2221
handler = logging.StreamHandler()
2322
handler.setFormatter(
2423
logging.Formatter(

archivist/timestamp.py

100755100644
File mode changed.

scripts/unittests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
rm -f coverage.xml
77
rm -rf htmlcov
88
COVERAGE="coverage"
9+
${COVERAGE} --version
910
${COVERAGE} run --branch --source archivist -m unittest discover -v
1011
${COVERAGE} annotate
1112
${COVERAGE} html

scripts/version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cat>archivist/about.py <<EOF
99
1010
WARNING: Do **not** edit directly
1111
This file is auto-generated by ./scripts/version.sh and is
12-
not version controlled by git (ironically) as this would
12+
not version controlled by git (ironically) as this would
1313
make the generated version from the tag 'dirty'
1414
"""
1515
__version__ = "$version"

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[pycodestyle]
22
ignore = E128, E203, E225, E265, E266, E402, E501, E713, E722, E741, W504,
33
statistics = True
4-
max-line-length = 88
4+
max-line-length = 88
5+
6+
[coverage:report]
7+
fail_under = 100

unittests/testabout.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Test archivist
3+
"""
4+
5+
# pylint: disable=attribute-defined-outside-init
6+
# pylint: disable=missing-docstring
7+
# pylint: disable=too-few-public-methods
8+
9+
from unittest import TestCase
10+
11+
from archivist import about
12+
13+
14+
class TestAbout(TestCase):
15+
"""
16+
Test about
17+
"""
18+
19+
def test_about(self):
20+
"""
21+
Test about
22+
"""
23+
self.assertGreater(
24+
len(about.__version__),
25+
0,
26+
msg="about version should be populated",
27+
)

0 commit comments

Comments
 (0)