MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / assert_raises_process_error

Function assert_raises_process_error

test/functional/test_framework/util.py:130–152  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

128
129
130def 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
155def assert_raises_rpc_error(code: Optional[int], message: Optional[str], fun: Callable, *args, **kwds):

Callers 1

run_testMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected