Skip to content

Commit c623146

Browse files
committed
test: back port assert_debug_log(expected_msg)
1 parent b0a0227 commit c623146

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/functional/test_framework/test_node.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Class for pivxd node under test"""
66

7+
import contextlib
78
import decimal
89
import errno
910
import http.client
@@ -201,6 +202,23 @@ def is_node_stopped(self):
201202
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
202203
wait_until(self.is_node_stopped, timeout=timeout)
203204

205+
@contextlib.contextmanager
206+
def assert_debug_log(self, expected_msgs):
207+
debug_log = os.path.join(self.datadir, 'regtest', 'debug.log')
208+
with open(debug_log, encoding='utf-8') as dl:
209+
dl.seek(0, 2)
210+
prev_size = dl.tell()
211+
try:
212+
yield
213+
finally:
214+
with open(debug_log, encoding='utf-8') as dl:
215+
dl.seek(prev_size)
216+
log = dl.read()
217+
print_log = " - " + "\n - ".join(log.splitlines())
218+
for expected_msg in expected_msgs:
219+
if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None:
220+
self._raise_assertion_error('Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log))
221+
204222
def node_encrypt_wallet(self, passphrase):
205223
""""Encrypts the wallet.
206224

0 commit comments

Comments
 (0)