aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2017-06-09 18:21:21 -0400
committerMarcoFalke <falke.marco@gmail.com>2017-10-03 18:43:43 +0200
commit801d2ae9247be5870344c8b4ed5c372ab8930408 (patch)
tree2326b26745fcdb556b9a937b5e8fe116fd21a9ae /test/functional/test_framework
parentbb5e7cb308b58a1c16db1275dfca1a31e2bba71f (diff)
downloadbitcoin-801d2ae9247be5870344c8b4ed5c372ab8930408.tar.xz
[tests] don't override __init__() in individual tests
Almost all test scripts currently need to override the __init__() method. When they do that they need to call into super().__init__() as the base class does some generic initialization. This commit makes the base class __init__() call into set_test_params() method. Individual test cases can override set_test_params() to setup their test parameters. Github-Pull: #11121 Rebased-From: 5448a1471d6fc638a2220ea5a2f3782172efe14c
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-xtest/functional/test_framework/test_framework.py89
1 files changed, 50 insertions, 39 deletions
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 5e3644a914..d860bc5594 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -48,58 +48,30 @@ BITCOIND_PROC_WAIT_TIMEOUT = 60
class BitcoinTestFramework(object):
"""Base class for a bitcoin test script.
- Individual bitcoin test scripts should subclass this class and override the following methods:
+ Individual bitcoin test scripts should subclass this class and override the run_test() method.
- - __init__()
+ Individual tests can also override the following methods to customize the test setup:
+
+ - set_test_params()
- add_options()
- setup_chain()
- setup_network()
- - run_test()
+ - setup_nodes()
- The main() method should not be overridden.
+ The __init__() and main() methods should not be overridden.
This class also contains various public and private helper methods."""
- # Methods to override in subclass test scripts.
def __init__(self):
+ """Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method"""
self.num_nodes = 4
self.setup_clean_chain = False
self.nodes = []
self.mocktime = 0
-
- def add_options(self, parser):
- pass
-
- def setup_chain(self):
- self.log.info("Initializing test directory " + self.options.tmpdir)
- if self.setup_clean_chain:
- self._initialize_chain_clean()
- else:
- self._initialize_chain()
-
- def setup_network(self):
- self.setup_nodes()
-
- # Connect the nodes as a "chain". This allows us
- # to split the network between nodes 1 and 2 to get
- # two halves that can work on competing chains.
- for i in range(self.num_nodes - 1):
- connect_nodes_bi(self.nodes, i, i + 1)
- self.sync_all()
-
- def setup_nodes(self):
- extra_args = None
- if hasattr(self, "extra_args"):
- extra_args = self.extra_args
- self.add_nodes(self.num_nodes, extra_args)
- self.start_nodes()
-
- def run_test(self):
- raise NotImplementedError
-
- # Main function. This should not be overridden by the subclass test scripts.
+ self.set_test_params()
def main(self):
+ """Main function. This should not be overridden by the subclass test scripts."""
parser = optparse.OptionParser(usage="%prog [options]")
parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
@@ -203,6 +175,46 @@ class BitcoinTestFramework(object):
logging.shutdown()
sys.exit(TEST_EXIT_FAILED)
+ # Methods to override in subclass test scripts.
+ def set_test_params(self):
+ """Override this method to change default values for number of nodes, topology, etc"""
+ pass
+
+ def add_options(self, parser):
+ """Override this method to add command-line options to the test"""
+ pass
+
+ def setup_chain(self):
+ """Override this method to customize blockchain setup"""
+ self.log.info("Initializing test directory " + self.options.tmpdir)
+ if self.setup_clean_chain:
+ self._initialize_chain_clean()
+ else:
+ self._initialize_chain()
+
+ def setup_network(self):
+ """Override this method to customize test network topology"""
+ self.setup_nodes()
+
+ # Connect the nodes as a "chain". This allows us
+ # to split the network between nodes 1 and 2 to get
+ # two halves that can work on competing chains.
+ for i in range(self.num_nodes - 1):
+ connect_nodes_bi(self.nodes, i, i + 1)
+ self.sync_all()
+
+ def setup_nodes(self):
+ """Override this method to customize test node setup"""
+ extra_args = None
+ if hasattr(self, "extra_args"):
+ extra_args = self.extra_args
+ self.add_nodes(self.num_nodes, extra_args)
+ self.start_nodes()
+
+ def run_test(self):
+ """Override this method to define test logic"""
+ raise NotImplementedError
+
# Public helper methods. These can be accessed by the subclass test scripts.
def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, binary=None):
@@ -442,8 +454,7 @@ class ComparisonTestFramework(BitcoinTestFramework):
- 2 binaries: 1 test binary, 1 ref binary
- n>2 binaries: 1 test binary, n-1 ref binaries"""
- def __init__(self):
- super().__init__()
+ def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True