TestCscCommander

class lsst.ts.salobj.TestCscCommander(index: Optional[int], enable: bool = False, exclude: Optional[Sequence[str]] = None, fields_to_ignore: Sequence[str] = ('ignored', 'value', 'priority'))

Bases: lsst.ts.salobj.csc_commander.CscCommander

Control a Test CSC from the command line.

Parameters
indexint, optional

SAL index of CSC.

enablebool, optional

Enable the CSC (when the commander starts up)? Note: amain always supplies this argument.

excludeiterable of str, optional

Names of topics (telemetry or events) to not support. Topic names must not have a tel_ or evt_ prefix. If None or empty then no topics are excluded.

Methods Summary

add_arguments(parser)

Add arguments to the parser created by make_from_cmd_line.

add_kwargs_from_args(args, kwargs)

Add constructor keyword arguments based on parsed arguments.

amain(*, index, **kwargs)

Construct the commander and run it.

check_arguments(args, *names)

Check that the required arguments are provided.

close()

Close the commander, prior to quitting.

do_setArrays(args)

do_start(args)

Allow the start command to have no arguments.

event_callback(data, name)

Generic callback for events.

evt_summaryState_callback(data)

field_is_public(name)

Return True if the specified field name is public, False otherwise.

format_data(data)

Format the public fields of an event or telemetry sample, for printing.

format_dict(data)

Format a dict for printing.

format_item(key, value)

Format one event or telemetry field for printing.

get_commands_help()

Get help for each command, as a list of strings.

get_public_data(data)

Get a dict of field_name: value for public fields of a DDS sample.

get_rounded_public_data(data[, digits])

Get a dict of field_name: value for public fields of a DDS sample with float values rounded.

make_from_cmd_line(index, **kwargs)

Construct a SAL-related class from command line arguments.

output(msg)

Print a message to output, appending a final newline.

print_help()

Print help.

run_command(cmd)

Run the specified command string and wait for it to finish.

run_command_topic(command_name, args)

Run a command that has an associated salobj RemoteCommand topic.

start()

Start asynchonous processes.

telemetry_callback(data, name[, digits])

Generic callback for telemetry.

Methods Documentation

classmethod add_arguments(parser: argparse.ArgumentParser) None

Add arguments to the parser created by make_from_cmd_line.

Parameters
parserargparse.ArgumentParser

The argument parser.

Notes

If you override this method then you should almost certainly override add_kwargs_from_args as well.

classmethod add_kwargs_from_args(args: argparse.Namespace, kwargs: Dict[str, Any]) None

Add constructor keyword arguments based on parsed arguments.

Parameters
argsargparse.namespace

Parsed command.

kwargsdict

Keyword argument dict for the constructor. Update this based on args. The index argument will already be present if relevant.

Notes

If you override this method then you should almost certainly override add_arguments as well.

async classmethod amain(*, index: Optional[Union[int, enum.IntEnum, bool]], **kwargs: Any) None

Construct the commander and run it.

Parse the command line to construct the commander, then parse and execute commands until the exit is seen.

Parameters
indexint, enum.IntEnum, True, or None

If the CSC is indexed, do one of the following:

  • Specify True to make index a required command-line argument that accepts any nonzero index.

  • Specify an enum.IntEnum class to make index a required command-line argument that only accepts the enum values.

  • Specify a non-zero integer to use that index. This is rare; if the CSC is indexed then the user should usually be allowed to specify the index.

If the CSC is not indexed, specify None or 0.

**kwargsdict, optional

Additional keyword arguments for your CSC’s constructor.

check_arguments(args: Sequence[str], *names: Union[str, Tuple[str, Callable[[str], Any]]]) Dict[str, Any]

Check that the required arguments are provided. and return them as a keyword argument dict with cast values.

Parameters
argsList [str]

Command arguments, as strings.

*namesList [str or tuple]

Argument name and optional cast function. Each element is either:

  • An argument name, in which case the argument is cast to a float

  • A tuple of (name, cast function), in which case the argument is cast using the cast function. The cast function takes one str argument and returns the cast value.

async close() None

Close the commander, prior to quitting.

async do_setArrays(args: Sequence[str]) None
async do_start(args: Sequence[str]) None

Allow the start command to have no arguments.

event_callback(data: Any, name: str) None

Generic callback for events.

You may provide evt_<event_name> methods to override printing of specific events.

evt_summaryState_callback(data: lsst.ts.salobj.type_hints.BaseMsgType) None
field_is_public(name: str) bool

Return True if the specified field name is public, False otherwise.

format_data(data: Any) str

Format the public fields of an event or telemetry sample, for printing.

format_dict(data: Any) str

Format a dict for printing.

Unlike format_data, this requires a dict and formats all fields.

format_item(key: str, value: Any) str

Format one event or telemetry field for printing.

get_commands_help() List[str]

Get help for each command, as a list of strings.

End with “Other Commands:” and any commands in help_dict that are not in command_dict.

get_public_data(data: Any) Dict[str, Any]

Get a dict of field_name: value for public fields of a DDS sample.

Parameters
datadds_sample

DDS sample.

get_rounded_public_data(data: Any, digits: int = 2) Any

Get a dict of field_name: value for public fields of a DDS sample with float values rounded.

classmethod make_from_cmd_line(index: Optional[Union[int, enum.IntEnum, bool]], **kwargs: Any) lsst.ts.salobj.csc_commander.CscCommander

Construct a SAL-related class from command line arguments.

Parameters
indexint, enum.IntEnum, True, or None

If the CSC is indexed, do one of the following:

  • Specify True to make index a required command-line argument that accepts any nonzero index.

  • Specify an enum.IntEnum class to make index a required command-line argument that only accepts the enum values.

  • Specify a non-zero integer to use that index. This is rare; if the CSC is indexed then the user should usually be allowed to specify the index.

If the CSC is not indexed, specify None or 0.

**kwargsdict, optional

Additional keyword arguments for your class’s constructor.

Returns
instancecls

The constructed instance.

Notes

To add additional command-line arguments, override add_arguments and add_kwargs_from_args.

output(msg: str) None

Print a message to output, appending a final newline.

Please call this instead of print to support unit tests.

If self.testing is True then append str to self.output_queue instead of printing it. Use this mode for unit testing a CSC commander.

print_help() None

Print help.

async run_command(cmd: str) None

Run the specified command string and wait for it to finish.

Parameters
cmdstr

Command string (command name and arguments). Note: does not handle the “exit” command.

async run_command_topic(command_name: str, args: Sequence[str]) None

Run a command that has an associated salobj RemoteCommand topic.

Parameters
command_namestr

Command name, e.g. Enable

argsList [str]

String arguments for the command. There must be exactly one argument per public fields.

Notes

This method works for command topics that take scalar arguments. To support command topics with more exotic arguments you must provide a do_<command> method that parses the arguments and add an entry to self.help_dict.

async start() None

Start asynchonous processes.

telemetry_callback(data: Any, name: str, digits: int = 2) None

Generic callback for telemetry.

You may provide tel_<telemetry_name> methods to override printing of specific telemetry topics.