pytweezer.servers.simulated_device module

Generic mechanism for building simulated (“dummy”) device backends.

Historically each driver hand-copied its real backend class into a parallel Simulated/Dummy class, reimplementing only the methods someone remembered to. That drifts out of sync silently (missing methods, typo’d names, stale signatures) as the real class evolves.

simulate() instead derives a simulated class’s method surface from the real class at class definition time (never touching an instance, so it never talks to hardware): any public method the hand-written simulated class doesn’t already define itself gets a safe, logging, no-op stub. Only methods with genuinely interesting fake behavior (e.g. synthesizing camera frames) need to be hand-written; everything else stays in sync automatically as the real class changes.

pytweezer.servers.simulated_device.default_simulated(real_cls)[source]

Return a hardware-free simulated stand-in generated from real_cls.

Every public method becomes a logging no-op stub (via simulate()), and the constructor accepts and ignores any arguments so a device config’s keyword entries pass through harmlessly without touching hardware. This is the default used whenever a driver has no hand-written simulated class, so simulation is always available; write an explicit Simulated<X> (decorated with @simulate(<X>)) only when the fake needs interesting behavior — synthesized camera frames, a remembered SLM mask, etc.

The stand-in does not subclass real_cls, so none of its hardware-touching code (including __init__) can run by accident.

Parameters:

real_cls (type)

Return type:

type

pytweezer.servers.simulated_device.public_methods(real_cls, *, exclude=())[source]

Return {name: unbound function} for every public method of real_cls.

Inspects the class itself, not an instance, so building this mapping never runs the real class’s __init__ or touches hardware.

Parameters:
Return type:

dict[str, Callable]

pytweezer.servers.simulated_device.simulate(real_cls, *, exclude=(), defaults=None)[source]

Class decorator: fill in any public method of real_cls missing from the decorated class with a logging, PYON-safe no-op stub.

Methods already defined directly on the decorated class are left alone, so hand-written fake behavior always wins over the auto-generated stub. defaults maps method name to a return value (or a zero-arg callable producing one, e.g. dict/list, so mutable defaults are fresh per call) for methods where returning bare None would be a poor fake.

Parameters:
Return type:

Callable[[type], type]