From e9110fa8955baff6780360725e4f42ad61539374 Mon Sep 17 00:00:00 2001 From: Sean Bryan Date: Fri, 17 Nov 2023 12:13:47 +1100 Subject: [PATCH] Add getter method for built executable This change removes any hard coded paths to the built executable that are outside the `CableRepository` class and replaces these with a method that returns the path to the executable. This is done to prepare for the changes in #183 which requires paths to vary accross different `CableRepository` objects. Fixes #199 --- benchcab/fluxsite.py | 8 +------- benchcab/model.py | 10 ++++++++++ tests/test_model.py | 11 +++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/benchcab/fluxsite.py b/benchcab/fluxsite.py index c499bed7..c6ffa1d7 100644 --- a/benchcab/fluxsite.py +++ b/benchcab/fluxsite.py @@ -264,13 +264,7 @@ def fetch_files(self, verbose=False): self.root_dir / internal.NAMELIST_DIR, task_dir, dirs_exist_ok=True ) - exe_src = ( - self.root_dir - / internal.SRC_DIR - / self.repo.name - / "offline" - / internal.CABLE_EXE - ) + exe_src = self.repo.get_exe_path() exe_dest = task_dir / internal.CABLE_EXE if verbose: diff --git a/benchcab/model.py b/benchcab/model.py index ee393c21..dd7f2f76 100644 --- a/benchcab/model.py +++ b/benchcab/model.py @@ -76,6 +76,16 @@ def svn_info_show_item(self, item: str) -> str: ) return proc.stdout.strip() + def get_exe_path(self) -> Path: + """Return the path to the built executable.""" + return ( + self.root_dir + / internal.SRC_DIR + / self.name + / "offline" + / internal.CABLE_EXE + ) + def custom_build(self, modules: list[str], verbose=False): """Build CABLE using a custom build script.""" build_script_path = ( diff --git a/tests/test_model.py b/tests/test_model.py index eb945deb..7e21aa5e 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -46,6 +46,17 @@ def test_undefined_repo_id(self, repo): _ = repo.repo_id +class TestGetExePath: + """Tests for `CableRepository.get_exe_path()`.""" + + def test_serial_exe_path(self, repo, mock_cwd): + """Success case: get path to serial executable.""" + assert ( + repo.get_exe_path() + == mock_cwd / internal.SRC_DIR / repo.name / "offline" / internal.CABLE_EXE + ) + + class TestCheckout: """Tests for `Model.checkout()`."""