Skip to content

Commit

Permalink
test: Allow pathlib.Path as RPC argument via authproxy
Browse files Browse the repository at this point in the history
Also, add datadir_path property to TestNode
  • Loading branch information
MarcoFalke authored and janus committed Sep 6, 2023
1 parent f528150 commit b4b3485
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/functional/rpc_dumptxoutset.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run_test(self):
# Specifying a path to an existing or invalid file will fail.
assert_raises_rpc_error(
-8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME)
invalid_path = str(Path(node.datadir) / "invalid" / "path")
invalid_path = node.datadir_path / "invalid" / "path"
assert_raises_rpc_error(
-8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path)

Expand Down
3 changes: 3 additions & 0 deletions test/functional/test_framework/authproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import http.client
import json
import logging
import pathlib
import socket
import time
import urllib.parse
Expand All @@ -62,6 +63,8 @@ def __init__(self, rpc_error, http_status=None):
def EncodeDecimal(o):
if isinstance(o, decimal.Decimal):
return str(o)
if isinstance(o, pathlib.Path):
return str(o)
raise TypeError(repr(o) + " is not JSON serializable")

class AuthServiceProxy():
Expand Down
12 changes: 9 additions & 3 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import sys
from pathlib import Path

from .authproxy import JSONRPCException
from .authproxy import (
JSONRPCException,
EncodeDecimal,
)
from .descriptors import descsum_create
from .p2p import P2P_SUBVERSION
from .util import (
Expand All @@ -35,7 +38,6 @@
rpc_url,
wait_until_helper,
p2p_port,
EncodeDecimal,
)

BGLD_PROC_WAIT_TIMEOUT = 60
Expand Down Expand Up @@ -417,9 +419,13 @@ def replace_in_config(self, replacements):
with open(self.BGLconf, '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 Path(self.datadir) / self.chain
return self.datadir_path / self.chain

@property
def debug_log_path(self) -> Path:
Expand Down
6 changes: 0 additions & 6 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ def check_json_precision():
raise RuntimeError("JSON encode/decode loses precision")


def EncodeDecimal(o):
if isinstance(o, Decimal):
return str(o)
raise TypeError(repr(o) + " is not JSON serializable")


def count_bytes(hex_string):
return len(bytearray.fromhex(hex_string))

Expand Down

0 comments on commit b4b3485

Please sign in to comment.