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 attached before interactive calls, but tests must work without a display (CI / headless servers).

Two fixtures are provided:

viewer

A MagicMock that satisfies every attribute and method call. We explicitly set xmin / xmax so that helper methods that compute sizes relative to the viewport return sensible values instead of zero.

gl_mock

A fake OpenGL.GL module injected into sys.modules via monkeypatch. Without it, any call to _paint() would fail with an ImportError. The fixture exposes the mock so you can assert on specific OpenGL calls:

c._paint()
gl_mock.glVertex2f.assert_called()

Key codes

Use Keys.ESCAPE, Keys.RETURN, etc. from wolfhece.plugins.abc instead of raw integer key codes:

from wolfhece.plugins.abc import Keys
kb = KeyboardSnapshot(key_code=Keys.ESCAPE)

Module Contents

test_companion.viewer()[source]

Minimal WolfMapViewer stand-in (no wx, no display required).

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.

test_companion._COMPANION_FILE[source]
test_companion._spec = None[source]
test_companion._mod = None[source]
test_companion.MyPluginCompanion[source]
test_companion.StepTransition[source]
test_companion._new_companion(viewer)[source]
class test_companion.TestMyPluginCompanion[source]

Behaviour tests — pure Python, no wx, no display.

test_instantiation(viewer)[source]

The companion can be created without errors.

test_start_registers_action(viewer)[source]
test_start_calls_viewer(viewer)[source]
test_esc_stops_action(viewer)[source]
test_unknown_key_returns_false(viewer)[source]
test_paint_does_not_crash(viewer, gl_mock)[source]
test_multistep_flow_next_then_finish(viewer)[source]