Skip to content

Commit 0df7a6c

Browse files
committed
Merge #13944: test: Port usage of deprecated optparse module to argparse module
5654efb Ported usage of deprecated optparse module to argparse module (Kvaciral) Pull request description: The optparse module is deprecated since Python 2,7/3.2 . Recommend usage of the argparse module which improves upon optparse. Tree-SHA512: ffd0e3e6f3babef1675226b107eeb7a6bab6e5199de572703da9d94e1f69c70d1c9abc353e9664b40670bb4976c06964bb2606deee52f5dfcc619f336ceb8cf8
2 parents 1b04b55 + 5654efb commit 0df7a6c

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

test/functional/rpc_bind.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def setup_network(self):
2020
self.add_nodes(self.num_nodes, None)
2121

2222
def add_options(self, parser):
23-
parser.add_option("--ipv4", action='store_true', dest="run_ipv4", help="Run ipv4 tests only", default=False)
24-
parser.add_option("--ipv6", action='store_true', dest="run_ipv6", help="Run ipv6 tests only", default=False)
25-
parser.add_option("--nonloopback", action='store_true', dest="run_nonloopback", help="Run non-loopback tests only", default=False)
23+
parser.add_argument("--ipv4", action='store_true', dest="run_ipv4", help="Run ipv4 tests only", default=False)
24+
parser.add_argument("--ipv6", action='store_true', dest="run_ipv6", help="Run ipv6 tests only", default=False)
25+
parser.add_argument("--nonloopback", action='store_true', dest="run_nonloopback", help="Run non-loopback tests only", default=False)
2626

2727
def run_bind_test(self, allow_ips, connect_to, addresses, expected):
2828
'''

test/functional/rpc_getblockstats.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class GetblockstatsTest(BitcoinTestFramework):
3535
]
3636

3737
def add_options(self, parser):
38-
parser.add_option('--gen-test-data', dest='gen_test_data',
39-
default=False, action='store_true',
40-
help='Generate test data')
41-
parser.add_option('--test-data', dest='test_data',
42-
default='data/rpc_getblockstats.json',
43-
action='store', metavar='FILE',
44-
help='Test data file')
38+
parser.add_argument('--gen-test-data', dest='gen_test_data',
39+
default=False, action='store_true',
40+
help='Generate test data')
41+
parser.add_argument('--test-data', dest='test_data',
42+
default='data/rpc_getblockstats.json',
43+
action='store', metavar='FILE',
44+
help='Test data file')
4545

4646
def set_test_params(self):
4747
self.num_nodes = 2

test/functional/test_framework/test_framework.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import configparser
88
from enum import Enum
99
import logging
10-
import optparse
10+
import argparse
1111
import os
1212
import pdb
1313
import shutil
@@ -96,31 +96,31 @@ def __init__(self):
9696
def main(self):
9797
"""Main function. This should not be overridden by the subclass test scripts."""
9898

99-
parser = optparse.OptionParser(usage="%prog [options]")
100-
parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
101-
help="Leave bitcoinds and test.* datadir on exit or error")
102-
parser.add_option("--noshutdown", dest="noshutdown", default=False, action="store_true",
103-
help="Don't stop bitcoinds after the test execution")
104-
parser.add_option("--cachedir", dest="cachedir", default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../cache"),
105-
help="Directory for caching pregenerated datadirs (default: %default)")
106-
parser.add_option("--tmpdir", dest="tmpdir", help="Root directory for datadirs")
107-
parser.add_option("-l", "--loglevel", dest="loglevel", default="INFO",
108-
help="log events at this level and higher to the console. Can be set to DEBUG, INFO, WARNING, ERROR or CRITICAL. Passing --loglevel DEBUG will output all logs to console. Note that logs at all levels are always written to the test_framework.log file in the temporary test directory.")
109-
parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true",
110-
help="Print out all RPC calls as they are made")
111-
parser.add_option("--portseed", dest="port_seed", default=os.getpid(), type='int',
112-
help="The seed to use for assigning port numbers (default: current process id)")
113-
parser.add_option("--coveragedir", dest="coveragedir",
114-
help="Write tested RPC commands into this directory")
115-
parser.add_option("--configfile", dest="configfile",
116-
default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../config.ini"),
117-
help="Location of the test framework config file (default: %default)")
118-
parser.add_option("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true",
119-
help="Attach a python debugger if test fails")
120-
parser.add_option("--usecli", dest="usecli", default=False, action="store_true",
121-
help="use bitcoin-cli instead of RPC for all commands")
99+
parser = argparse.ArgumentParser(usage="%(prog)s [options]")
100+
parser.add_argument("--nocleanup", dest="nocleanup", default=False, action="store_true",
101+
help="Leave bitcoinds and test.* datadir on exit or error")
102+
parser.add_argument("--noshutdown", dest="noshutdown", default=False, action="store_true",
103+
help="Don't stop bitcoinds after the test execution")
104+
parser.add_argument("--cachedir", dest="cachedir", default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../cache"),
105+
help="Directory for caching pregenerated datadirs (default: %(default)s)")
106+
parser.add_argument("--tmpdir", dest="tmpdir", help="Root directory for datadirs")
107+
parser.add_argument("-l", "--loglevel", dest="loglevel", default="INFO",
108+
help="log events at this level and higher to the console. Can be set to DEBUG, INFO, WARNING, ERROR or CRITICAL. Passing --loglevel DEBUG will output all logs to console. Note that logs at all levels are always written to the test_framework.log file in the temporary test directory.")
109+
parser.add_argument("--tracerpc", dest="trace_rpc", default=False, action="store_true",
110+
help="Print out all RPC calls as they are made")
111+
parser.add_argument("--portseed", dest="port_seed", default=os.getpid(), type=int,
112+
help="The seed to use for assigning port numbers (default: current process id)")
113+
parser.add_argument("--coveragedir", dest="coveragedir",
114+
help="Write tested RPC commands into this directory")
115+
parser.add_argument("--configfile", dest="configfile",
116+
default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../config.ini"),
117+
help="Location of the test framework config file (default: %(default)s)")
118+
parser.add_argument("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true",
119+
help="Attach a python debugger if test fails")
120+
parser.add_argument("--usecli", dest="usecli", default=False, action="store_true",
121+
help="use bitcoin-cli instead of RPC for all commands")
122122
self.add_options(parser)
123-
(self.options, self.args) = parser.parse_args()
123+
self.options = parser.parse_args()
124124

125125
PortSeed.n = self.options.port_seed
126126

test/functional/wallet_txn_clone.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def set_test_params(self):
1717
self.num_nodes = 4
1818

1919
def add_options(self, parser):
20-
parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true",
21-
help="Test double-spend of 1-confirmed transaction")
22-
parser.add_option("--segwit", dest="segwit", default=False, action="store_true",
23-
help="Test behaviour with SegWit txn (which should fail")
20+
parser.add_argument("--mineblock", dest="mine_block", default=False, action="store_true",
21+
help="Test double-spend of 1-confirmed transaction")
22+
parser.add_argument("--segwit", dest="segwit", default=False, action="store_true",
23+
help="Test behaviour with SegWit txn (which should fail")
2424

2525
def setup_network(self):
2626
# Start with split network:

test/functional/wallet_txn_doublespend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def set_test_params(self):
1919
self.num_nodes = 4
2020

2121
def add_options(self, parser):
22-
parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true",
23-
help="Test double-spend of 1-confirmed transaction")
22+
parser.add_argument("--mineblock", dest="mine_block", default=False, action="store_true",
23+
help="Test double-spend of 1-confirmed transaction")
2424

2525
def setup_network(self):
2626
# Start with split network:

0 commit comments

Comments
 (0)