mpylab.device.switch_virtual module¶
Virtual switch driver for tests without switching hardware.
- class mpylab.device.switch_virtual.SWITCH(SearchPaths=None)
Bases:
DRIVERProvide an in-memory switch with state history.
- Parameters:
SearchPaths (sequence of path-like, optional) – Directories searched for the virtual device configuration.
- GetDescription()
Return virtual identification.
- Returns:
(0, identification).- Return type:
tuple
- GetState()
Return active switch state.
- Returns:
(0, state).- Return type:
tuple
- GetStates()
Return number of available switch states.
- Returns:
(0, state_count).- Return type:
tuple
- GetVirtual()
Return the fixed virtual-mode flag.
- Returns:
(0, True).- Return type:
tuple
- Init(ini=None, channel=None, ignore_bus=None)
Initialize switch states without opening a hardware bus.
- Parameters:
ini (path-like or file-like, optional) – Virtual switch configuration source.
channel (int or str, optional) – Logical channel.
ignore_bus (bool, optional) – Accepted for compatibility; the hardware bus is always ignored.
- Returns:
Device status; zero indicates success.
- Return type:
int
- Quit()
Close the virtual switch.
- Returns:
Zero.
- Return type:
int
- SetState(state)
Set and return active switch state.
- Parameters:
state (int) – Zero-based state index.
- Returns:
(0, state).- Return type:
tuple
- conftmpl = {'description': {'description': <class 'str'>, 'deviceid': <class 'str'>, 'driver': <class 'str'>, 'serialnr': <class 'str'>, 'type': <class 'str'>, 'vendor': <class 'str'>}, 'init_value': {'initial_state': <class 'int'>, 'states': <class 'int'>, 'virtual': <function strbool>}}
- query(cmd, tmpl=None)
Write a command and return its response.
- Parameters:
cmd (str) – Supported command.
tmpl (str, optional) – Regular expression used to parse the response.
- Returns:
Raw or parsed response.
- Return type:
str or dict
- read(tmpl=None)
Read the last virtual response.
- Parameters:
tmpl (str, optional) – Regular expression with named groups.
- Returns:
Raw response, parsed groups, or an empty dictionary.
- Return type:
str or dict
- switch_to(state)
Select a zero-based switch state.
- Parameters:
state (int) – State index from zero to
states - 1.- Returns:
Zero after switching.
- Return type:
int
- write(cmd)
Handle one virtual command.
- Parameters:
cmd (str) – Supported command.
- Returns:
Zero.
- Return type:
int
- mpylab.device.switch_virtual.main()
Run a short virtual switch smoke test.