Run the command in app and return what it writes to app.stdout and sys.stderr.
(app: cmd2.Cmd, cmd: str)
| 60 | |
| 61 | |
| 62 | def run_cmd(app: cmd2.Cmd, cmd: str) -> tuple[list[str], list[str]]: |
| 63 | """Run the command in app and return what it writes to app.stdout and sys.stderr.""" |
| 64 | |
| 65 | # This will be used to capture app.stdout |
| 66 | copy_cmd_stdout = StdSim(cast(TextIO, app.stdout)) |
| 67 | |
| 68 | # This will be used to capture sys.stderr |
| 69 | copy_stderr = StdSim(sys.stderr) |
| 70 | |
| 71 | try: |
| 72 | app.stdout = cast(TextIO, copy_cmd_stdout) |
| 73 | with redirect_stderr(cast(TextIO, copy_stderr)): |
| 74 | app.onecmd_plus_hooks(cmd) |
| 75 | finally: |
| 76 | app.stdout = cast(TextIO, copy_cmd_stdout.inner_stream) |
| 77 | |
| 78 | out = copy_cmd_stdout.getvalue() |
| 79 | err = copy_stderr.getvalue() |
| 80 | return normalize(out), normalize(err) |
| 81 | |
| 82 | |
| 83 | @pytest.fixture |
no test coverage detected
searching dependent graphs…