TestCsc#

class lsst.ts.salobj.TestCsc(index, config_dir=None, check_if_duplicate=False, initial_state=State.STANDBY, override='', simulation_mode=0)#

Bases: ConfigurableCsc

A simple CSC intended for unit testing.

Supported commands:

  • setScalars and setArrays: 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, since wait supports this.

  • The standard state transition commands do the usual thing and output the summaryState event. The exitControl command 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, but amain sets it true.

  • initial_state (salobj.State, optional) –

    The initial state of the CSC. Typically one of:

    • salobj.State.ENABLED if you want the CSC immediately usable.

    • salobj.State.STANDBY if you want full emulation of a CSC.

  • override (str, optional) – Configuration override file to apply if initial_state is State.DISABLED or State.ENABLED.

  • simulation_mode (int, optional) – Simulation mode. The only allowed value is 0.

Raises:
  • ValueError – If config_dir is not a directory or initial_state is invalid.

  • salobj.ExpectedError – If simulation_mode is invalid. Note: you will only see this error if you await start_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 arrays and scalars telemetry topics in reponse to the setArrays or setScalars command (just like the arrays and scalars events). That makes it more predictable when this data will appear. Note that the heartbeat event 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.ENABLED state.

Error Codes

  • 1: the fault command was executed

Attributes Summary

arrays_fields

Get a tuple of the fields in an arrays struct.

enable_cmdline_state

field_type

element type.

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

version

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_config_pkg()

Get the name of the configuration package, e.g. "ts_config_ocs".

make_random_arrays_dict()

Make a random arrays data dict.

make_random_scalars_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.

Parameters:
  • data (any) – The data to copy.

  • fields (list [str]) – The names of the fields of data to copy.

Return type:

dict[str, Any]

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.

Parameters:
Return type:

None

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.

Parameters:
  • scalars1 (Any)

  • scalars2 (Any)

Return type:

None

async configure(config)#

Configure the CSC.

Parameters:

config (object) – The configuration, as described by the config schema, as a struct-like object.

Return type:

None

Notes

Called when running the start command, just before changing summary state from State.STANDBY to State.DISABLED.

async do_fault(data)#

Execute the fault command.

Change the summary state to State.FAULT

Parameters:

data (BaseMsgType)

Return type:

None

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:

None

async do_setArrays(data)#

Execute the setArrays command.

Parameters:

data (BaseMsgType)

Return type:

None

async do_setScalars(data)#

Execute the setScalars command.

Parameters:

data (BaseMsgType)

Return type:

None

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:

None

static get_config_pkg()#

Get the name of the configuration package, e.g. “ts_config_ocs”.

Return type:

str

make_random_arrays_dict()#

Make a random arrays data dict.

Return type:

dict[str, Any]

make_random_scalars_dict()#

Make a random arrays data dict.

Return type:

dict[str, Any]