Testing¶
hexa ships a zero-mock pytest suite that exercises the real sample pipelines. The same fixtures make great templates for testing your own pipelines against the container.
๐งช Running the Suite¶
python -m pytest tests -q
# expected: all pass (tests degrade gracefully when samples are absent)
The suite is fully deterministic: no network, no filesystem mocks, no dependency on external fixtures. A couple of tests guard on sample-file existence and skip cleanly otherwise, so the suite stays green in minimal checkouts.
๐ฆ What's Covered¶
| Module | What it proves |
|---|---|
test_model.py |
PortNode, MethodSpec, nested attributes equality & helpers. |
test_parse_yaml.py |
YAML โ tree: minimal spec and the extraction-pipeline grammar (attributes / nested structs / ports / methods:). |
test_parse_abc.py |
ABC module โ tree: reflection from __annotations__ + @abstractmethod. |
test_check_matches.py |
Two-representation agreement and ValueError on unknown extensions. |
test_roundtrip.py |
Full circle fidelity: parse_yaml โ generate_abc โ parse_abc โ generate_yaml โ parse_yaml. |
test_container.py |
build behavior: wiring, instances=/config= injection, defaults. |
๐ The Round-Trip Tests¶
The strongest guarantee lives in test_roundtrip.py โ the same tree must survive a full circuit and stay equal, not just lossless:
test_yaml_to_abc_to_yamlโ parsesamples/minimal/sample.yaml, generate ABC source, parse it back, re-emit YAML, parse again; the roots and child counts match.test_nested_struct_roundtripโ a nested struct attribute (source) survives YAML โ ABC โ YAML unchanged:test_abc_to_yaml_to_abcโ the mirror circuit starting fromsamples/minimal/abc.py.
These are the tests to keep green when you add a new grammar feature or a new converter.
๐๏ธ Container Tests¶
test_container.py pins the four injection contracts:
- Wiring with no overrides (
test_build_without_overrides_is_unchanged) โbuild(_Root)constructs every annotated slot from its type and keeps class defaults. - Runtime injection (
test_build_with_instances_and_config) โ - Typing-generic config fields (
test_config_applies_to_typing_generic_annotations) โstr | None/list | Nonefields takeconfigvalues and leave unset ones at their defaults. - Optional defaults (
test_config_optional_field_defaulted_to_none_when_unprovided) โ unprovided optional fields default toNone.
The _Root/_Mid/_Leaf fixture classes live right in the test file โ a great minimal template for testing your own annotated pipelines.
๐ก Tips¶
- Keep fixture classes small and place them in the test module (like
_Root,_Repo,_OptionalConfig). No fixtures framework needed for the container tests. - Add
hexa check <spec.yaml> <abc.py>to CI as a live example of the guard, then assert on the return withis True. - When extending the YAML grammar, add a case to both
test_parse_yaml.pyand a round-trip test โ if the round-trip holds, the converter pair is consistent by construction.