mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-26 15:36:19 +01:00
test: refactor: introduce replace_in_config helper
This commit is contained in:
@@ -387,6 +387,21 @@ class TestNode():
|
||||
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
|
||||
wait_until_helper(self.is_node_stopped, timeout=timeout, timeout_factor=self.timeout_factor)
|
||||
|
||||
def replace_in_config(self, replacements):
|
||||
"""
|
||||
Perform replacements in the configuration file.
|
||||
The substitutions are passed as a list of search-replace-tuples, e.g.
|
||||
[("old", "new"), ("foo", "bar"), ...]
|
||||
"""
|
||||
with open(self.bitcoinconf, 'r', encoding='utf8') as conf:
|
||||
conf_data = conf.read()
|
||||
for replacement in replacements:
|
||||
assert_equal(len(replacement), 2)
|
||||
old, new = replacement[0], replacement[1]
|
||||
conf_data = conf_data.replace(old, new)
|
||||
with open(self.bitcoinconf, 'w', encoding='utf8') as conf:
|
||||
conf.write(conf_data)
|
||||
|
||||
@property
|
||||
def chain_path(self) -> Path:
|
||||
return Path(self.datadir) / self.chain
|
||||
|
||||
Reference in New Issue
Block a user