test_companion
Unit tests for MyPluginCompanion.
This file is copied verbatim (with MyPluginCompanion replaced by your
class name) when you create a new plugin with New plugin from template….
Quick-start
Run from the project root:
pytest <your_plugin_dir>/tests/ -v
Mocking strategy
The companion needs a WolfMapViewer at construction time, but tests must
work without a display (CI / headless servers).
Two fixtures are provided:
viewerA
MagicMockthat satisfies every attribute and method call. We explicitly setxmin/xmaxso that helper methods that compute sizes relative to the viewport return sensible values instead of zero.gl_mockA fake
OpenGL.GLmodule injected intosys.modulesviamonkeypatch. Without it, any call to_paint()would fail with anImportError. The fixture exposes the mock so you can assert on specific OpenGL calls:c._paint(viewer) gl_mock.glVertex2f.assert_called()
Key codes
Import KeyboardSnapshot and pass integer key codes. Common values:
_WXK_ESCAPE = 27
_WXK_RETURN = 13
Module Contents
- test_companion.gl_mock(monkeypatch)[source]
Inject a headless OpenGL.GL module so paint methods do not crash.
- test_companion._ctx(x: float = 0.0, y: float = 0.0) wolfhece._viewer_plugin_handlers.MouseContext[source]
Build a right-click context at world coordinates (x, y).
- test_companion._kb(key_code: int, ctrl: bool = False) wolfhece._viewer_plugin_handlers.KeyboardSnapshot[source]
Build a keyboard event.