mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-01 16:31:33 +01:00
test: Use pathlib over os.path #28362
revert netutil chgs py3.8 compliant fixes based on PR review
This commit is contained in:
@@ -67,7 +67,7 @@ class TestNode():
|
||||
To make things easier for the test writer, any unrecognised messages will
|
||||
be dispatched to the RPC connection."""
|
||||
|
||||
def __init__(self, i, datadir, *, chain, rpchost, timewait, timeout_factor, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False):
|
||||
def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False):
|
||||
"""
|
||||
Kwargs:
|
||||
start_perf (bool): If True, begin profiling the node with `perf` as soon as
|
||||
@@ -76,10 +76,10 @@ class TestNode():
|
||||
|
||||
self.index = i
|
||||
self.p2p_conn_index = 1
|
||||
self.datadir = datadir
|
||||
self.bitcoinconf = os.path.join(self.datadir, "bitcoin.conf")
|
||||
self.stdout_dir = os.path.join(self.datadir, "stdout")
|
||||
self.stderr_dir = os.path.join(self.datadir, "stderr")
|
||||
self.datadir_path = datadir_path
|
||||
self.bitcoinconf = self.datadir_path / "bitcoin.conf"
|
||||
self.stdout_dir = self.datadir_path / "stdout"
|
||||
self.stderr_dir = self.datadir_path / "stderr"
|
||||
self.chain = chain
|
||||
self.rpchost = rpchost
|
||||
self.rpc_timeout = timewait
|
||||
@@ -88,7 +88,7 @@ class TestNode():
|
||||
self.cwd = cwd
|
||||
self.descriptors = descriptors
|
||||
if extra_conf is not None:
|
||||
append_config(datadir, extra_conf)
|
||||
append_config(self.datadir_path, extra_conf)
|
||||
# Most callers will just need to add extra args to the standard list below.
|
||||
# For those callers that need more flexibility, they can just set the args property directly.
|
||||
# Note that common args are set in the config file (see initialize_datadir)
|
||||
@@ -99,7 +99,7 @@ class TestNode():
|
||||
# spam debug.log.
|
||||
self.args = [
|
||||
self.binary,
|
||||
"-datadir=" + self.datadir,
|
||||
f"-datadir={self.datadir_path}",
|
||||
"-logtimemicros",
|
||||
"-debug",
|
||||
"-debugexclude=libevent",
|
||||
@@ -111,9 +111,7 @@ class TestNode():
|
||||
self.args.append("-disablewallet")
|
||||
|
||||
if use_valgrind:
|
||||
default_suppressions_file = os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
"..", "..", "..", "contrib", "valgrind.supp")
|
||||
default_suppressions_file = Path(__file__).parents[3] / "contrib" / "valgrind.supp"
|
||||
suppressions_file = os.getenv("VALGRIND_SUPPRESSIONS_FILE",
|
||||
default_suppressions_file)
|
||||
self.args = ["valgrind", "--suppressions={}".format(suppressions_file),
|
||||
@@ -127,7 +125,7 @@ class TestNode():
|
||||
if self.version_is_at_least(239000):
|
||||
self.args.append("-loglevel=trace")
|
||||
|
||||
self.cli = TestNodeCLI(bitcoin_cli, self.datadir)
|
||||
self.cli = TestNodeCLI(bitcoin_cli, self.datadir_path)
|
||||
self.use_cli = use_cli
|
||||
self.start_perf = start_perf
|
||||
|
||||
@@ -213,7 +211,7 @@ class TestNode():
|
||||
# Delete any existing cookie file -- if such a file exists (eg due to
|
||||
# unclean shutdown), it will get overwritten anyway by bitcoind, and
|
||||
# potentially interfere with our attempt to authenticate
|
||||
delete_cookie_file(self.datadir, self.chain)
|
||||
delete_cookie_file(self.datadir_path, self.chain)
|
||||
|
||||
# add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal
|
||||
subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1")
|
||||
@@ -243,7 +241,7 @@ class TestNode():
|
||||
f'bitcoind exited with status {self.process.returncode} during initialization. {str_error}'))
|
||||
try:
|
||||
rpc = get_rpc_proxy(
|
||||
rpc_url(self.datadir, self.index, self.chain, self.rpchost),
|
||||
rpc_url(self.datadir_path, self.index, self.chain, self.rpchost),
|
||||
self.index,
|
||||
timeout=self.rpc_timeout // 2, # Shorter timeout to allow for one retry in case of ETIMEDOUT
|
||||
coveragedir=self.coverage_dir,
|
||||
@@ -307,7 +305,7 @@ class TestNode():
|
||||
poll_per_s = 4
|
||||
for _ in range(poll_per_s * self.rpc_timeout):
|
||||
try:
|
||||
get_auth_cookie(self.datadir, self.chain)
|
||||
get_auth_cookie(self.datadir_path, self.chain)
|
||||
self.log.debug("Cookie credentials successfully retrieved")
|
||||
return
|
||||
except ValueError: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting
|
||||
@@ -424,10 +422,6 @@ class TestNode():
|
||||
with open(self.bitcoinconf, 'w', encoding='utf8') as conf:
|
||||
conf.write(conf_data)
|
||||
|
||||
@property
|
||||
def datadir_path(self) -> Path:
|
||||
return Path(self.datadir)
|
||||
|
||||
@property
|
||||
def chain_path(self) -> Path:
|
||||
return self.datadir_path / self.chain
|
||||
@@ -556,7 +550,7 @@ class TestNode():
|
||||
"perf output won't be very useful without debug symbols compiled into bitcoind")
|
||||
|
||||
output_path = tempfile.NamedTemporaryFile(
|
||||
dir=self.datadir,
|
||||
dir=self.datadir_path,
|
||||
prefix="{}.perf.data.".format(profile_name or 'test'),
|
||||
delete=False,
|
||||
).name
|
||||
@@ -783,7 +777,7 @@ class TestNodeCLI():
|
||||
"""Run bitcoin-cli command. Deserializes returned string as python object."""
|
||||
pos_args = [arg_to_cli(arg) for arg in args]
|
||||
named_args = [str(key) + "=" + arg_to_cli(value) for (key, value) in kwargs.items()]
|
||||
p_args = [self.binary, "-datadir=" + self.datadir] + self.options
|
||||
p_args = [self.binary, f"-datadir={self.datadir}"] + self.options
|
||||
if named_args:
|
||||
p_args += ["-named"]
|
||||
if command is not None:
|
||||
|
||||
Reference in New Issue
Block a user