Execute a process and asserts the process return code and output. Calls function `fun` with arguments `args` and `kwds`. Catches a CalledProcessError and verifies that the return code and output are as expected. Throws AssertionError if no CalledProcessError was raised or if the return
(returncode: int, output: str, fun: Callable, *args, **kwds)
| 128 | |
| 129 | |
| 130 | def assert_raises_process_error(returncode: int, output: str, fun: Callable, *args, **kwds): |
| 131 | """Execute a process and asserts the process return code and output. |
| 132 | |
| 133 | Calls function `fun` with arguments `args` and `kwds`. Catches a CalledProcessError |
| 134 | and verifies that the return code and output are as expected. Throws AssertionError if |
| 135 | no CalledProcessError was raised or if the return code and output are not as expected. |
| 136 | |
| 137 | Args: |
| 138 | returncode: the process return code. |
| 139 | output: [a substring of] the process output. |
| 140 | fun: the function to call. This should execute a process. |
| 141 | args*: positional arguments for the function. |
| 142 | kwds**: named arguments for the function. |
| 143 | """ |
| 144 | try: |
| 145 | fun(*args, **kwds) |
| 146 | except CalledProcessError as e: |
| 147 | if returncode != e.returncode: |
| 148 | raise AssertionError("Unexpected returncode %i" % e.returncode) |
| 149 | if output not in e.output: |
| 150 | raise AssertionError(f"Expected substring not found in: {e.output!r}") |
| 151 | else: |
| 152 | raise AssertionError("No exception raised") |
| 153 | |
| 154 | |
| 155 | def assert_raises_rpc_error(code: Optional[int], message: Optional[str], fun: Callable, *args, **kwds): |