Skip to content

Commit

Permalink
Better test coverage, test cleanup
Browse files Browse the repository at this point in the history
Improve the testcase code quality a bit and add a few more
testcases.

Signed-off-by: David Weinehall <[email protected]>
  • Loading branch information
taotriad committed Dec 3, 2024
1 parent 8cb3c16 commit 2da8e54
Show file tree
Hide file tree
Showing 28 changed files with 652 additions and 489 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG/CHANGELOG-0.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,17 @@ Output:
```
Name Stmts Miss Branch BrPart Cover
---------------------------------------------------------------------------------------
clustermanagementtoolkit/listgetters_async.py 119 103 54 0 9.2%
clustermanagementtoolkit/infogetters.py 1676 1270 1008 68 21.9%
clustermanagementtoolkit/cluster_actions.py 223 175 72 3 19.3%
clustermanagementtoolkit/itemgetters.py 507 375 290 8 22.3%
clustermanagementtoolkit/infogetters.py 1677 1208 1008 79 25.2%
clustermanagementtoolkit/fieldgetters.py 81 54 46 0 27.6%
clustermanagementtoolkit/kubernetes_helper.py 1494 1004 760 62 27.9%
clustermanagementtoolkit/kubernetes_helper.py 1494 1004 760 61 28.0%
clustermanagementtoolkit/listgetters.py 1212 808 662 90 28.7%
clustermanagementtoolkit/curses_helper.py 2388 1544 1124 125 29.0%
clustermanagementtoolkit/networkio.py 342 237 171 2 29.2%
clustermanagementtoolkit/logparser.py 2008 1275 1125 45 31.1%
clustermanagementtoolkit/datagetters.py 277 181 142 5 32.2%
clustermanagementtoolkit/listgetters_async.py 119 76 54 2 31.8%
clustermanagementtoolkit/datagetters.py 277 145 142 11 45.1%
clustermanagementtoolkit/checks.py 631 310 248 11 47.3%
clustermanagementtoolkit/generators.py 732 317 384 59 49.6%
clustermanagementtoolkit/formatters.py 807 310 424 25 57.8%
Expand All @@ -262,7 +263,7 @@ clustermanagementtoolkit/objgetters.py 56 0 12 0
clustermanagementtoolkit/pvtypes.py 1 0 0 0 100.0%
clustermanagementtoolkit/recommended_permissions.py 11 0 0 0 100.0%
---------------------------------------------------------------------------------------
TOTAL 15930 8152 8334 588 44.7%
TOTAL 16154 8202 8406 609 45.1%
```


Expand Down
31 changes: 29 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ coverage-cluster: setup_tests
fi; \
printf -- "\n\nRunning python3-coverage to check test coverage\n" ;\
printf -- "\n\n Running: tests/async_fetch\n\n" ;\
$$cmd run --branch --append tests/dgtests || exit 1 ;\
printf -- "\n\n Running: tests/dgtests --include-cluster\n\n" ;\
$$cmd run --branch --append tests/async_fetch || exit 1 ;\
printf -- "\n\n Running: tests/dgtests --include-cluster\n\n" ;\
$$cmd run --branch --append tests/dgtests --include-cluster || exit 1 ;\
printf -- "\n\n Running: tests/lgtests --include-cluster\n\n" ;\
$$cmd run --branch --append tests/lgtests --include-cluster || exit 1 ;\
printf -- "\n\n Running: tests/khtests --include-cluster\n\n" ;\
$$cmd run --branch --append tests/khtests --include-cluster || exit 1 ;\
printf -- "\n\n Running: tests/cmtlibtests --include-cluster\n\n" ;\
Expand Down Expand Up @@ -253,6 +255,18 @@ ruff:
$$cmd check --target-version $(RUFF_PYTHON_VERSION) $$file ;\
done

ruff-tests:
@cmd=ruff ;\
if ! command -v $$cmd > /dev/null 2> /dev/null; then \
printf -- "\n\n$$cmd not installed; skipping.\n\n\n" ;\
exit 0 ;\
fi ;\
printf -- "\n\nRunning $$cmd to check Python code quality\n\n" ;\
for file in $(python_test_executables); do \
printf -- "File: $$file\n" ;\
$$cmd check --target-version $(RUFF_PYTHON_VERSION) $$file ;\
done

pylint:
@cmd=pylint ;\
if ! command -v $$cmd > /dev/null 2> /dev/null; then \
Expand Down Expand Up @@ -347,6 +361,19 @@ mypy:
$$cmd $(MYPY_FLAGS) $$file || true; \
done

# Note: we know that the code does not have complete type-hinting,
# hence we return 0 after each test to avoid it from stopping.
mypy-tests:
@cmd=mypy ;\
if ! command -v $$cmd > /dev/null 2> /dev/null; then \
printf -- "\n\n$$cmd not installed; skipping.\n\n\n"; \
exit 0; \
fi; \
printf -- "\n\nRunning mypy to check Python typing\n\n"; \
for file in $(python_test_executables); do \
$$cmd $(MYPY_FLAGS) $$file || true; \
done

# Note: we know that the code does not have complete type-hinting,
# hence we return 0 after each test to avoid it from stopping.
mypy-markdown:
Expand Down
3 changes: 2 additions & 1 deletion clustermanagementtoolkit/infogetters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import os
import re
import sys
from typing import Any, Callable, cast, Optional, Sequence, Type, Union
from typing import Any, cast, Optional, Type, Union
from collections.abc import Callable, Sequence
import yaml

try:
Expand Down
61 changes: 31 additions & 30 deletions docs/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,45 @@ get a perfect score.
If the file you're modifying is not listed here you can either implement one on your own,
or ask for help.

| File: | Tests: | Notes: |
| :-------------------- | :--------------------- | :------------------------------------ |
| `ansithemeprint.py` | `tests/atptests` | Optional manual tests |
| `ansible_helper.py` | `tests/ansibletests` | Ansible setup required |
| `checks.py` | `tests/checkstests` | |
| `cmtio.py` | `tests/iotests` | |
| `cmtio_yaml.py` | `tests/iotests` | |
| `cmtlib.py` | `tests/cmtlibtests` | Ansible & cluster setup optional |
| `cmtvalidators.py` | `tests/validatortests` | |
| `cmttypes.py` | `tests/typetests` | |
| `cni_data.py` | `tests/cnitests` | |
| `commandparser.py` | `tests/clptests` | |
| `curses_helper.py` | `tests/cursestests` | |
| `datagetters.py` | `tests/dgtests` | |
| `fieldgetters.py` | `tests/fgtests` | |
| `generators.py` | `tests/gentests` | |
| `formatter.py` | `tests/fmttests` | |
| `infogetters.py` | `tests/infogtests` | |
| `itemgetters.py` | `tests/itemgtests` | |
| `kubernetes_helper.py`| `tests/khtests` | Cluster setup optional |
| `listgetters.py` | `tests/lgtests` | |
| `logparser.py` | `tests/logtests` | |
| `objgetters.py` | `tests/ogtests` | |
| `networkio.py` | `tests/iotests` | |
| `networkio.py` | `tests/networkiotests` | Tests in iotests should be moved here |
| `reexecutor.py` | `tests/async_fetch` | Cluster setup mandatory |
| File: | Tests: | Notes: |
| :--------------------- | :--------------------- | :------------------------------------ |
| `ansithemeprint.py` | `tests/atptests` | Optional manual tests |
| `ansible_helper.py` | `tests/ansibletests` | Ansible setup required |
| `checks.py` | `tests/checkstests` | |
| `cmtio.py` | `tests/iotests` | |
| `cmtio_yaml.py` | `tests/iotests` | |
| `cmtlib.py` | `tests/cmtlibtests` | Ansible & cluster setup optional |
| `cmtvalidators.py` | `tests/validatortests` | |
| `cmttypes.py` | `tests/typetests` | |
| `cni_data.py` | `tests/cnitests` | |
| `commandparser.py` | `tests/clptests` | |
| `curses_helper.py` | `tests/cursestests` | |
| `datagetters.py` | `tests/dgtests` | |
| `fieldgetters.py` | `tests/fgtests` | |
| `generators.py` | `tests/gentests` | |
| `formatter.py` | `tests/fmttests` | |
| `infogetters.py` | `tests/infogtests` | |
| `itemgetters.py` | `tests/itemgtests` | |
| `kubernetes_helper.py` | `tests/khtests` | Cluster setup optional |
| `listgetters.py` | `tests/lgtests` | |
| `listgetters_async.py` | `tests/lgtests` | Cluster setup required |
| `logparser.py` | `tests/logtests` | |
| `objgetters.py` | `tests/ogtests` | |
| `networkio.py` | `tests/iotests` | |
| `networkio.py` | `tests/networkiotests` | Tests in iotests should be moved here |
| `reexecutor.py` | `tests/async_fetch` | Cluster setup required |

_Note_:

* Optional manual tests mean that there are optional testcases that require manual input
* Ansible setup optional means that there are optional testcases that require cmt to
be installed and configured with an inventory
be installed and configured with an inventory.
* Ansible setup required means that all or almost all testcases require cmt to
be installed and configured with an inventory
be installed and configured with an inventory.
* Cluster setup optional means that there are optional testcases that require access
to a cluster
to a cluster.
* Cluster setup required means that all or almost all testcases require access
to a cluster
to a cluster; these tests may be hidden behind the `--include-cluster` flag.

At some point this might be revisited; ideally most most functions that only rely
indirectly on a working cluster or Ansible setup should be passed dummy data instead.
Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap/Project_roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ the roadmap has, for now, been pushed back one quarter, but further slips are li
## Q4 roadmap

* _General_:
* [ ] tests: Achieve 45% test coverage for `*.py`.
* [x] tests: Achieve 45% test coverage for `*.py`.
* [ ] All functions, classes, and methods should have docstrings and type hints.
* [ ] Distribute as:
* [ ] Source code.
Expand Down
Loading

0 comments on commit 2da8e54

Please sign in to comment.