BaseCscTestCase#
- class lsst.ts.salobj.BaseCscTestCase#
Bases:
objectBase class for CSC tests.
Subclasses must:
Inherit both from this and
unittest.IsolatedAsyncioTestCase.Override
basic_make_cscto return a CSC.
Also we suggest:
Add a method
test_standard_state_transitionswhich callscheck_standard_state_transitions.Add a method
test_bin_scriptwhich callscheck_bin_script, assuming you have a binary script to run your CSC.
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
summaryStateevent.Runs after each test is completed.
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.
Get the next SAL index.
run([result])Set a random LSST_TOPIC_SUBNAME and set LSST_SITE=test for every test.
Methods Documentation
- async assert_next_sample(topic, flush=False, timeout=30, **kwargs)#
Wait for the next data sample for the specified topic, check specified fields for equality, and return the data.
- Parameters:
topic (
topics.ReadTopic) – Topic to read, e.g.remote.evt_logMessage.flush (
bool, optional) – Flush the read queue before waiting?timeout (
double, optional) – Time limit for getting the data sample (sec).kwargs (
dict) – Dict of field_name: expected_value The specified fields will be checked for equality.
- Returns:
data – The data read.
- Return type:
topic data type
- Raises:
asyncio.TimeoutError – If no message is available within the specified time limit.
- async assert_next_summary_state(state, flush=False, timeout=30, remote=None)#
Wait for and check the next
summaryStateevent.- Parameters:
- Raises:
asyncio.TimeoutError – If summary state is not seen within the specified time limit.
- Return type:
- abstract basic_make_csc(initial_state, config_dir, simulation_mode, **kwargs)#
Make and return a CSC.
- Parameters:
initial_state (
lsst.ts.salobj.Stateorint) – The initial state of the CSC.config_dir (
strorpathlib.PathorNone) – Directory of configuration files, or None for the standard configuration directory (obtained fromConfigureCsc._get_default_config_dir).simulation_mode (
int) – Simulation mode.kwargs (
dict) – Extra keyword arguments, if needed.
- Return type:
- async check_bad_commands(bad_commands=None, good_commands=None)#
Check that bad commands fail.
- Parameters:
- Return type:
Notes
If a command appears in both lists, it is considered a good command, so it is skipped.
- async check_bin_script(name, index, exe_name, default_initial_state=State.STANDBY, initial_state=None, override=None, cmdline_args=(), timeout=40)#
Test running the CSC command line script.
- Parameters:
name (
str) – Name of SAL component, e.g. “Rotator”exe_name (
str) – Name of executable, e.g. “run_rotator.py”default_initial_state (
lsst.ts.salobj.State, optional) – The default initial state of the CSC. Ignored unlessinitial_stateis None.initial_state (
lsst.ts.salobj.StateorintorNone, optional) – The desired initial state of the CSC; used to specify the--statecommand-argument.override (
strorNone, optional) – Value for the--overridecommand-line argument, which is omitted if override is None.cmdline_args (
List[str]) – Additional command-line arguments, such as “–simulate”.timeout (
float, optional) – Time limit for the CSC to start and output the summaryState event.
- Raises:
asyncio.TimeoutError – If the CSC cannot be started within the specified time limit.
- Return type:
- async check_standard_state_transitions(enabled_commands, skip_commands=None, override='', timeout=30)#
Test standard CSC state transitions.
- Parameters:
enabled_commands (
List[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_commands (
List[str] orNone, optional) – List of commands to skip.override (
str, optional) – Configuration override file to apply when the CSC is taken from stateState.STANDBYtoState.DISABLED.timeout (
float, optional) – Time limit for state transition commands (seconds).
- Raises:
asyncio.TimeoutError – If any state transition takes longer than the specified time limit.
- Return type:
Notes
timeoutis only used for state transition commands that are expected to succceed.STD_TIMEOUTis used for things that should happen quickly:Commands that should fail, due to the CSC being in the wrong state.
The
summaryStateevent after each state transition:
- make_csc(initial_state=None, config_dir=None, simulation_mode=0, log_level=None, timeout=30, **kwargs)#
Create a CSC and remote and wait for them to start.
The csc is accessed as
self.cscand the remote asself.remote.The topics in
self.remotewill queue all telemetry and events from when the CSC is constructed, with one exception: self.remote.evt_summaryState will only have the final summary state, because earlier values are read and checked against the expected startup states. (The final summary state is left queued for backwards compatibility.)- Parameters:
name (
str) – Name of SAL component.initial_state (
lsst.ts.salobj.Stateorint, optional) – The initial state of the CSC. If None use the CSC’s default initial state.config_dir (
str, optional) – Directory of configuration files, orNone(the default) for the standard configuration directory (obtained fromConfigureCsc._get_default_config_dir).simulation_mode (
int, 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_level (
intorNone, optional) – Logging level, such aslogging.INFO. IfNonethen do not set the log level, leaving the default behavior ofSalInfo: increase the log level to INFO.timeout (
float, optional) – Time limit for the CSC to start (seconds).**kwargs (
dict, optional) – Extra keyword arguments forbasic_make_csc. For a configurable CSC this may includeoverride, especially ifinitial_stateis DISABLED or ENABLED.
- Raises:
asyncio.TimeoutError – If the CSC cannot be constructed within the specified time limit.
- Return type: