tests: add a standalone unit-test suite for wic's pure-Python logic
PATCH 1/1 tests: add a standalone unit-test suite for wic's pure-Python logic
wic currently has no test mechanism of its own; it relies on the oe-selftest from oe-core for all its testing, which means a full bitbake build is needed to exercise even pure-Python logic. Add a small standalone suite that runs from a plain checkout with nothing but pytest (and ruff for linting), so that logic can be pinned down and kept stable as the code evolves.
What this adds:
- tests/conftest.py: a session banner identifying what the run is tested against.
- tests/run-tests.sh: a small wrapper that runs the suite from anywhere in the checkout.
- tests/unit/: in-process unit suites for wic's pure-Python modules.
- tests/docs/: how to run the suite and the conventions it follows.
- pyproject.toml: a [tests] optional-dependency group and the pytest and ruff configuration.
- README.md: a Testing section pointing at the suite and its docs.
- .gitignore: ignore the coverage data file.
Install and run with:
pip install -e ".[tests]"
tests/run-tests.sh
The suite follows a test-driven style: each test states the behaviour wic is expected to provide. Where a behaviour is not yet in place, the test is written ahead of the implementation and marked xfail, so the specification is captured in the test itself. The test code itself is kept ruff-clean (see tests/docs/linting.md).
AI-Generated: codex/claude-opus 4.7 (xhigh)
--- .gitignore | 6 + README.md | 28 + pyproject.toml | 30 + tests/conftest.py | 38 + tests/docs/README.md | 77 + tests/docs/authoring.md | 97 ++ tests/docs/linting.md | 50 + tests/docs/philosophy.md | 84 ++ tests/run-tests.sh | 135 ++ tests/unit/test_bb_utils.py | 133 ++ tests/unit/test_bootfiles.py | 188 +++ tests/unit/test_cli_types.py | 288 ++++ tests/unit/test_engine.py | 282 ++++ tests/unit/test_filemap.py | 2317 +++++++++++++++++++++++++++++ tests/unit/test_help.py | 118 ++ tests/unit/test_ksparser_parse.py | 209 +++ tests/unit/test_ksparser_types.py | 400 +++++ tests/unit/test_misc.py | 128 ++ tests/unit/test_misc_vars.py | 182 +++ tests/unit/test_oe_path.py | 465 ++++++ tests/unit/test_partition.py | 598 ++++++++ tests/unit/test_pluginbase.py | 93 ++ tests/unit/test_update_fstab.py | 265 ++++ 23 files changed, 6211 insertions(+) create mode 100644 tests/conftest.py create mode 100644 tests/docs/README.md create mode 100644 tests/docs/authoring.md create mode 100644 tests/docs/linting.md create mode 100644 tests/docs/philosophy.md create mode 100755 tests/run-tests.sh create mode 100644 tests/unit/test_bb_utils.py create mode 100644 tests/unit/test_bootfiles.py create mode 100644 tests/unit/test_cli_types.py create mode 100644 tests/unit/test_engine.py create mode 100644 tests/unit/test_filemap.py create mode 100644 tests/unit/test_help.py create mode 100644 tests/unit/test_ksparser_parse.py create mode 100644 tests/unit/test_ksparser_types.py create mode 100644 tests/unit/test_misc.py create mode 100644 tests/unit/test_misc_vars.py create mode 100644 tests/unit/test_oe_path.py create mode 100644 tests/unit/test_partition.py create mode 100644 tests/unit/test_pluginbase.py create mode 100644 tests/unit/test_update_fstab.py
.gitignore +6 -0
@@ -1 +1,7 @@ **/__pycache__ + +# coverage.py data file +/.coverage + +# HTML coverage report (default output dir for run-tests.sh --html) +/htmlcov/
README.md +28 -0
@@ -5,6 +5,17 @@ Python CLI using Hatch. It either consumes a BitBake-exported environment file or folder (generated via `bitbake -c rootfs_wicenv <image>`) or will invoke BitBake directly (if available on the PATH). +## Contents + +- [Quick start](#quick-start) + - [Using wicenv (one environment file)](#using-wicenv-one-environment-file) + - [Using wicenv (environment folder)](#using-wicenv-environment-folder) + - [With bitbake](#with-bitbake) +- [Project layout](#project-layout) +- [Testing](#testing) +- [Contributing](#contributing) +- [Licensing](#licensing) + ## Quick start ### Using wicenv (one environment file)
@@ -46,6 +57,23 @@ environment file or folder (generated via `bitbake -c rootfs_wicenv - `src/wic/*`: core engine, plugins, and helpers. - `src/bb/*`: various bitbake helpers that were brought along and used in other parts of wic. - `src/oe/*`: various oe-core helpers that were brought along and used in other parts of wic. +- `tests/*`: the standalone test suite and its documentation (see Testing below). + +## Testing + +wic ships a standalone test suite under `tests/` that runs from a plain +checkout with nothing but `pytest` -- no bitbake and no OpenEmbedded +build required. Install the test extras and run it: + +``` +pip install -e ".[tests]" +tests/run-tests.sh +``` + +Add branch coverage of the wic source with `tests/run-tests.sh +--coverage`, or lint with `tests/run-tests.sh --lint`. See +[tests/docs/README.md](tests/docs/README.md) for the suite layout, how +to add a test, and the test-driven conventions it follows. ## Contributing
pyproject.toml +30 -0
@@ -17,6 +17,14 @@ classifiers = [ "Programming Language :: Python :: 3", ] +[project.optional-dependencies] +tests = [ + "pytest >= 7.0", + "coverage >= 7.0", + "pytest-cov >= 4.0", + "ruff >= 0.5", +] + [project.urls] Homepage = "https://git.yoctoproject.org/wic" Repository = "https://git.yoctoproject.org/wic"
@@ -36,3 +44,25 @@ build-backend = "hatchling.build" [tool.hatch.version] path = "src/wic/cli.py" + +[tool.pytest.ini_options] +# Keep a test's scratch directory only when it fails; a passing test's +# tmp_path is removed automatically so repeated runs do not accumulate +# leftover files under the pytest base temp directory. +tmp_path_retention_policy = "failed" +tmp_path_retention_count = 1 + +[tool.ruff] +# For now only the test suite is actually linted (run-tests.sh --lint +# passes the tests/ path); the wic source under src/ is not yet +# ruff-clean and is left out until its findings are fixed (see +# tests/docs/linting.md). The per-file-ignores below are the only +# intentional, test-specific exceptions. + +[tool.ruff.lint.per-file-ignores] +# Test modules prepend the in-tree src/ directory to sys.path before +# importing wic, so that the suite runs against a checkout that has not +# been installed. That bootstrap necessarily runs before the wic imports, +# which trips E402 (module-level import not at top of file). The ordering +# is deliberate; ignore E402 for the test tree only. +"tests/**" = ["E402"]
tests/conftest.py new file +38 -0
@@ -0,0 +1,38 @@ +# Session banner for the wic test suite. +# +# Before collection, print the environment the tests exercise: +# - the host +# - the Python and pytest versions +# - the wic under test (its version and the module path of its import) + +import platform + +import pytest + + +def _wic_under_test(): + """Return (version, module_path) for the wic being tested.""" + try: + import wic.cli as wic_cli + except Exception as exc: # pragma: no cover - reported in the banner + return ("(import failed: %s)" % exc, "(unimported)") + version = getattr(wic_cli, "__version__", "(unknown)") + module_path = getattr(wic_cli, "__file__", "(unknown)") + return (version, module_path) + + +def _format_banner(): + wic_version, wic_path = _wic_under_test() + lines = [ + "wic test suite", + " host: %s %s %s" % ( + platform.node(), platform.system(), platform.machine()), + " python: %s pytest: %s" % ( + platform.python_version(), pytest.__version__), + " wic: %s (%s)" % (wic_version, wic_path), + ] + return "\n".join(lines) + + +def pytest_report_header(config): + return _format_banner()
tests/docs/README.md new file +77 -0
77 lines not on this page · raw message
tests/docs/authoring.md new file +97 -0
97 lines not on this page · raw message
tests/docs/linting.md new file +50 -0
50 lines not on this page · raw message
tests/docs/philosophy.md new file +84 -0
84 lines not on this page · raw message
tests/run-tests.sh new file +135 -0
135 lines not on this page · raw message
tests/unit/test_bb_utils.py new file +133 -0
133 lines not on this page · raw message
tests/unit/test_bootfiles.py new file +188 -0
188 lines not on this page · raw message
tests/unit/test_cli_types.py new file +288 -0
288 lines not on this page · raw message
tests/unit/test_engine.py new file +282 -0
282 lines not on this page · raw message
tests/unit/test_filemap.py new file +2317 -0
1,542 lines not on this page · raw message
tests/unit/test_help.py new file +118 -0
118 lines not on this page · raw message
tests/unit/test_ksparser_parse.py new file +209 -0
209 lines not on this page · raw message
tests/unit/test_ksparser_types.py new file +400 -0
400 lines not on this page · raw message
tests/unit/test_misc.py new file +128 -0
128 lines not on this page · raw message
tests/unit/test_misc_vars.py new file +182 -0
182 lines not on this page · raw message
tests/unit/test_oe_path.py new file +465 -0
465 lines not on this page · raw message
tests/unit/test_partition.py new file +598 -0
598 lines not on this page · raw message
tests/unit/test_pluginbase.py new file +93 -0
93 lines not on this page · raw message
tests/unit/test_update_fstab.py new file +265 -0
265 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
Part of the diff is not shown here. View the raw message.
Quoted 51 lines · Trevor Woerner via lists.yoctoproject.org
wic currently has no test mechanism of its own; it relies on the oe-selftest from oe-core for all its testing, which means a full bitbake build is needed to exercise even pure-Python logic. Add a small standalone suite that runs from a plain checkout with nothing but pytest (and ruff for linting), so that logic can be pinned down and kept stable as the code evolves.
What this adds:
-
tests/conftest.py: a session banner identifying what the run is tested against.
-tests/run-tests.sh: a small wrapper that runs the suite from anywhere in the checkout.
- tests/unit/: in-process unit suites for wic's pure-Python modules.
- tests/docs/: how to run the suite and the conventions it follows.
- pyproject.toml: a [tests] optional-dependency group and the pytest and ruff configuration.
- README.md: a Testing section pointing at the suite and its docs.
- .gitignore: ignore the coverage data file.Install and run with:
pip install -e ".[tests]"
tests/run-tests.shThe suite follows a test-driven style: each test states the behaviour wic is expected to provide. Where a behaviour is not yet in place, the test is written ahead of the implementation and marked xfail, so the specification is captured in the test itself. The test code itself is kept ruff-clean (see
tests/docs/linting.md).AI-Generated: codex/claude-opus 4.7 (xhigh)
Signed-off-by Trevor Woerner <[email protected]>--- .gitignore | 6 + README.md | 28 + pyproject.toml | 30 + tests/conftest.py | 38 + tests/docs/README.md | 77 + tests/docs/authoring.md | 97 ++ tests/docs/linting.md | 50 + tests/docs/philosophy.md | 84 ++ tests/run-tests.sh | 135 ++ tests/unit/test_bb_utils.py | 133 ++ tests/unit/test_bootfiles.py | 188 +++ tests/unit/test_cli_types.py | 288 ++++ tests/unit/test_engine.py | 282 ++++ tests/unit/test_filemap.py | 2317 +++++++++++++++++++++++++++++ tests/unit/test_help.py | 118 ++ tests/unit/test_ksparser_parse.py | 209 +++
Quoted 8 lines
tests/unit/test_ksparser_types.py | 400 +++++ tests/unit/test_misc.py | 128 ++ tests/unit/test_misc_vars.py | 182 +++ tests/unit/test_oe_path.py | 465 ++++++ tests/unit/test_partition.py | 598 ++++++++ tests/unit/test_pluginbase.py | 93 ++ tests/unit/test_update_fstab.py | 265 ++++ 23 files changed, 6211 insertions(+)
Hi Trevor,
Thanks for sending this, I think it's important to add a standalone test suite to wic. 6211 new lines in one patch isn't reviewable though. Please separate this into a logical series of smaller changes.
I also recommend fixing issues in the wic code as you go instead of capturing them in xfail conditions. That is much easier if you take this one step at a time.
An initial series could add the test framework, add one test module and fix the errors along the way (e.g. in mkdirhier()).
Best regards,
Signature · 1 line
Paul Barker