Skip to content

Commit fabd348

Browse files
author
MarcoFalke
committed
test: Rename EncodeDecimal to serialization_fallback
The new name better explains that the function handles fallbacks, without listing all in the function name.
1 parent c6287fa commit fabd348

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

test/functional/test_framework/authproxy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, rpc_error, http_status=None):
6060
self.http_status = http_status
6161

6262

63-
def EncodeDecimal(o):
63+
def serialization_fallback(o):
6464
if isinstance(o, decimal.Decimal):
6565
return str(o)
6666
if isinstance(o, pathlib.Path):
@@ -111,7 +111,7 @@ def get_request(self, *args, **argsn):
111111
log.debug("-{}-> {} {}".format(
112112
AuthServiceProxy.__id_count,
113113
self._service_name,
114-
json.dumps(args or argsn, default=EncodeDecimal, ensure_ascii=self.ensure_ascii),
114+
json.dumps(args or argsn, default=serialization_fallback, ensure_ascii=self.ensure_ascii),
115115
))
116116
if args and argsn:
117117
params = dict(args=args, **argsn)
@@ -123,7 +123,7 @@ def get_request(self, *args, **argsn):
123123
'id': AuthServiceProxy.__id_count}
124124

125125
def __call__(self, *args, **argsn):
126-
postdata = json.dumps(self.get_request(*args, **argsn), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
126+
postdata = json.dumps(self.get_request(*args, **argsn), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
127127
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
128128
if response['error'] is not None:
129129
raise JSONRPCException(response['error'], status)
@@ -137,7 +137,7 @@ def __call__(self, *args, **argsn):
137137
return response['result']
138138

139139
def batch(self, rpc_call_list):
140-
postdata = json.dumps(list(rpc_call_list), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
140+
postdata = json.dumps(list(rpc_call_list), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
141141
log.debug("--> " + postdata)
142142
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
143143
if status != HTTPStatus.OK:
@@ -170,7 +170,7 @@ def _get_response(self):
170170
response = json.loads(responsedata, parse_float=decimal.Decimal)
171171
elapsed = time.time() - req_start_time
172172
if "error" in response and response["error"] is None:
173-
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=EncodeDecimal, ensure_ascii=self.ensure_ascii)))
173+
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
174174
else:
175175
log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
176176
return response, http_response.status

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from .authproxy import (
2626
JSONRPCException,
27-
EncodeDecimal,
27+
serialization_fallback,
2828
)
2929
from .descriptors import descsum_create
3030
from .p2p import P2P_SUBVERSION
@@ -714,7 +714,7 @@ def arg_to_cli(arg):
714714
elif arg is None:
715715
return 'null'
716716
elif isinstance(arg, dict) or isinstance(arg, list):
717-
return json.dumps(arg, default=EncodeDecimal)
717+
return json.dumps(arg, default=serialization_fallback)
718718
else:
719719
return str(arg)
720720

0 commit comments

Comments
 (0)