BaseCscTestCase

class lsst.ts.salobj.BaseCscTestCase

Bases: object

Base class for CSC tests.

Subclasses must:

Also we suggest:

Methods Summary

assert_next_sample(topic[, flush, timeout])

Wait for the next data sample for the specified topic, check specified fields for equality, and return the data.

assert_next_summary_state(state[, flush, ...])

Wait for and check the next summaryState event.

basic_make_csc(initial_state, config_dir, ...)

Make and return a CSC.

check_bad_commands([bad_commands, good_commands])

Check that bad commands fail.

check_bin_script(name, index, exe_name[, ...])

Test running the CSC command line script.

check_standard_state_transitions(...[, ...])

Test standard CSC state transitions.

make_csc([initial_state, config_dir, ...])

Create a CSC and remote and wait for them to start, after setting a random $LSST_DDS_PARTITION_PREFIX.

next_index()

Get the next SAL index.

run([result])

Set a random LSST_DDS_PARTITION_PREFIX and set LSST_SITE=test for every test.

Methods Documentation

async assert_next_sample(topic: lsst.ts.salobj.topics.read_topic.ReadTopic, flush: bool = False, timeout: float = 60, **kwargs: Any) lsst.ts.salobj.type_hints.BaseMsgType

Wait for the next data sample for the specified topic, check specified fields for equality, and return the data.

Parameters
topictopics.ReadTopic

Topic to read, e.g. remote.evt_logMessage.

flushbool, optional

Flush the read queue before waiting?

timeoutdouble, optional

Time limit for getting the data sample (sec).

kwargsdict

Dict of field_name: expected_value The specified fields will be checked for equality.

Returns
datatopic data type

The data read.

async assert_next_summary_state(state: lsst.ts.salobj.sal_enums.State, flush: bool = False, timeout: float = 60, remote: Optional[lsst.ts.salobj.remote.Remote] = None) None

Wait for and check the next summaryState event.

Parameters
statelsst.ts.salobj.State or int

Desired summary state.

flushbool, optional

Flush the read queue before waiting?

timeoutfloat, optional

Time limit for getting the data sample (sec).

remoteRemote, optional

Remote to use; self.remote if None.

abstract basic_make_csc(initial_state: Union[lsst.ts.salobj.sal_enums.State, int], config_dir: Optional[Union[str, pathlib.Path]], simulation_mode: int, **kwargs: Any) lsst.ts.salobj.base_csc.BaseCsc

Make and return a CSC.

Parameters
initial_statelsst.ts.salobj.State or int

The initial state of the CSC.

config_dirstr or pathlib.Path or None

Directory of configuration files, or None for the standard configuration directory (obtained from ConfigureCsc._get_default_config_dir).

simulation_modeint

Simulation mode.

kwargsdict

Extra keyword arguments, if needed.

async check_bad_commands(bad_commands: Optional[Sequence[str]] = None, good_commands: Optional[Sequence[str]] = None) None

Check that bad commands fail.

Parameters
bad_commandsList`[`str] or None, optional

Names of bad commands to try, or None for all commands.

good_commandsList`[`str] or None, optional

Names of good commands to skip, or None to skip none.

Notes

If a command appears in both lists, it is considered a good command, so it is skipped.

async check_bin_script(name: str, index: int, exe_name: str, default_initial_state: lsst.ts.salobj.sal_enums.State = State.STANDBY, initial_state: Optional[lsst.ts.salobj.sal_enums.State] = None, override: Optional[str] = None, cmdline_args: Sequence[str] = (), timeout: float = 60) None

Test running the CSC command line script.

Parameters
namestr

Name of SAL component, e.g. “Rotator”

indexint or None

SAL index of component.

exe_namestr

Name of executable, e.g. “run_rotator.py”

default_initial_statelsst.ts.salobj.State, optional

The default initial state of the CSC. Ignored unless initial_state is None.

initial_statelsst.ts.salobj.State or int or None, optional

The desired initial state of the CSC; used to specify the --state command-argument.

overridestr or None, optional

Value for the --override command-line argument, which is omitted if override is None.

cmdline_argsList [str]

Additional command-line arguments, such as “–simulate”.

timeoutfloat, optional

Time limit for the CSC to start and output the summaryState event.

async check_standard_state_transitions(enabled_commands: Sequence[str], skip_commands: Optional[Sequence[str]] = None, override: str = '', timeout: float = 60) None

Test standard CSC state transitions.

Parameters
enabled_commandsList [str]

List of CSC-specific commands that are valid in the enabled state. Need not include the standard commands, which are “disable” and “setLogLevel” (which is valid in any state).

skip_commandsList [str] or None, optional

List of commands to skip.

overridestr, optional

Configuration override file to apply when the CSC is taken from state State.STANDBY to State.DISABLED.

timeoutfloat, optional

Time limit for state transition commands (seconds).

Notes

timeout is only used for state transition commands that are expected to succceed. STD_TIMEOUT is used for things that should happen quickly:

  • Commands that should fail, due to the CSC being in the wrong state.

  • The summaryState event after each state transition:

make_csc(initial_state: lsst.ts.salobj.sal_enums.State = State.STANDBY, config_dir: Optional[Union[str, pathlib.Path]] = None, simulation_mode: int = 0, log_level: Optional[int] = None, timeout: float = 60, **kwargs: Any) AsyncGenerator[None, None]

Create a CSC and remote and wait for them to start, after setting a random $LSST_DDS_PARTITION_PREFIX.

The csc is accessed as self.csc and the remote as self.remote.

Reads and checks all but the last summaryState event during startup.

Parameters
namestr

Name of SAL component.

initial_statelsst.ts.salobj.State or int, optional

The initial state of the CSC. Defaults to STANDBY.

config_dirstr, optional

Directory of configuration files, or None (the default) for the standard configuration directory (obtained from ConfigureCsc._get_default_config_dir).

simulation_modeint, optional

Simulation mode. Defaults to 0 because not all CSCs support simulation. However, tests of CSCs that support simulation will almost certainly want to set this nonzero.

log_levelint or None, optional

Logging level, such as logging.INFO. If None then do not set the log level, leaving the default behavior of SalInfo: increase the log level to INFO.

timeoutfloat, optional

Time limit for the CSC to start (seconds).

**kwargsdict, optional

Extra keyword arguments for basic_make_csc. For a configurable CSC this may include override, especially if initial_state is DISABLED or ENABLED.

next_index() int

Get the next SAL index.

run(result: Optional[Any] = None) None

Set a random LSST_DDS_PARTITION_PREFIX and set LSST_SITE=test for every test.

Unlike setUp, a user cannot forget to override this. (This is also a good place for context managers).