Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
class SkipTest(Exception): | class SkipTest(Exception): | ||||
"""This exception is raised to skip a test""" | """This exception is raised to skip a test""" | ||||
def __init__(self, message): | def __init__(self, message): | ||||
self.message = message | self.message = message | ||||
class BitcoinTestFramework(): | class BitcoinTestMetaClass(type): | ||||
"""Metaclass for BitcoinTestFramework. | |||||
Ensures that any attempt to register a subclass of `BitcoinTestFramework` | |||||
adheres to a standard whereby the subclass overrides `set_test_params` and | |||||
`run_test` but DOES NOT override either `__init__` or `main`. If any of | |||||
those standards are violated, a ``TypeError`` is raised.""" | |||||
def __new__(cls, clsname, bases, dct): | |||||
if not clsname == 'BitcoinTestFramework': | |||||
if not ('run_test' in dct and 'set_test_params' in dct): | |||||
raise TypeError("BitcoinTestFramework subclasses must override " | |||||
"'run_test' and 'set_test_params'") | |||||
if '__init__' in dct or 'main' in dct: | |||||
raise TypeError("BitcoinTestFramework subclasses may not override " | |||||
"'__init__' or 'main'") | |||||
return super().__new__(cls, clsname, bases, dct) | |||||
class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): | |||||
"""Base class for a bitcoin test script. | """Base class for a bitcoin test script. | ||||
Individual bitcoin test scripts should subclass this class and override the set_test_params() and run_test() methods. | Individual bitcoin test scripts should subclass this class and override the set_test_params() and run_test() methods. | ||||
Individual tests can also override the following methods to customize the test setup: | Individual tests can also override the following methods to customize the test setup: | ||||
- add_options() | - add_options() | ||||
- setup_chain() | - setup_chain() | ||||
▲ Show 20 Lines • Show All 528 Lines • Show Last 20 Lines |