[Tests] Require exact match in assert_start_raises_init_eror()

This commit is contained in:
John Newbery
2018-02-07 10:38:25 -05:00
committed by MarcoFalke
parent 0ec08a672d
commit 58122736b5
6 changed files with 35 additions and 18 deletions

View File

@@ -169,8 +169,11 @@ class TestNode():
def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, *args, **kwargs):
"""Attempt to start the node and expect it to raise an error.
extra_args: extra arguments to pass through to bitcoind
expected_msg: regex that stderr should match when bitcoind fails
Will throw if bitcoind starts without an error.
Will throw if an expected_msg is provided and it does not appear in bitcoind's stdout."""
Will throw if an expected_msg is provided and it does not match bitcoind's stdout."""
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
try:
self.start(extra_args, stderr=log_stderr, *args, **kwargs)
@@ -181,11 +184,12 @@ class TestNode():
assert 'bitcoind exited' in str(e) # node must have shutdown
self.running = False
self.process = None
# Check stderr for expected message
if expected_msg is not None:
log_stderr.seek(0)
stderr = log_stderr.read().decode('utf-8')
if expected_msg not in stderr:
raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr)
if re.fullmatch(expected_msg + '\n', stderr) is None:
raise AssertionError('Expected message "{}" does not match stderr:\n"{}"'.format(expected_msg, stderr))
else:
if expected_msg is None:
assert_msg = "bitcoind should have exited with an error"