Skip to content

Commit dda961c

Browse files
committed
test, refactor: Add set_binary_paths function
This change factors out the repeated code into a new `set_binary_paths` function.
1 parent da9f62f commit dda961c

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ def parse_args(self):
228228

229229
PortSeed.n = self.options.port_seed
230230

231+
def set_binary_paths(self):
232+
"""Update self.options with the paths of all binaries from environment variables or their default values"""
233+
234+
binaries = {
235+
"bitcoind": ("bitcoind", "BITCOIND"),
236+
"bitcoin-cli": ("bitcoincli", "BITCOINCLI"),
237+
"bitcoin-util": ("bitcoinutil", "BITCOINUTIL"),
238+
}
239+
for binary, [attribute_name, env_variable_name] in binaries.items():
240+
default_filename = os.path.join(
241+
self.config["environment"]["BUILDDIR"],
242+
"src",
243+
binary + self.config["environment"]["EXEEXT"],
244+
)
245+
setattr(self.options, attribute_name, os.getenv(env_variable_name, default=default_filename))
246+
231247
def setup(self):
232248
"""Call this method to start up the test framework object with options set."""
233249

@@ -237,24 +253,7 @@ def setup(self):
237253

238254
config = self.config
239255

240-
fname_bitcoind = os.path.join(
241-
config["environment"]["BUILDDIR"],
242-
"src",
243-
"bitcoind" + config["environment"]["EXEEXT"],
244-
)
245-
fname_bitcoincli = os.path.join(
246-
config["environment"]["BUILDDIR"],
247-
"src",
248-
"bitcoin-cli" + config["environment"]["EXEEXT"],
249-
)
250-
fname_bitcoinutil = os.path.join(
251-
config["environment"]["BUILDDIR"],
252-
"src",
253-
"bitcoin-util" + config["environment"]["EXEEXT"],
254-
)
255-
self.options.bitcoind = os.getenv("BITCOIND", default=fname_bitcoind)
256-
self.options.bitcoincli = os.getenv("BITCOINCLI", default=fname_bitcoincli)
257-
self.options.bitcoinutil = os.getenv("BITCOINUTIL", default=fname_bitcoinutil)
256+
self.set_binary_paths()
258257

259258
os.environ['PATH'] = os.pathsep.join([
260259
os.path.join(config['environment']['BUILDDIR'], 'src'),

0 commit comments

Comments
 (0)