test: refactor: introduce replace_in_config helper

This commit is contained in:
Sebastian Falbesoner
2023-01-23 17:35:04 +01:00
parent 5271c77f83
commit b530d9605d
4 changed files with 19 additions and 18 deletions

View File

@@ -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