Run a command and check it returns the expected output. A timeout guards against hangs (e.g., GTK main loop not quitting). On timeout, the child is killed and any captured output is logged to aid troubleshooting.
(args, expected_output, timeout=120)
| 141 | |
| 142 | |
| 143 | def assert_execute(args, expected_output, timeout=120): |
| 144 | """Run a command and check it returns the expected output. |
| 145 | |
| 146 | A timeout guards against hangs (e.g., GTK main loop not quitting). |
| 147 | On timeout, the child is killed and any captured output is logged |
| 148 | to aid troubleshooting. |
| 149 | """ |
| 150 | try: |
| 151 | actual_output = subprocess.check_output( |
| 152 | args, stderr=subprocess.STDOUT, timeout=timeout).decode(SetupEncoding) |
| 153 | except subprocess.TimeoutExpired as e: |
| 154 | partial = (e.output or b'').decode(SetupEncoding, errors='replace') |
| 155 | logger.error('Command %s timed out after %ss. Partial output:\n%s', |
| 156 | args, timeout, partial) |
| 157 | raise RuntimeError(f'Timeout running {args} after {timeout}s') from e |
| 158 | if -1 == actual_output.find(expected_output): |
| 159 | raise RuntimeError( |
| 160 | f'When running command {args} expected output {expected_output} but got {actual_output}') |
| 161 | |
| 162 | |
| 163 | def assert_execute_console(): |
no outgoing calls
no test coverage detected