Skip to content

Commit 2da8e54

Browse files
committed
Better test coverage, test cleanup
Improve the testcase code quality a bit and add a few more testcases. Signed-off-by: David Weinehall <[email protected]>
1 parent 8cb3c16 commit 2da8e54

28 files changed

+652
-489
lines changed

CHANGELOG/CHANGELOG-0.8.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,17 @@ Output:
231231
```
232232
Name Stmts Miss Branch BrPart Cover
233233
---------------------------------------------------------------------------------------
234-
clustermanagementtoolkit/listgetters_async.py 119 103 54 0 9.2%
235-
clustermanagementtoolkit/infogetters.py 1676 1270 1008 68 21.9%
234+
clustermanagementtoolkit/cluster_actions.py 223 175 72 3 19.3%
236235
clustermanagementtoolkit/itemgetters.py 507 375 290 8 22.3%
236+
clustermanagementtoolkit/infogetters.py 1677 1208 1008 79 25.2%
237237
clustermanagementtoolkit/fieldgetters.py 81 54 46 0 27.6%
238-
clustermanagementtoolkit/kubernetes_helper.py 1494 1004 760 62 27.9%
238+
clustermanagementtoolkit/kubernetes_helper.py 1494 1004 760 61 28.0%
239239
clustermanagementtoolkit/listgetters.py 1212 808 662 90 28.7%
240240
clustermanagementtoolkit/curses_helper.py 2388 1544 1124 125 29.0%
241241
clustermanagementtoolkit/networkio.py 342 237 171 2 29.2%
242242
clustermanagementtoolkit/logparser.py 2008 1275 1125 45 31.1%
243-
clustermanagementtoolkit/datagetters.py 277 181 142 5 32.2%
243+
clustermanagementtoolkit/listgetters_async.py 119 76 54 2 31.8%
244+
clustermanagementtoolkit/datagetters.py 277 145 142 11 45.1%
244245
clustermanagementtoolkit/checks.py 631 310 248 11 47.3%
245246
clustermanagementtoolkit/generators.py 732 317 384 59 49.6%
246247
clustermanagementtoolkit/formatters.py 807 310 424 25 57.8%
@@ -262,7 +263,7 @@ clustermanagementtoolkit/objgetters.py 56 0 12 0
262263
clustermanagementtoolkit/pvtypes.py 1 0 0 0 100.0%
263264
clustermanagementtoolkit/recommended_permissions.py 11 0 0 0 100.0%
264265
---------------------------------------------------------------------------------------
265-
TOTAL 15930 8152 8334 588 44.7%
266+
TOTAL 16154 8202 8406 609 45.1%
266267
```
267268

268269

Makefile

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ coverage-cluster: setup_tests
173173
fi; \
174174
printf -- "\n\nRunning python3-coverage to check test coverage\n" ;\
175175
printf -- "\n\n Running: tests/async_fetch\n\n" ;\
176-
$$cmd run --branch --append tests/dgtests || exit 1 ;\
177-
printf -- "\n\n Running: tests/dgtests --include-cluster\n\n" ;\
178176
$$cmd run --branch --append tests/async_fetch || exit 1 ;\
177+
printf -- "\n\n Running: tests/dgtests --include-cluster\n\n" ;\
178+
$$cmd run --branch --append tests/dgtests --include-cluster || exit 1 ;\
179+
printf -- "\n\n Running: tests/lgtests --include-cluster\n\n" ;\
180+
$$cmd run --branch --append tests/lgtests --include-cluster || exit 1 ;\
179181
printf -- "\n\n Running: tests/khtests --include-cluster\n\n" ;\
180182
$$cmd run --branch --append tests/khtests --include-cluster || exit 1 ;\
181183
printf -- "\n\n Running: tests/cmtlibtests --include-cluster\n\n" ;\
@@ -253,6 +255,18 @@ ruff:
253255
$$cmd check --target-version $(RUFF_PYTHON_VERSION) $$file ;\
254256
done
255257

258+
ruff-tests:
259+
@cmd=ruff ;\
260+
if ! command -v $$cmd > /dev/null 2> /dev/null; then \
261+
printf -- "\n\n$$cmd not installed; skipping.\n\n\n" ;\
262+
exit 0 ;\
263+
fi ;\
264+
printf -- "\n\nRunning $$cmd to check Python code quality\n\n" ;\
265+
for file in $(python_test_executables); do \
266+
printf -- "File: $$file\n" ;\
267+
$$cmd check --target-version $(RUFF_PYTHON_VERSION) $$file ;\
268+
done
269+
256270
pylint:
257271
@cmd=pylint ;\
258272
if ! command -v $$cmd > /dev/null 2> /dev/null; then \
@@ -347,6 +361,19 @@ mypy:
347361
$$cmd $(MYPY_FLAGS) $$file || true; \
348362
done
349363

364+
# Note: we know that the code does not have complete type-hinting,
365+
# hence we return 0 after each test to avoid it from stopping.
366+
mypy-tests:
367+
@cmd=mypy ;\
368+
if ! command -v $$cmd > /dev/null 2> /dev/null; then \
369+
printf -- "\n\n$$cmd not installed; skipping.\n\n\n"; \
370+
exit 0; \
371+
fi; \
372+
printf -- "\n\nRunning mypy to check Python typing\n\n"; \
373+
for file in $(python_test_executables); do \
374+
$$cmd $(MYPY_FLAGS) $$file || true; \
375+
done
376+
350377
# Note: we know that the code does not have complete type-hinting,
351378
# hence we return 0 after each test to avoid it from stopping.
352379
mypy-markdown:

clustermanagementtoolkit/infogetters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import os
2727
import re
2828
import sys
29-
from typing import Any, Callable, cast, Optional, Sequence, Type, Union
29+
from typing import Any, cast, Optional, Type, Union
30+
from collections.abc import Callable, Sequence
3031
import yaml
3132

3233
try:

docs/Development.md

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,45 @@ get a perfect score.
3030
If the file you're modifying is not listed here you can either implement one on your own,
3131
or ask for help.
3232

33-
| File: | Tests: | Notes: |
34-
| :-------------------- | :--------------------- | :------------------------------------ |
35-
| `ansithemeprint.py` | `tests/atptests` | Optional manual tests |
36-
| `ansible_helper.py` | `tests/ansibletests` | Ansible setup required |
37-
| `checks.py` | `tests/checkstests` | |
38-
| `cmtio.py` | `tests/iotests` | |
39-
| `cmtio_yaml.py` | `tests/iotests` | |
40-
| `cmtlib.py` | `tests/cmtlibtests` | Ansible & cluster setup optional |
41-
| `cmtvalidators.py` | `tests/validatortests` | |
42-
| `cmttypes.py` | `tests/typetests` | |
43-
| `cni_data.py` | `tests/cnitests` | |
44-
| `commandparser.py` | `tests/clptests` | |
45-
| `curses_helper.py` | `tests/cursestests` | |
46-
| `datagetters.py` | `tests/dgtests` | |
47-
| `fieldgetters.py` | `tests/fgtests` | |
48-
| `generators.py` | `tests/gentests` | |
49-
| `formatter.py` | `tests/fmttests` | |
50-
| `infogetters.py` | `tests/infogtests` | |
51-
| `itemgetters.py` | `tests/itemgtests` | |
52-
| `kubernetes_helper.py`| `tests/khtests` | Cluster setup optional |
53-
| `listgetters.py` | `tests/lgtests` | |
54-
| `logparser.py` | `tests/logtests` | |
55-
| `objgetters.py` | `tests/ogtests` | |
56-
| `networkio.py` | `tests/iotests` | |
57-
| `networkio.py` | `tests/networkiotests` | Tests in iotests should be moved here |
58-
| `reexecutor.py` | `tests/async_fetch` | Cluster setup mandatory |
33+
| File: | Tests: | Notes: |
34+
| :--------------------- | :--------------------- | :------------------------------------ |
35+
| `ansithemeprint.py` | `tests/atptests` | Optional manual tests |
36+
| `ansible_helper.py` | `tests/ansibletests` | Ansible setup required |
37+
| `checks.py` | `tests/checkstests` | |
38+
| `cmtio.py` | `tests/iotests` | |
39+
| `cmtio_yaml.py` | `tests/iotests` | |
40+
| `cmtlib.py` | `tests/cmtlibtests` | Ansible & cluster setup optional |
41+
| `cmtvalidators.py` | `tests/validatortests` | |
42+
| `cmttypes.py` | `tests/typetests` | |
43+
| `cni_data.py` | `tests/cnitests` | |
44+
| `commandparser.py` | `tests/clptests` | |
45+
| `curses_helper.py` | `tests/cursestests` | |
46+
| `datagetters.py` | `tests/dgtests` | |
47+
| `fieldgetters.py` | `tests/fgtests` | |
48+
| `generators.py` | `tests/gentests` | |
49+
| `formatter.py` | `tests/fmttests` | |
50+
| `infogetters.py` | `tests/infogtests` | |
51+
| `itemgetters.py` | `tests/itemgtests` | |
52+
| `kubernetes_helper.py` | `tests/khtests` | Cluster setup optional |
53+
| `listgetters.py` | `tests/lgtests` | |
54+
| `listgetters_async.py` | `tests/lgtests` | Cluster setup required |
55+
| `logparser.py` | `tests/logtests` | |
56+
| `objgetters.py` | `tests/ogtests` | |
57+
| `networkio.py` | `tests/iotests` | |
58+
| `networkio.py` | `tests/networkiotests` | Tests in iotests should be moved here |
59+
| `reexecutor.py` | `tests/async_fetch` | Cluster setup required |
5960

6061
_Note_:
6162

6263
* Optional manual tests mean that there are optional testcases that require manual input
6364
* Ansible setup optional means that there are optional testcases that require cmt to
64-
be installed and configured with an inventory
65+
be installed and configured with an inventory.
6566
* Ansible setup required means that all or almost all testcases require cmt to
66-
be installed and configured with an inventory
67+
be installed and configured with an inventory.
6768
* Cluster setup optional means that there are optional testcases that require access
68-
to a cluster
69+
to a cluster.
6970
* Cluster setup required means that all or almost all testcases require access
70-
to a cluster
71+
to a cluster; these tests may be hidden behind the `--include-cluster` flag.
7172

7273
At some point this might be revisited; ideally most most functions that only rely
7374
indirectly on a working cluster or Ansible setup should be passed dummy data instead.

docs/roadmap/Project_roadmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ the roadmap has, for now, been pushed back one quarter, but further slips are li
5050
## Q4 roadmap
5151

5252
* _General_:
53-
* [ ] tests: Achieve 45% test coverage for `*.py`.
53+
* [x] tests: Achieve 45% test coverage for `*.py`.
5454
* [ ] All functions, classes, and methods should have docstrings and type hints.
5555
* [ ] Distribute as:
5656
* [ ] Source code.

0 commit comments

Comments
 (0)