Skip to content

Commit 1581ecb

Browse files
committed
Use configparser in rpc-tests.py
Remove the use of wildcard imports in rpc-tests.py and replace with configparser.
1 parent a7ea2f8 commit 1581ecb

File tree

5 files changed

+41
-36
lines changed

5 files changed

+41
-36
lines changed

Makefile.am

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ EXTRA_DIST = $(top_srcdir)/share/genbuild.sh qa/pull-tester/rpc-tests.py qa/rpc-
227227

228228
CLEANFILES = $(OSX_DMG) $(BITCOIN_WIN_INSTALLER)
229229

230-
# This file is problematic for out-of-tree builds if it exists.
231-
DISTCLEANFILES = qa/pull-tester/tests_config.pyc
232-
233230
.INTERMEDIATE: $(COVERAGE_INFO)
234231

235232
DISTCHECK_CONFIGURE_FLAGS = --enable-man

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ AC_SUBST(ZMQ_LIBS)
10871087
AC_SUBST(PROTOBUF_LIBS)
10881088
AC_SUBST(QR_LIBS)
10891089
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist src/test/buildenv.py])
1090-
AC_CONFIG_FILES([qa/pull-tester/tests_config.py],[chmod +x qa/pull-tester/tests_config.py])
1090+
AC_CONFIG_FILES([qa/pull-tester/tests_config.ini],[chmod +x qa/pull-tester/tests_config.ini])
10911091
AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
10921092
AC_CONFIG_LINKS([qa/pull-tester/rpc-tests.py:qa/pull-tester/rpc-tests.py])
10931093

qa/pull-tester/rpc-tests.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
"""
2323

24+
import configparser
2425
import os
2526
import time
2627
import shutil
@@ -29,26 +30,22 @@
2930
import tempfile
3031
import re
3132

32-
sys.path.append("qa/pull-tester/")
33-
from tests_config import *
34-
3533
BOLD = ("","")
3634
if os.name == 'posix':
3735
# primitive formatting on supported
3836
# terminal via ANSI escape sequences:
3937
BOLD = ('\033[0m', '\033[1m')
4038

41-
RPC_TESTS_DIR = SRCDIR + '/qa/rpc-tests/'
39+
# Read config generated by configure.
40+
config = configparser.ConfigParser()
41+
config.read_file(open(os.path.dirname(__file__) + "/tests_config.ini"))
42+
43+
ENABLE_WALLET = config["components"]["ENABLE_WALLET"] == "True"
44+
ENABLE_UTILS = config["components"]["ENABLE_UTILS"] == "True"
45+
ENABLE_BITCOIND = config["components"]["ENABLE_BITCOIND"] == "True"
46+
ENABLE_ZMQ = config["components"]["ENABLE_ZMQ"] == "True"
4247

43-
#If imported values are not defined then set to zero (or disabled)
44-
if 'ENABLE_WALLET' not in vars():
45-
ENABLE_WALLET=0
46-
if 'ENABLE_BITCOIND' not in vars():
47-
ENABLE_BITCOIND=0
48-
if 'ENABLE_UTILS' not in vars():
49-
ENABLE_UTILS=0
50-
if 'ENABLE_ZMQ' not in vars():
51-
ENABLE_ZMQ=0
48+
RPC_TESTS_DIR = config["environment"]["SRCDIR"] + '/qa/rpc-tests/'
5249

5350
ENABLE_COVERAGE=0
5451

@@ -76,15 +73,15 @@
7673

7774
#Set env vars
7875
if "BITCOIND" not in os.environ:
79-
os.environ["BITCOIND"] = BUILDDIR + '/src/bitcoind' + EXEEXT
76+
os.environ["BITCOIND"] = config["environment"]["BUILDDIR"] + '/src/bitcoind' + config["environment"]["EXEEXT"]
8077

81-
if EXEEXT == ".exe" and "-win" not in opts:
78+
if config["environment"]["EXEEXT"] == ".exe" and "-win" not in opts:
8279
# https://github.com/bitcoin/bitcoin/commit/d52802551752140cf41f0d9a225a43e84404d3e9
8380
# https://github.com/bitcoin/bitcoin/pull/5677#issuecomment-136646964
8481
print("Win tests currently disabled by default. Use -win option to enable")
8582
sys.exit(0)
8683

87-
if not (ENABLE_WALLET == 1 and ENABLE_UTILS == 1 and ENABLE_BITCOIND == 1):
84+
if not (ENABLE_WALLET and ENABLE_UTILS and ENABLE_BITCOIND):
8885
print("No rpc tests to run. Wallet, utils, and bitcoind must all be enabled")
8986
sys.exit(0)
9087

@@ -209,8 +206,8 @@ def runtests():
209206
if ENABLE_COVERAGE:
210207
coverage = RPCCoverage()
211208
print("Initializing coverage directory at %s\n" % coverage.dir)
212-
flags = ["--srcdir=%s/src" % BUILDDIR] + passon_args
213-
flags.append("--cachedir=%s/qa/cache" % BUILDDIR)
209+
flags = ["--srcdir=%s/src" % config["environment"]["BUILDDIR"]] + passon_args
210+
flags.append("--cachedir=%s/qa/cache" % config["environment"]["BUILDDIR"])
214211
if coverage:
215212
flags.append(coverage.flag)
216213

qa/pull-tester/tests_config.ini.in

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2013-2016 The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
# These environment variables are set by the build process and read by
6+
# rpc-tests.py
7+
8+
[DEFAULT]
9+
# Provides default values for whether different components are enabled
10+
ENABLE_WALLET=False
11+
ENABLE_UTILS=False
12+
ENABLE_BITCOIND=False
13+
ENABLE_ZMQ=False
14+
15+
[environment]
16+
SRCDIR=@abs_top_srcdir@
17+
BUILDDIR=@abs_top_builddir@
18+
EXEEXT=@EXEEXT@
19+
20+
[components]
21+
# Which components are enabled. These are commented out by `configure` if they were disabled when running config.
22+
@ENABLE_WALLET_TRUE@ENABLE_WALLET=True
23+
@BUILD_BITCOIN_UTILS_TRUE@ENABLE_UTILS=True
24+
@BUILD_BITCOIND_TRUE@ENABLE_BITCOIND=True
25+
@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=True

qa/pull-tester/tests_config.py.in

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)