test: add type annotations to util.get_rpc_proxy

Remove proxy.url assignment:
error: "AuthServiceProxy" has no attribute "url"
This commit is contained in:
fanquake
2021-05-28 12:03:37 +08:00
parent 1488f55fa5
commit fbeb8c43bc
3 changed files with 19 additions and 17 deletions

View File

@@ -10,6 +10,7 @@ testing.
import os
from .authproxy import AuthServiceProxy
REFERENCE_FILENAME = 'rpc_interface.txt'
@@ -19,16 +20,17 @@ class AuthServiceProxyWrapper():
An object that wraps AuthServiceProxy to record specific RPC calls.
"""
def __init__(self, auth_service_proxy_instance, coverage_logfile=None):
def __init__(self, auth_service_proxy_instance: AuthServiceProxy, rpc_url: str, coverage_logfile: str=None):
"""
Kwargs:
auth_service_proxy_instance (AuthServiceProxy): the instance
being wrapped.
coverage_logfile (str): if specified, write each service_name
auth_service_proxy_instance: the instance being wrapped.
rpc_url: url of the RPC instance being wrapped
coverage_logfile: if specified, write each service_name
out to a file when called.
"""
self.auth_service_proxy_instance = auth_service_proxy_instance
self.rpc_url = rpc_url
self.coverage_logfile = coverage_logfile
def __getattr__(self, name):
@@ -36,7 +38,7 @@ class AuthServiceProxyWrapper():
if not isinstance(return_val, type(self.auth_service_proxy_instance)):
# If proxy getattr returned an unwrapped value, do the same here.
return return_val
return AuthServiceProxyWrapper(return_val, self.coverage_logfile)
return AuthServiceProxyWrapper(return_val, self.rpc_url, self.coverage_logfile)
def __call__(self, *args, **kwargs):
"""
@@ -57,6 +59,7 @@ class AuthServiceProxyWrapper():
def __truediv__(self, relative_uri):
return AuthServiceProxyWrapper(self.auth_service_proxy_instance / relative_uri,
self.rpc_url,
self.coverage_logfile)
def get_request(self, *args, **kwargs):
@@ -74,18 +77,18 @@ def get_filename(dirname, n_node):
dirname, "coverage.pid%s.node%s.txt" % (pid, str(n_node)))
def write_all_rpc_commands(dirname, node):
def write_all_rpc_commands(dirname: str, node: AuthServiceProxy) -> bool:
"""
Write out a list of all RPC functions available in `bitcoin-cli` for
coverage comparison. This will only happen once per coverage
directory.
Args:
dirname (str): temporary test dir
node (AuthServiceProxy): client
dirname: temporary test dir
node: client
Returns:
bool. if the RPC interface file was written.
if the RPC interface file was written.
"""
filename = os.path.join(dirname, REFERENCE_FILENAME)