Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/coverage.py
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def __call__(self, *args, **kwargs): | ||||
self._log_call() | self._log_call() | ||||
return return_val | return return_val | ||||
def _log_call(self): | def _log_call(self): | ||||
rpc_method = self.auth_service_proxy_instance._service_name | rpc_method = self.auth_service_proxy_instance._service_name | ||||
if self.coverage_logfile: | if self.coverage_logfile: | ||||
with open(self.coverage_logfile, 'a+', encoding='utf8') as f: | with open(self.coverage_logfile, 'a+', encoding='utf8') as f: | ||||
f.write("%s\n" % rpc_method) | f.write("{}\n".format(rpc_method)) | ||||
def __truediv__(self, relative_uri): | def __truediv__(self, relative_uri): | ||||
return AuthServiceProxyWrapper(self.auth_service_proxy_instance / relative_uri, | return AuthServiceProxyWrapper(self.auth_service_proxy_instance / relative_uri, | ||||
self.coverage_logfile) | self.coverage_logfile) | ||||
def get_request(self, *args, **kwargs): | def get_request(self, *args, **kwargs): | ||||
self._log_call() | self._log_call() | ||||
return self.auth_service_proxy_instance.get_request(*args, **kwargs) | return self.auth_service_proxy_instance.get_request(*args, **kwargs) | ||||
def get_filename(dirname, n_node): | def get_filename(dirname, n_node): | ||||
""" | """ | ||||
Get a filename unique to the test process ID and node. | Get a filename unique to the test process ID and node. | ||||
This file will contain a list of RPC commands covered. | This file will contain a list of RPC commands covered. | ||||
""" | """ | ||||
pid = str(os.getpid()) | pid = str(os.getpid()) | ||||
return os.path.join( | return os.path.join( | ||||
dirname, "coverage.pid%s.node%s.txt" % (pid, str(n_node))) | dirname, "coverage.pid{}.node{}.txt".format(pid, str(n_node))) | ||||
def write_all_rpc_commands(dirname, node): | def write_all_rpc_commands(dirname, node): | ||||
""" | """ | ||||
Write out a list of all RPC functions available in `bitcoin-cli` for | Write out a list of all RPC functions available in `bitcoin-cli` for | ||||
coverage comparison. This will only happen once per coverage | coverage comparison. This will only happen once per coverage | ||||
directory. | directory. | ||||
Show All 13 Lines | def write_all_rpc_commands(dirname, node): | ||||
help_output = node.help().split('\n') | help_output = node.help().split('\n') | ||||
commands = set() | commands = set() | ||||
for line in help_output: | for line in help_output: | ||||
line = line.strip() | line = line.strip() | ||||
# Ignore blanks and headers | # Ignore blanks and headers | ||||
if line and not line.startswith('='): | if line and not line.startswith('='): | ||||
commands.add("%s\n" % line.split()[0]) | commands.add("{}\n".format(line.split()[0])) | ||||
with open(filename, 'w', encoding='utf8') as f: | with open(filename, 'w', encoding='utf8') as f: | ||||
f.writelines(list(commands)) | f.writelines(list(commands)) | ||||
return True | return True |