launch_testing.tools package

Submodules

Module contents

class launch_testing.tools.ProcessProxy(process_action, proc_info, proc_output, *, output_filter=None)

Bases: object

A proxy to interact with launch.actions.ExecuteProcess instances.

property exit_code
property output
property running
property stderr
property stdout
property target_process_action
property terminated
wait_for_output(condition=None, timeout=None)

Wait for the target process to produce any output, either over stdout or stderr.

Parameters:
  • condition – a callable to wait on a specific output condition to be satisfied, or None (default) to wake on any output.

  • timeout – time in seconds to wait, or None (default) to block indefinitely.

Returns:

whether the condition has been satisfied or not.

wait_for_shutdown(timeout=None)

Wait for the target process to shutdown.

Parameters:

timeout – time in seconds to wait, or None to block indefinitely.

Returns:

whether the target process shut down or not.

launch_testing.tools.basic_output_filter(filtered_prefixes=None, filtered_patterns=None)

Create a line filtering function to help output testing.

Parameters:

filtered_prefixes – A list of byte strings representing prefixes that will cause

output lines to be ignored if they start with one of the prefixes. By default lines starting with the process ID (‘pid’) and return code (‘rc’) will be ignored. :param filtered_patterns: A list of byte strings representing regexes that will cause output lines to be ignored if they match one of the regexes.

launch_testing.tools.expect_output(text=None, *, lines=None, expected_text=None, expected_lines=None, strip_ansi_escape_sequences=True, strict=False)

Match output text or lines with expected text or lines.

Either (expected) text or (expected) lines can be provided but giving both results in a ValueError. If lines are given but a text is expected, these lines are joined using ‘n’. Likewise, if text is given but lines are expected, text is split into lines.

Parameters:
  • expected_text – output text expectation, as supported by launch_testing.tools.text.build_text_match

  • expected_lines – output lines expectation, as supported by launch_testing.tools.text.build_line_match

  • text – output text to be matched

  • lines – output text lines to be matched

  • strip_ansi_escape_sequences – If True (default), strip ansi escape sequences from actual output before comparing

launch_testing.tools.expected_output_from_file(path)

Get expected output lines from a file.

Parameters:

path – path w/o extension of either a .txt file containing the lines

to be matched or a .regex file containing patterns to be searched for.

launch_testing.tools.launch_process(launch_service, process_action, proc_info, proc_output, **kwargs)

Launch and interact with a process.

On context entering, start execution of a process_action using the given launch_service and yield a ProcessProxy to that process_action. On context exiting, shut the process down if it has not been terminated yet. All additional arguments are forwarded to ProcessProxy on construction.