Skip to content

Commit b6dbd8b

Browse files
fanquakePastaPastaPasta
authored andcommitted
Merge bitcoin#22092: test: convert documentation into type annotations
68ace23 test: convert docs into type annotations in test_framework/test_node.py (fanquake) 8bfcba3 test: convert docs into type annotations in test_framework/wallet.py (fanquake) b043ca8 test: convert docs into type annotations in test_framework/util.py (fanquake) Pull request description: Rather than having function types exist as documentation, make them type annotations, which enables more `mypy` checking. ACKs for top commit: instagibbs: utACK bitcoin@68ace23 Tree-SHA512: b705f26b48baabde07b9b2c0a8d547b4dcca291b16eaf5ac70462bb3a1f9e9c2783d93a9d4290889d0cbb3f7db3671446754411a1f498b265d336f6ff33478df
1 parent cc70886 commit b6dbd8b

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,14 @@ def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2):
419419
self._raise_assertion_error('Expected messages "{}" does not partially match log:\n\n{}\n\n'.format(str(expected_msgs), print_log))
420420

421421
@contextlib.contextmanager
422-
def profile_with_perf(self, profile_name):
422+
def profile_with_perf(self, profile_name: str):
423423
"""
424424
Context manager that allows easy profiling of node activity using `perf`.
425425
426426
See `test/functional/README.md` for details on perf usage.
427427
428428
Args:
429-
profile_name (str): This string will be appended to the
429+
profile_name: This string will be appended to the
430430
profile data filename generated by perf.
431431
"""
432432
subp = self._start_perf(profile_name)

test/functional/test_framework/util.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from . import coverage
2121
from .authproxy import AuthServiceProxy, JSONRPCException
22+
from typing import Callable, Optional
2223

2324
logger = logging.getLogger("TestFramework.utils")
2425

@@ -79,17 +80,17 @@ def assert_raises_message(exc, message, fun, *args, **kwds):
7980
raise AssertionError("No exception raised")
8081

8182

82-
def assert_raises_process_error(returncode, output, fun, *args, **kwds):
83+
def assert_raises_process_error(returncode: int, output: str, fun: Callable, *args, **kwds):
8384
"""Execute a process and asserts the process return code and output.
8485
8586
Calls function `fun` with arguments `args` and `kwds`. Catches a CalledProcessError
8687
and verifies that the return code and output are as expected. Throws AssertionError if
8788
no CalledProcessError was raised or if the return code and output are not as expected.
8889
8990
Args:
90-
returncode (int): the process return code.
91-
output (string): [a substring of] the process output.
92-
fun (function): the function to call. This should execute a process.
91+
returncode: the process return code.
92+
output: [a substring of] the process output.
93+
fun: the function to call. This should execute a process.
9394
args*: positional arguments for the function.
9495
kwds**: named arguments for the function.
9596
"""
@@ -104,19 +105,19 @@ def assert_raises_process_error(returncode, output, fun, *args, **kwds):
104105
raise AssertionError("No exception raised")
105106

106107

107-
def assert_raises_rpc_error(code, message, fun, *args, **kwds):
108+
def assert_raises_rpc_error(code: Optional[int], message: Optional[str], fun: Callable, *args, **kwds):
108109
"""Run an RPC and verify that a specific JSONRPC exception code and message is raised.
109110
110111
Calls function `fun` with arguments `args` and `kwds`. Catches a JSONRPCException
111112
and verifies that the error code and message are as expected. Throws AssertionError if
112113
no JSONRPCException was raised or if the error code/message are not as expected.
113114
114115
Args:
115-
code (int), optional: the error code returned by the RPC call (defined
116-
in src/rpc/protocol.h). Set to None if checking the error code is not required.
117-
message (string), optional: [a substring of] the error string returned by the
118-
RPC call. Set to None if checking the error string is not required.
119-
fun (function): the function to call. This should be the name of an RPC.
116+
code: the error code returned by the RPC call (defined in src/rpc/protocol.h).
117+
Set to None if checking the error code is not required.
118+
message: [a substring of] the error string returned by the RPC call.
119+
Set to None if checking the error string is not required.
120+
fun: the function to call. This should be the name of an RPC.
120121
args*: positional arguments for the function.
121122
kwds**: named arguments for the function.
122123
"""

test/functional/test_framework/wallet.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from decimal import Decimal
88
from test_framework.address import ADDRESS_BCRT1_P2SH_OP_TRUE
9+
from typing import Optional
910
from test_framework.messages import (
1011
COIN,
1112
COutPoint,
@@ -42,12 +43,12 @@ def generate(self, num_blocks):
4243
def get_address(self):
4344
return self._address
4445

45-
def get_utxo(self, *, txid=''):
46+
def get_utxo(self, *, txid: Optional[str]=''):
4647
"""
4748
Returns a utxo and marks it as spent (pops it from the internal list)
4849
4950
Args:
50-
txid (string), optional: get the first utxo we find from a specific transaction
51+
txid: get the first utxo we find from a specific transaction
5152
5253
Note: Can be used to get the change output immediately after a send_self_transfer
5354
"""

0 commit comments

Comments
 (0)