From 4218b8708c4c5f7f37078647470b3d209f00615b Mon Sep 17 00:00:00 2001 From: Abhaas Goyal Date: Mon, 4 Mar 2024 12:07:45 +1100 Subject: [PATCH] Add integration test for local checkout of CABLE --- benchcab/data/config-schema.yml | 2 +- benchcab/data/test/integration.sh | 17 +++++++++- benchcab/utils/repo.py | 56 ++++++++++++++++++++----------- tests/test_workdir.py | 6 ++-- 4 files changed, 57 insertions(+), 24 deletions(-) diff --git a/benchcab/data/config-schema.yml b/benchcab/data/config-schema.yml index df9fc9d0..5546306c 100644 --- a/benchcab/data/config-schema.yml +++ b/benchcab/data/config-schema.yml @@ -48,7 +48,7 @@ realisations: type: "dict" excludes: ["git", "svn"] schema: - local_path: + path: type: "string" required: true name: diff --git a/benchcab/data/test/integration.sh b/benchcab/data/test/integration.sh index e672c887..200ff8cf 100644 --- a/benchcab/data/test/integration.sh +++ b/benchcab/data/test/integration.sh @@ -2,13 +2,24 @@ set -ex +CABLE_REPO="git@github.com:CABLE-LSM/CABLE.git" +CABLE_DIR=/scratch/$PROJECT/$USER/benchcab/CABLE + TEST_DIR=/scratch/$PROJECT/$USER/benchcab/integration EXAMPLE_REPO="git@github.com:CABLE-LSM/bench_example.git" -# Remove the test work space, then recreate +# Remove CABLE and test work space, then recreate +rm -rf $CABLE_DIR +mkdir -p $CABLE_DIR + rm -rf $TEST_DIR mkdir -p $TEST_DIR +# Clone local checkout for CABLE +git clone $CABLE_REPO $CABLE_DIR +cd $CABLE_DIR +git reset --hard 67a52dc5721f0da78ee7d61798c0e8a804dcaaeb + # Clone the example repo git clone $EXAMPLE_REPO $TEST_DIR cd $TEST_DIR @@ -18,9 +29,13 @@ cat > config.yaml << EOL project: $PROJECT realisations: + - repo: + local: + path: $CABLE_DIR - repo: git: branch: main + commit: 67a52dc5721f0da78ee7d61798c0e8a804dcaaeb modules: [ intel-compiler/2021.1.1, diff --git a/benchcab/utils/repo.py b/benchcab/utils/repo.py index dfa3da9c..0dd807f1 100644 --- a/benchcab/utils/repo.py +++ b/benchcab/utils/repo.py @@ -49,26 +49,32 @@ def get_branch_name(self) -> str: class LocalRepo(Repo): """Concrete implementation of the `Repo` class using local path backend.""" - def __init__(self, local_path: str, path: str) -> None: + def __init__(self, path: str, realisation_path: str) -> None: """_summary_. Parameters ---------- - local_path : str + realisation_path : str Path for local checkout of CABLE path : str - Directory where CABLE is symlinked + Directory where CABLE is symlinked from """ - self.name = Path(local_path).name - self.local_path = local_path - self.path = path / self.name if path.is_dir() else path + self.name = Path(path).name + self.local_path = path + self.realisation_path = ( + realisation_path / self.name + if realisation_path.is_dir() + else realisation_path + ) self.logger = get_logger() def checkout(self): """Checkout the source code.""" - self.path.symlink_to(self.local_path) - self.logger.info(f"Created symlink from to {self.path} named {self.name}") + self.realisation_path.symlink_to(self.local_path) + self.logger.info( + f"Created symlink from to {self.realisation_path} named {self.name}" + ) def get_revision(self) -> str: """Return the latest revision of the source code. @@ -79,7 +85,7 @@ def get_revision(self) -> str: Human readable string describing the latest revision. """ - return f"Using local CABLE branch: {self.name}" + return f"Local CABLE build: {self.name}" def get_branch_name(self) -> str: """Return the branch name of the source code. @@ -90,7 +96,7 @@ def get_branch_name(self) -> str: Branch name of the source code. """ - return Path(self.path).absolute() + return Path(self.realisation_path).absolute().as_posix() class GitRepo(Repo): @@ -106,7 +112,11 @@ class GitRepo(Repo): subprocess_handler = SubprocessWrapper() def __init__( - self, url: str, branch: str, path: Path, commit: Optional[str] = None + self, + url: str, + branch: str, + realisation_path: Path, + commit: Optional[str] = None, ) -> None: """Return a `GitRepo` instance. @@ -116,7 +126,7 @@ def __init__( URL pointing to the GitHub repository. branch: str Name of a branch on the GitHub repository. - path: Path + realisation_path: Path Path to a directory in which the repository is cloned into. If `path` points to an existing directory, the repository will be cloned into `path / branch`. @@ -127,7 +137,9 @@ def __init__( """ self.url = url self.branch = branch - self.path = path / branch if path.is_dir() else path + self.path = ( + realisation_path / branch if realisation_path.is_dir() else realisation_path + ) self.commit = commit self.logger = get_logger() @@ -187,7 +199,7 @@ def __init__( self, svn_root: str, branch_path: str, - path: Path, + realisation_path: Path, revision: Optional[int] = None, ) -> None: """Return an `SVNRepo` instance. @@ -198,7 +210,7 @@ def __init__( URL pointing to the root of the SVN repository. branch_path: str Path to a branch relative to `svn_root`. - path: Path + realisation_path: Path Path to a directory in which the branch is checked out into. If `path` points to an existing directory, the repository will be cloned into `path / ` where `` is the @@ -211,7 +223,11 @@ def __init__( self.svn_root = svn_root self.branch_path = branch_path self.revision = revision - self.path = path / Path(branch_path).name if path.is_dir() else path + self.path = ( + realisation_path / Path(branch_path).name + if realisation_path.is_dir() + else realisation_path + ) self.logger = get_logger() def checkout(self): @@ -280,9 +296,11 @@ def create_repo(spec: dict, path: Path) -> Repo: if "git" in spec: if "url" not in spec["git"]: spec["git"]["url"] = internal.CABLE_GIT_URL - return GitRepo(path=path, **spec["git"]) + return GitRepo(realisation_path=path, **spec["git"]) if "svn" in spec: - return SVNRepo(svn_root=internal.CABLE_SVN_ROOT, path=path, **spec["svn"]) + return SVNRepo( + svn_root=internal.CABLE_SVN_ROOT, realisation_path=path, **spec["svn"] + ) if "local" in spec: - return LocalRepo(path=path, **spec["local"]) + return LocalRepo(realisation_path=path, **spec["local"]) raise RepoSpecError diff --git a/tests/test_workdir.py b/tests/test_workdir.py index 62b05a24..a25c8518 100644 --- a/tests/test_workdir.py +++ b/tests/test_workdir.py @@ -75,9 +75,9 @@ def src_path(self) -> Path: def runs_path(self) -> Path: return Path("runs") - @pytest.fixture() - def revision_log_file(self) -> Path: - return Path("rev_number-200.log") + @pytest.fixture(params=["rev_number-0.log", "rev_number-200.log"]) + def revision_log_file(self, request) -> Path: + return Path(request.param) @pytest.fixture( params=["benchmark_cable_qsub.sh.o21871", "benchmark_cable_qsub.sh"]