TestCsc#
- class lsst.ts.salobj.TestCsc(index, config_dir=None, check_if_duplicate=False, initial_state=State.STANDBY, override='', simulation_mode=0)#
Bases:
ConfigurableCscA simple CSC intended for unit testing.
Supported commands:
setScalarsandsetArrays: output the provided data using the corresponding event and telemetry topics. Note that this violates the convention that telemetry is output at regular intervals, but it makes unit tests much easier to write.wait: wait for the specified amount of time, and, if requested, raise an exception. One use for this is to test command timeout by specifying a long wait and waiting a shorter time for the command to finish. Another use is to test multiple simultaneous commands, sincewaitsupports this.The standard state transition commands do the usual thing and output the
summaryStateevent. TheexitControlcommand shuts the CSC down.
- Parameters:
index (
int) – Index of Test component; each unit test method should use a different index.config_dir (
str, optional) – Path to configuration files.check_if_duplicate (
bool, optional) – Check for heartbeat events from the same SAL name and index at startup (before starting the heartbeat loop)? Defaults to False in order to speed up unit tests, butamainsets it true.initial_state (
salobj.State, optional) –The initial state of the CSC. Typically one of:
salobj.State.ENABLEDif you want the CSC immediately usable.salobj.State.STANDBYif you want full emulation of a CSC.
override (
str, optional) – Configuration override file to apply ifinitial_stateisState.DISABLEDorState.ENABLED.simulation_mode (
int, optional) – Simulation mode. The only allowed value is 0.
- Raises:
ValueError – If
config_diris not a directory orinitial_stateis invalid.salobj.ExpectedError – If
simulation_modeis invalid. Note: you will only see this error if you awaitstart_task.
Notes
Unlike a normal CSC this one does not output telemetry at regular intervals. Instead, in order to simplify unit tests, it outputs the
arraysandscalarstelemetry topics in reponse to thesetArraysorsetScalarscommand (just like thearraysandscalarsevents). That makes it more predictable when this data will appear. Note that theheartbeatevent is output at regular intervals, as for any CSC.Also, unlike most normal configurable CSCs, this one does not need to be configured in order to be used (though self.config will be None). Thus it is safe to start this CSC in the
salobj.State.ENABLEDstate.Error Codes
1: the fault command was executed
Attributes Summary
Get a tuple of the fields in an arrays struct.
element type.
Get a tuple of the integer fields in a struct.
Get a tuple of the fields in a scalars struct.
Methods Summary
as_dict(data, fields)Return the specified fields from a data struct as a dict.
assert_arrays_equal(arrays1, arrays2)Assert that two arrays data structs are equal.
assert_scalars_equal(scalars1, scalars2)Assert that two scalars data structs are equal.
configure(config)Configure the CSC.
do_fault(data)Execute the fault command.
do_newCommand(data)This method is defined here to provide a test to the extra_commands features in CSC.
do_setArrays(data)Execute the setArrays command.
do_setScalars(data)Execute the setScalars command.
do_wait(data)Execute the wait command by waiting for the specified duration.
Get the name of the configuration package, e.g. "ts_config_ocs".
Make a random arrays data dict.
Make a random arrays data dict.
Attributes Documentation
- arrays_fields#
Get a tuple of the fields in an arrays struct.
- enable_cmdline_state = True#
- field_type#
element type.
- Type:
Get a dict of field_name
- int_fields#
Get a tuple of the integer fields in a struct.
- scalars_fields#
Get a tuple of the fields in a scalars struct.
- valid_simulation_modes: Sequence[int] = [0]#
- version = '8.2.9'#
Methods Documentation
- as_dict(data, fields)#
Return the specified fields from a data struct as a dict.
- assert_arrays_equal(arrays1, arrays2)#
Assert that two arrays data structs are equal.
The types need not match; each struct can be command, event or telemetry data, or a dict of field: value.
- assert_scalars_equal(scalars1, scalars2)#
Assert that two scalars data structs are equal.
The types need not match; each struct can be command, event or telemetry data, or a dict of field: value.
- async configure(config)#
Configure the CSC.
- Parameters:
config (
object) – The configuration, as described by the config schema, as a struct-like object.- Return type:
Notes
Called when running the
startcommand, just before changing summary state fromState.STANDBYtoState.DISABLED.
- async do_fault(data)#
Execute the fault command.
Change the summary state to State.FAULT
- Parameters:
data (
BaseMsgType)- Return type:
- async do_newCommand(data)#
This method is defined here to provide a test to the extra_commands features in CSC.
Warning: DO NOTE REMOVE THIS COMMAND.
- Parameters:
data (
BaseMsgType)- Return type:
- async do_setArrays(data)#
Execute the setArrays command.
- Parameters:
data (
BaseMsgType)- Return type:
- async do_setScalars(data)#
Execute the setScalars command.
- Parameters:
data (
BaseMsgType)- Return type:
- async do_wait(data)#
Execute the wait command by waiting for the specified duration.
If duration is negative then wait for abs(duration) but do not acknowledge the command as “in progress”. This is useful for testing command timeout.
- Parameters:
data (
BaseMsgType)- Return type:
- static get_config_pkg()#
Get the name of the configuration package, e.g. “ts_config_ocs”.
- Return type: