diff options
author | MarcoFalke <falke.marco@gmail.com> | 2018-08-24 14:07:20 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2018-08-24 14:07:24 -0400 |
commit | 55c18a45305f9e89a726f8cf82a7b16a2ab7f955 (patch) | |
tree | 9f7acf9dc060cd9765fcc4ae1a2671b199ba07f3 /test/functional/test_framework | |
parent | 540bf8aacc50aae0ea5beb76511905a7d2a3e15f (diff) | |
parent | fa3e9f7627784ee00980590e5bf044a0e1249999 (diff) | |
download | bitcoin-55c18a45305f9e89a726f8cf82a7b16a2ab7f955.tar.xz |
Merge #14024: qa: Add TestNode::assert_debug_log
fa3e9f7627 qa: Add TestNode::assert_debug_log (MarcoFalke)
Pull request description:
Closes #13006
Tree-SHA512: 8e2d2331039d70525a425aad65a4eaf9b83fb1f85a4260d69453176f04dbede6dd9b7bb4d5f089b46cf8f8c98571aa6ba7fac8fa6847bb3bdf6a6ad21a27b1a7
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-x | test/functional/test_framework/test_node.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 0d00cc2082..a831fdcd5d 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -4,6 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Class for bitcoind node under test""" +import contextlib import decimal import errno from enum import Enum @@ -229,6 +230,23 @@ class TestNode(): def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): wait_until(self.is_node_stopped, timeout=timeout) + @contextlib.contextmanager + def assert_debug_log(self, expected_msgs): + debug_log = os.path.join(self.datadir, 'regtest', 'debug.log') + with open(debug_log, encoding='utf-8') as dl: + dl.seek(0, 2) + prev_size = dl.tell() + try: + yield + finally: + with open(debug_log, encoding='utf-8') as dl: + dl.seek(prev_size) + log = dl.read() + print_log = " - " + "\n - ".join(log.splitlines()) + for expected_msg in expected_msgs: + if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None: + self._raise_assertion_error('Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log)) + def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, match=ErrorMatch.FULL_TEXT, *args, **kwargs): """Attempt to start the node and expect it to raise an error. |