Skip to content

Commit faabd7b

Browse files
author
MarcoFalke
committed
qa: Use files for stdout/stderr to support Windows
1 parent facb56f commit faabd7b

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

test/functional/feature_help.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Verify that starting bitcoin with -h works as expected."""
6-
import subprocess
76

87
from test_framework.test_framework import BitcoinTestFramework
98
from test_framework.util import assert_equal
@@ -17,41 +16,47 @@ def setup_network(self):
1716
self.add_nodes(self.num_nodes)
1817
# Don't start the node
1918

19+
def get_node_output(self, *, ret_code_expected):
20+
ret_code = self.nodes[0].process.wait(timeout=1)
21+
assert_equal(ret_code, ret_code_expected)
22+
self.nodes[0].stdout.seek(0)
23+
self.nodes[0].stderr.seek(0)
24+
out = self.nodes[0].stdout.read()
25+
err = self.nodes[0].stderr.read()
26+
self.nodes[0].stdout.close()
27+
self.nodes[0].stderr.close()
28+
29+
# Clean up TestNode state
30+
self.nodes[0].running = False
31+
self.nodes[0].process = None
32+
self.nodes[0].rpc_connected = False
33+
self.nodes[0].rpc = None
34+
35+
return out, err
36+
2037
def run_test(self):
2138
self.log.info("Start bitcoin with -h for help text")
22-
self.nodes[0].start(extra_args=['-h'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
39+
self.nodes[0].start(extra_args=['-h'])
2340
# Node should exit immediately and output help to stdout.
24-
ret_code = self.nodes[0].process.wait(timeout=1)
25-
assert_equal(ret_code, 0)
26-
output = self.nodes[0].process.stdout.read()
41+
output, _ = self.get_node_output(ret_code_expected=0)
2742
assert b'Options' in output
2843
self.log.info("Help text received: {} (...)".format(output[0:60]))
29-
self.nodes[0].running = False
3044

3145
self.log.info("Start bitcoin with -version for version information")
32-
self.nodes[0].start(extra_args=['-version'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
46+
self.nodes[0].start(extra_args=['-version'])
3347
# Node should exit immediately and output version to stdout.
34-
ret_code = self.nodes[0].process.wait(timeout=1)
35-
assert_equal(ret_code, 0)
36-
output = self.nodes[0].process.stdout.read()
48+
output, _ = self.get_node_output(ret_code_expected=0)
3749
assert b'version' in output
3850
self.log.info("Version text received: {} (...)".format(output[0:60]))
3951

4052
# Test that arguments not in the help results in an error
4153
self.log.info("Start bitcoind with -fakearg to make sure it does not start")
42-
self.nodes[0].start(extra_args=['-fakearg'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
54+
self.nodes[0].start(extra_args=['-fakearg'])
4355
# Node should exit immediately and output an error to stderr
44-
ret_code = self.nodes[0].process.wait(timeout=1)
45-
assert_equal(ret_code, 1)
46-
output = self.nodes[0].process.stderr.read()
56+
_, output = self.get_node_output(ret_code_expected=1)
4757
assert b'Error parsing command line arguments' in output
4858
self.log.info("Error message received: {} (...)".format(output[0:60]))
4959

50-
# Clean up TestNode state
51-
self.nodes[0].running = False
52-
self.nodes[0].process = None
53-
self.nodes[0].rpc_connected = False
54-
self.nodes[0].rpc = None
5560

5661
if __name__ == '__main__':
5762
HelpTest().main()

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __getattr__(self, name):
122122
assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
123123
return getattr(self.rpc, name)
124124

125-
def start(self, extra_args=None, stdout=None, stderr=None, *args, **kwargs):
125+
def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs):
126126
"""Start the node."""
127127
if extra_args is None:
128128
extra_args = self.extra_args
@@ -143,7 +143,7 @@ def start(self, extra_args=None, stdout=None, stderr=None, *args, **kwargs):
143143
# add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal
144144
subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1")
145145

146-
self.process = subprocess.Popen(self.args + extra_args, env=subp_env, stdout=stdout, stderr=stderr, *args, **kwargs)
146+
self.process = subprocess.Popen(self.args + extra_args, env=subp_env, stdout=stdout, stderr=stderr, **kwargs)
147147

148148
self.running = True
149149
self.log.debug("bitcoind started, waiting for RPC to come up")

0 commit comments

Comments
 (0)