Skip to content

Commit fae1374

Browse files
author
MarcoFalke
committed
qa: Allow for partial_match when checking init error
This allows the tests to pass on different platforms
1 parent 5812273 commit fae1374

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

test/functional/test_framework/test_node.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def is_node_stopped(self):
166166
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
167167
wait_until(self.is_node_stopped, timeout=timeout)
168168

169-
def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, *args, **kwargs):
169+
def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, partial_match=False, *args, **kwargs):
170170
"""Attempt to start the node and expect it to raise an error.
171171
172172
extra_args: extra arguments to pass through to bitcoind
@@ -187,9 +187,13 @@ def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, *ar
187187
# Check stderr for expected message
188188
if expected_msg is not None:
189189
log_stderr.seek(0)
190-
stderr = log_stderr.read().decode('utf-8')
191-
if re.fullmatch(expected_msg + '\n', stderr) is None:
192-
raise AssertionError('Expected message "{}" does not match stderr:\n"{}"'.format(expected_msg, stderr))
190+
stderr = log_stderr.read().decode('utf-8').strip()
191+
if partial_match:
192+
if re.search(expected_msg, stderr, flags=re.MULTILINE) is None:
193+
raise AssertionError('Expected message "{}" does not partially match stderr:\n"{}"'.format(expected_msg, stderr))
194+
else:
195+
if re.fullmatch(expected_msg, stderr) is None:
196+
raise AssertionError('Expected message "{}" does not fully match stderr:\n"{}"'.format(expected_msg, stderr))
193197
else:
194198
if expected_msg is None:
195199
assert_msg = "bitcoind should have exited with an error"

test/functional/wallet_multiwallet.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Verify that a bitcoind node can load multiple wallet files
88
"""
99
import os
10+
import re
1011
import shutil
1112

1213
from test_framework.test_framework import BitcoinTestFramework
@@ -60,11 +61,8 @@ def run_test(self):
6061
assert_equal(os.path.isfile(wallet_dir(wallet_name)), True)
6162

6263
# should not initialize if wallet path can't be created
63-
exp_stderr = "\n\n\*+\n" + \
64-
"EXCEPTION: .*\n" + \
65-
"boost::filesystem::create_directory: Not a directory:.*\n" + \
66-
"bitcoin in .*\n"
67-
self.nodes[0].assert_start_raises_init_error(['-wallet=wallet.dat/bad'], exp_stderr)
64+
exp_stderr = "boost::filesystem::create_directory: (The system cannot find the path specified|Not a directory):"
65+
self.nodes[0].assert_start_raises_init_error(['-wallet=wallet.dat/bad'], exp_stderr, partial_match=True)
6866

6967
self.nodes[0].assert_start_raises_init_error(['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" does not exist')
7068
self.nodes[0].assert_start_raises_init_error(['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" is a relative path', cwd=data_dir())
@@ -75,11 +73,8 @@ def run_test(self):
7573

7674
# should not initialize if one wallet is a copy of another
7775
shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy'))
78-
exp_stderr = "\n\n\*+\n" + \
79-
"EXCEPTION: .*\n" + \
80-
"CDB: Can't open database w8_copy \(duplicates fileid \w+ from w8\)\s*\n" + \
81-
"bitcoin in .*\n"
82-
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr)
76+
exp_stderr = "CDB: Can't open database w8_copy \(duplicates fileid \w+ from w8\)"
77+
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr, partial_match=True)
8378

8479
# should not initialize if wallet file is a symlink
8580
os.symlink('w8', wallet_dir('w8_symlink'))
@@ -90,7 +85,7 @@ def run_test(self):
9085
# should not initialize if the specified walletdir is not a directory
9186
not_a_dir = wallet_dir('notadir')
9287
open(not_a_dir, 'a').close()
93-
self.nodes[0].assert_start_raises_init_error(['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
88+
self.nodes[0].assert_start_raises_init_error(['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + re.escape(not_a_dir) + '" is not a directory')
9489

9590
# if wallets/ doesn't exist, datadir should be the default wallet dir
9691
wallet_dir2 = data_dir('walletdir')
@@ -112,7 +107,7 @@ def run_test(self):
112107
os.mkdir(competing_wallet_dir)
113108
self.restart_node(0, ['-walletdir=' + competing_wallet_dir])
114109
exp_stderr = "Error: Error initializing wallet database environment \"\S+competing_walletdir\"!"
115-
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr)
110+
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr, partial_match=True)
116111

117112
self.restart_node(0, extra_args)
118113

0 commit comments

Comments
 (0)