microscope.testsuite.mock_devices module

Mock devices to be used in test cases.

These classes mock the different hardware as much as needed for our testing needs. Their behaviour is based first on the specifications we have, and second on what we actually experience. Our experience is that most hardware does not actually follow the specs.

To fake a specific device type for interactive usage, use the dummy device classes instead. There’s a concrete class for each device interface.

class microscope.testsuite.mock_devices.CoboltLaserMock(*args, **kwargs)[source]

Bases: microscope.testsuite.mock_devices.SerialMock

Modelled after a Cobolt Jive laser 561nm.

baudrate = 115200
bytesize = 8
default_power = 50.0
dsrdtr = False
eol = b'\r'
handle(command)[source]
max_power = 600.0
min_power = 0.0
parity = 'N'
rtscts = False
stopbits = 1
class microscope.testsuite.mock_devices.CoherentSapphireLaserMock(*args, **kwargs)[source]

Bases: microscope.testsuite.mock_devices.SerialMock

Modelled after a Coherent Sapphire LP 561nm laser.

This mocked device is constructed into the ready state. That is, after the laser has been turned on enough time to warmup (~ 30 seconds), and then the key has been turned on for enough time to actual get the laser ready (~10 seconds).

We don’t mock the turning of the key, that’s much trickier and we don’t need it yet. We’ll do it if it ever becomes an issue, and probably use a state machine library for that.

baudrate = 19200
bytesize = 8
default_power = 50.0
dsrdtr = False
eol = b'\r\n'
handle(command)[source]
max_power = 220.0
min_power = 20.0
parity = 'N'
rtscts = False
stopbits = 1
write(data)[source]
class microscope.testsuite.mock_devices.OmicronDeepstarLaserMock(*args, **kwargs)[source]

Bases: microscope.testsuite.mock_devices.SerialMock

Modelled after a TA Deepstar 488nm.

class Mode[source]

Bases: enum.Enum

An enumeration.

bias = 2
blackout = 1
deepstar = 4
modulated = 3
class State[source]

Bases: enum.Enum

An enumeration.

S0 = 0
S1 = 1
S2 = 2
baudrate = 9600
bytesize = 8
command2mode = {b'BLK': <Mode.blackout: 1>, b'L0': <Mode.blackout: 1>, b'L1': <Mode.modulated: 3>, b'L2': <Mode.deepstar: 4>, b'LB': <Mode.bias: 2>}
default_power = 50.0
dsrdtr = False
eol = b'\r\n'
handle(command)[source]
light
max_power = 200.0
min_power = 0.0
mode2answer = {<Mode.blackout: 1>: b'L0', <Mode.bias: 2>: b'LB', <Mode.modulated: 3>: b'L1', <Mode.deepstar: 4>: b'L2'}
parity = 'N'
rtscts = False
stopbits = 1
write(data)[source]
class microscope.testsuite.mock_devices.SerialMock(*args, **kwargs)[source]

Bases: serial.serialutil.SerialBase

Base class to mock devices controlled via serial.

It has two BytesIO buffers. One write() into the the output buffer and read() from the input buffer. After a write, the output buffer is analysed for a command. If there is a command, stuff gets done. This usually means adding to the input buffer and changing state of the device.

_readx_wrapper(reader, *args, **kwargs)[source]

Place pointer of input buffer before and after read methods

close()[source]

Flush and close the IO object.

This method has no effect if the file is already closed.

handle(command)[source]
open()[source]
read(size=1)[source]
readline(size=-1)[source]

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

reset_input_buffer()[source]
reset_output_buffer()[source]
write(data)[source]