Skip to content

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:

  1. MockGenerator (if provided) — dynamic events with configurable timing
  2. data/events/events.jsonl — static event replay
  3. 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 if count > file length
  • seed — random seed for reproducible shuffling; None preserves 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:

gen = MockGenerator.from_random(100).set_speed(10.0).set_jitter(0.1)

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:

kazunoko --mock status
kazunoko --mock read 10
kazunoko --mock generate random --count 50

generate is the only CLI command backed exclusively by MockGenerator; it is not available without --mock.