Skip to content

Commit

Permalink
Add tests for local checkout of cable
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaasgoyal committed Mar 4, 2024
1 parent 6731ec0 commit 9e86846
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
2 changes: 1 addition & 1 deletion benchcab/data/config-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ realisations:
type: "dict"
excludes: ["git", "svn"]
schema:
local_path:
path:
type: "string"
required: true
name:
Expand Down
17 changes: 16 additions & 1 deletion benchcab/data/test/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

set -ex

CABLE_REPO="[email protected]:CABLE-LSM/CABLE.git"
CABLE_DIR=/scratch/$PROJECT/$USER/benchcab/CABLE

TEST_DIR=/scratch/$PROJECT/$USER/benchcab/integration
EXAMPLE_REPO="[email protected]: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
Expand All @@ -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,
Expand Down
56 changes: 37 additions & 19 deletions benchcab/utils/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (

Check warning on line 65 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L63-L65

Added lines #L63 - L65 were not covered by tests
realisation_path / self.name
if realisation_path.is_dir()
else realisation_path
)
self.logger = get_logger()

Check warning on line 70 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L70

Added line #L70 was not covered by tests

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(

Check warning on line 75 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L74-L75

Added lines #L74 - L75 were not covered by tests
f"Created symlink from to {self.realisation_path} named {self.name}"
)

def get_revision(self) -> str:
"""Return the latest revision of the source code.
Expand All @@ -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}"

Check warning on line 88 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L88

Added line #L88 was not covered by tests

def get_branch_name(self) -> str:
"""Return the branch name of the source code.
Expand All @@ -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()

Check warning on line 99 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L99

Added line #L99 was not covered by tests


class GitRepo(Repo):
Expand All @@ -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.
Expand All @@ -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`.
Expand All @@ -127,7 +137,9 @@ def __init__(
"""
self.url = url
self.branch = branch
self.path = path / branch if path.is_dir() else path
self.path = (

Check warning on line 140 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L140

Added line #L140 was not covered by tests
realisation_path / branch if realisation_path.is_dir() else realisation_path
)
self.commit = commit
self.logger = get_logger()

Expand Down Expand Up @@ -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.
Expand All @@ -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 / <branch_name>` where `<branch_name>` is the
Expand All @@ -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 = (

Check warning on line 226 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L226

Added line #L226 was not covered by tests
realisation_path / Path(branch_path).name
if realisation_path.is_dir()
else realisation_path
)
self.logger = get_logger()

def checkout(self):
Expand Down Expand Up @@ -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"])

Check warning on line 299 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L299

Added line #L299 was not covered by tests
if "svn" in spec:
return SVNRepo(svn_root=internal.CABLE_SVN_ROOT, path=path, **spec["svn"])
return SVNRepo(

Check warning on line 301 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L301

Added line #L301 was not covered by tests
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"])

Check warning on line 305 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L304-L305

Added lines #L304 - L305 were not covered by tests
raise RepoSpecError
21 changes: 15 additions & 6 deletions tests/test_workdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,35 @@ 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"]
)
def pbs_job_file(self, request) -> Path:
return Path(request.param)

def test_clean_realisation_files(self, src_path, revision_log_file):
"""Success case: directory tree does not exist after clean."""
def test_clean_realisation_files(
self, src_path: Path, tmp_path: Path, revision_log_file: Path
):
"""Success case: Realisation files created by benchcab are removed after clean."""
src_path.mkdir()
cable_symlink = src_path / "main"
# tmp_path contains the path being symlinked
local_cable_src_path = tmp_path / "CABLE"
local_cable_src_path.mkdir()
cable_symlink.symlink_to(local_cable_src_path)
revision_log_file.touch()
clean_realisation_files()

assert local_cable_src_path.exists()
assert not src_path.exists()
assert not revision_log_file.exists()

def test_clean_submission_files(self, runs_path, pbs_job_file):
"""Success case: log files in project root directory do not exist after clean."""
"""Success case: Submission files created by benchcab are removed after clean."""
runs_path.mkdir()
pbs_job_file.touch()
clean_submission_files()
Expand Down

0 comments on commit 9e86846

Please sign in to comment.