Mock Layer¶
Drop-in simulation of the OSECHI detector for testing without hardware.
Design Intent¶
MockDevice implements DeviceProtocol exactly like PortDevice, so all code written against the interface runs unchanged in tests. No conditionals, no special test paths — swap the device object and everything above it is unaffected.
MockDevice¶
MockDevice loads detection events from data/events/events.jsonl at startup and responds to recognized device commands with plausible static replies.
Event priority when receive_response(field_type="event") is called:
MockGenerator(if provided) — dynamic events with configurable timingdata/events/events.jsonl— static event replay- Command response fallback
from kazunoko import MockDevice, Command
with MockDevice() as device:
cmd = Command(device)
response = cmd.status() # same API as real hardware
MockGenerator¶
MockGenerator produces detection events with configurable speed and timing jitter, suitable for load testing or UI development.
| Factory | Source |
|---|---|
from_file(path) |
Load events from a specific JSONL file |
from_random(count, seed) |
Sample from events.jsonl, optionally shuffled |
from_random parameters:
count— number of events to return; cycles through the file ifcount > file lengthseed— random seed for reproducible shuffling;Nonepreserves original order
Timing control (method chaining):
gen = MockGenerator.from_random(count=1000, seed=42)
gen.set_speed(2.0) # 2× faster than real timing
gen.set_jitter(0.05) # ±50 ms random variation
set_speed and set_jitter return self, so they can be chained:
Integrating with MockDevice:
from kazunoko import MockDevice, MockGenerator
gen = MockGenerator.from_random(count=500, seed=0).set_speed(5.0)
with MockDevice(generator=gen) as device:
reader = Reader(device)
events = reader.read_by_count(100)
CLI mock mode¶
All CLI commands accept --mock to use MockDevice instead of a real port:
generate is the only CLI command backed exclusively by MockGenerator; it is not available without --mock.