Skip to content

Add unit tests for osism/data/playbooks#2207

Open
berendt wants to merge 1 commit intomainfrom
gh2196
Open

Add unit tests for osism/data/playbooks#2207
berendt wants to merge 1 commit intomainfrom
gh2196

Conversation

@berendt
Copy link
Copy Markdown
Member

@berendt berendt commented Apr 25, 2026

Covers the lazy YAML loader and module-level getattr in osism/data/playbooks.py: multi-file merging into _MAP_ROLE2ENVIRONMENT, filename-stem mapping in _MAP_ROLE2RUNTIME, swallowing of yaml.YAMLError with a logged warning, cache short-circuit on re-entry, and the getattr paths for MAP_ROLE2ENVIRONMENT, MAP_ROLE2RUNTIME, plus the AttributeError fallback. Module caches are reset via an autouse fixture so tests are order-independent.

Closes #2196

AI-assisted: Claude Code

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The playbook_dir fixture replaces Path with a plain function that asserts on the exact string path; consider monkeypatching only the specific Path('/interface/playbooks') resolution (e.g., patching the constant or wrapping Path) to avoid coupling tests too tightly to the concrete implementation and to better mirror actual Path behavior.
  • The _reset_module_caches autouse fixture directly manipulates playbooks.__dict__ and private globals; to reduce brittleness against future refactors, you could centralize this reset logic in a small helper in the module under test and call that from the fixture instead of reaching into __dict__.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `playbook_dir` fixture replaces `Path` with a plain function that asserts on the exact string path; consider monkeypatching only the specific `Path('/interface/playbooks')` resolution (e.g., patching the constant or wrapping `Path`) to avoid coupling tests too tightly to the concrete implementation and to better mirror actual `Path` behavior.
- The `_reset_module_caches` autouse fixture directly manipulates `playbooks.__dict__` and private globals; to reduce brittleness against future refactors, you could centralize this reset logic in a small helper in the module under test and call that from the fixture instead of reaching into `__dict__`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Covers the lazy YAML loader and module-level __getattr__ in
osism/data/playbooks.py: multi-file merging into _MAP_ROLE2ENVIRONMENT,
filename-stem mapping in _MAP_ROLE2RUNTIME, swallowing of yaml.YAMLError
with a logged warning, cache short-circuit on re-entry, and the
__getattr__ paths for MAP_ROLE2ENVIRONMENT, MAP_ROLE2RUNTIME, plus the
AttributeError fallback. Module caches are reset via an autouse fixture
so tests are order-independent.

Closes #2196

AI-assisted: Claude Code
Signed-off-by: Christian Berendt <berendt@osism.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit tests for osism/data/playbooks.py

1 participant