Skip to content

Commit b4b3485

Browse files
MarcoFalkejanus
authored andcommitted
test: Allow pathlib.Path as RPC argument via authproxy
Also, add datadir_path property to TestNode
1 parent f528150 commit b4b3485

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

test/functional/rpc_dumptxoutset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def run_test(self):
5353
# Specifying a path to an existing or invalid file will fail.
5454
assert_raises_rpc_error(
5555
-8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME)
56-
invalid_path = str(Path(node.datadir) / "invalid" / "path")
56+
invalid_path = node.datadir_path / "invalid" / "path"
5757
assert_raises_rpc_error(
5858
-8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path)
5959

test/functional/test_framework/authproxy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import http.client
4040
import json
4141
import logging
42+
import pathlib
4243
import socket
4344
import time
4445
import urllib.parse
@@ -62,6 +63,8 @@ def __init__(self, rpc_error, http_status=None):
6263
def EncodeDecimal(o):
6364
if isinstance(o, decimal.Decimal):
6465
return str(o)
66+
if isinstance(o, pathlib.Path):
67+
return str(o)
6568
raise TypeError(repr(o) + " is not JSON serializable")
6669

6770
class AuthServiceProxy():

test/functional/test_framework/test_node.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
import sys
2323
from pathlib import Path
2424

25-
from .authproxy import JSONRPCException
25+
from .authproxy import (
26+
JSONRPCException,
27+
EncodeDecimal,
28+
)
2629
from .descriptors import descsum_create
2730
from .p2p import P2P_SUBVERSION
2831
from .util import (
@@ -35,7 +38,6 @@
3538
rpc_url,
3639
wait_until_helper,
3740
p2p_port,
38-
EncodeDecimal,
3941
)
4042

4143
BGLD_PROC_WAIT_TIMEOUT = 60
@@ -417,9 +419,13 @@ def replace_in_config(self, replacements):
417419
with open(self.BGLconf, 'w', encoding='utf8') as conf:
418420
conf.write(conf_data)
419421

422+
@property
423+
def datadir_path(self) -> Path:
424+
return Path(self.datadir)
425+
420426
@property
421427
def chain_path(self) -> Path:
422-
return Path(self.datadir) / self.chain
428+
return self.datadir_path / self.chain
423429

424430
@property
425431
def debug_log_path(self) -> Path:

test/functional/test_framework/util.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ def check_json_precision():
211211
raise RuntimeError("JSON encode/decode loses precision")
212212

213213

214-
def EncodeDecimal(o):
215-
if isinstance(o, Decimal):
216-
return str(o)
217-
raise TypeError(repr(o) + " is not JSON serializable")
218-
219-
220214
def count_bytes(hex_string):
221215
return len(bytearray.fromhex(hex_string))
222216

0 commit comments

Comments
 (0)