From 0ec08a672dce3f619e46d0c7455e95a13dc5c4e2 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Wed, 7 Feb 2018 09:36:13 -0500 Subject: [Tests] Move assert_start_raises_init_error method to TestNode --- test/functional/test_framework/test_framework.py | 21 ------------------ test/functional/test_framework/test_node.py | 28 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 21 deletions(-) (limited to 'test/functional/test_framework') diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 8efac9c475..aeb335edb3 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -281,27 +281,6 @@ class BitcoinTestFramework(): self.stop_node(i) self.start_node(i, extra_args) - def assert_start_raises_init_error(self, i, extra_args=None, expected_msg=None, *args, **kwargs): - with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr: - try: - self.start_node(i, extra_args, stderr=log_stderr, *args, **kwargs) - self.stop_node(i) - except Exception as e: - assert 'bitcoind exited' in str(e) # node must have shutdown - self.nodes[i].running = False - self.nodes[i].process = None - 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) - else: - if expected_msg is None: - assert_msg = "bitcoind should have exited with an error" - else: - assert_msg = "bitcoind should have exited with expected error " + expected_msg - raise AssertionError(assert_msg) - def wait_for_node_exit(self, i, timeout): self.nodes[i].process.wait(timeout) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 86e44e4c97..dbdaf67201 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -12,6 +12,7 @@ import logging import os import re import subprocess +import tempfile import time from .authproxy import JSONRPCException @@ -165,6 +166,33 @@ class TestNode(): def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): wait_until(self.is_node_stopped, timeout=timeout) + 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. + + 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.""" + with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr: + try: + self.start(extra_args, stderr=log_stderr, *args, **kwargs) + self.wait_for_rpc_connection() + self.stop_node() + self.wait_util_stopped() + except Exception as e: + assert 'bitcoind exited' in str(e) # node must have shutdown + self.running = False + self.process = None + 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) + else: + if expected_msg is None: + assert_msg = "bitcoind should have exited with an error" + else: + assert_msg = "bitcoind should have exited with expected error " + expected_msg + raise AssertionError(assert_msg) + def node_encrypt_wallet(self, passphrase): """"Encrypts the wallet. -- cgit v1.2.3 From 58122736b53390a2013630e95ff760800af160e7 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Wed, 7 Feb 2018 10:38:25 -0500 Subject: [Tests] Require exact match in assert_start_raises_init_eror() --- test/functional/test_framework/test_node.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test/functional/test_framework') diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index dbdaf67201..8d88069108 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -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" -- cgit v1.2.3 From fae137454adc50a4e1d448ed7219a8f5344486c9 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 19 Mar 2018 15:35:04 -0400 Subject: qa: Allow for partial_match when checking init error This allows the tests to pass on different platforms --- test/functional/test_framework/test_node.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test/functional/test_framework') diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 8d88069108..8d6ec618d5 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -166,7 +166,7 @@ class TestNode(): def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): wait_until(self.is_node_stopped, timeout=timeout) - def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, *args, **kwargs): + def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, partial_match=False, *args, **kwargs): """Attempt to start the node and expect it to raise an error. extra_args: extra arguments to pass through to bitcoind @@ -187,9 +187,13 @@ class TestNode(): # Check stderr for expected message if expected_msg is not None: log_stderr.seek(0) - stderr = log_stderr.read().decode('utf-8') - if re.fullmatch(expected_msg + '\n', stderr) is None: - raise AssertionError('Expected message "{}" does not match stderr:\n"{}"'.format(expected_msg, stderr)) + stderr = log_stderr.read().decode('utf-8').strip() + if partial_match: + if re.search(expected_msg, stderr, flags=re.MULTILINE) is None: + raise AssertionError('Expected message "{}" does not partially match stderr:\n"{}"'.format(expected_msg, stderr)) + else: + if re.fullmatch(expected_msg, stderr) is None: + raise AssertionError('Expected message "{}" does not fully match stderr:\n"{}"'.format(expected_msg, stderr)) else: if expected_msg is None: assert_msg = "bitcoind should have exited with an error" -- cgit v1.2.3