forked from ESCOMP/CTSM
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ESCOMP#15 from jedwards4b/add_tests
Add tests
- Loading branch information
Showing
8 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Run this job on pushes to `main`, and for pull requests. If you don't specify | ||
# `branches: [main], then this actions runs _twice_ on pull requests, which is | ||
# annoying. | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
# If you wanted to use multiple Python versions, you'd have specify a matrix in the job and | ||
# reference the matrixe python version here. | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.9' | ||
|
||
# Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow | ||
# from installing Poetry every time, which can be slow. Note the use of the Poetry version | ||
# number in the cache key, and the "-0" suffix: this allows you to invalidate the cache | ||
# manually if/when you want to upgrade Poetry, or if something goes wrong. This could be | ||
# mildly cleaner by using an environment variable, but I don't really care. | ||
- name: cache poetry install | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.local | ||
key: poetry-1.7.1 | ||
|
||
# Install Poetry. You could do this manually, or there are several actions that do this. | ||
# `snok/install-poetry` seems to be minimal yet complete, and really just calls out to | ||
# Poetry's default install script, which feels correct. I pin the Poetry version here | ||
# because Poetry does occasionally change APIs between versions and I don't want my | ||
# actions to break if it does. | ||
# | ||
# The key configuration value here is `virtualenvs-in-project: true`: this creates the | ||
# venv as a `.venv` in your testing directory, which allows the next step to easily | ||
# cache it. | ||
- uses: snok/install-poetry@v1 | ||
with: | ||
version: 1.7.1 | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
|
||
# Cache your dependencies (i.e. all the stuff in your `pyproject.toml`). Note the cache | ||
# key: if you're using multiple Python versions, or multiple OSes, you'd need to include | ||
# them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock. | ||
- name: cache deps | ||
id: cache-deps | ||
uses: actions/cache@v4 | ||
with: | ||
path: .venv | ||
key: pydeps-${{ hashFiles('**/poetry.lock') }} | ||
|
||
# Install dependencies. `--no-root` means "install all dependencies but not the project | ||
# itself", which is what you want to avoid caching _your_ code. The `if` statement | ||
# ensures this only runs on a cache miss. | ||
- run: poetry install --no-interaction --no-root | ||
if: steps.cache-deps.outputs.cache-hit != 'true' | ||
|
||
# Now install _your_ project. This isn't necessary for many types of projects -- particularly | ||
# things like Django apps don't need this. But it's a good idea since it fully-exercises the | ||
# pyproject.toml and makes that if you add things like console-scripts at some point that | ||
# they'll be installed and working. | ||
- run: poetry install --no-interaction | ||
|
||
# And finally run tests. I'm using pytest and all my pytest config is in my `pyproject.toml` | ||
# so this line is super-simple. But it could be as complex as you need. | ||
- run: poetry run pytest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pytest | ||
from git_fleximod.gitinterface import GitInterface | ||
import os | ||
import subprocess | ||
import logging | ||
from pathlib import Path | ||
|
||
@pytest.fixture(scope='session') | ||
def logger(): | ||
logging.basicConfig( | ||
level=logging.INFO, format="%(name)s - %(levelname)s - %(message)s", handlers=[logging.StreamHandler()] | ||
) | ||
logger = logging.getLogger(__name__) | ||
return logger | ||
|
||
@pytest.fixture | ||
def test_repo_base(tmp_path, logger): | ||
test_dir = tmp_path / "test_repo" | ||
test_dir.mkdir() | ||
str_path = str(test_dir) | ||
gitp = GitInterface(str_path, logger) | ||
#subprocess.run(["git", "init"], cwd=test_dir) | ||
assert test_dir.joinpath(".git").is_dir() | ||
return test_dir | ||
|
||
@pytest.fixture(params=["modules/test"]) | ||
def test_repo(request, test_repo_base, logger): | ||
subrepo_path = request.param | ||
gitp = GitInterface(str(test_repo_base), logger) | ||
gitp.git_operation("submodule", "add", "--depth","1","--name","test_submodule", "https://github.com/ESMCI/mpi-serial.git", subrepo_path) | ||
# subprocess.run( | ||
assert test_repo_base.joinpath(".gitmodules").is_file() | ||
return test_repo_base | ||
|
||
@pytest.fixture | ||
def git_fleximod(test_repo): | ||
def _run_fleximod(args, input=None): | ||
cmd = ["git", "fleximod"] + args.split() | ||
result = subprocess.run(cmd, cwd=test_repo, input=input, | ||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, | ||
text=True) | ||
return result | ||
return _run_fleximod | ||
|
||
|
||
@pytest.fixture | ||
def deinit_submodule(test_repo, logger): | ||
def _deinit(submodule_path): | ||
gitp = GitInterface(str(test_repo), logger) | ||
gitp.git_operation( "submodule", "deinit", "-f", submodule_path) | ||
yield _deinit |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
from pathlib import Path | ||
|
||
def test_basic_checkout(git_fleximod, test_repo): | ||
# Prepare a simple .gitmodules | ||
|
||
gitmodules_content = """ | ||
[submodule "test_submodule"] | ||
path = modules/test | ||
url = https://github.com/ESMCI/mpi-serial.git | ||
fxtag = MPIserial_2.4.0 | ||
fxurl = https://github.com/ESMCI/mpi-serial.git | ||
fxrequired = T:T | ||
""" | ||
(test_repo / ".gitmodules").write_text(gitmodules_content) | ||
|
||
# Run the command | ||
result = git_fleximod("checkout") | ||
|
||
# Assertions | ||
assert result.returncode == 0 | ||
assert Path(test_repo / "modules/test").exists() # Did the submodule directory get created? | ||
|
||
status = git_fleximod("status") | ||
|
||
assert "test_submodule d82ce7c is out of sync with .gitmodules MPIserial_2.4.0" in status.stdout | ||
|
||
result = git_fleximod("update") | ||
assert result.returncode == 0 | ||
|
||
status = git_fleximod("status") | ||
assert "test_submodule at tag MPIserial_2.4.0" in status.stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
from shutil import rmtree | ||
from pathlib import Path | ||
from git_fleximod.gitinterface import GitInterface | ||
|
||
def test_sparse_checkout(git_fleximod, test_repo_base): | ||
# Prepare a simple .gitmodules | ||
gitmodules_content = (test_repo_base / ".gitmodules").read_text() + """ | ||
[submodule "test_sparse_submodule"] | ||
path = modules/sparse_test | ||
url = https://github.com/ESMCI/mpi-serial.git | ||
fxtag = MPIserial_2.5.0 | ||
fxurl = https://github.com/ESMCI/mpi-serial.git | ||
fxsparse = ../.sparse_file_list | ||
""" | ||
(test_repo_base / ".gitmodules").write_text(gitmodules_content) | ||
|
||
# Add the sparse checkout file | ||
sparse_content = """m4 | ||
""" | ||
(test_repo_base / "modules" / ".sparse_file_list").write_text(sparse_content) | ||
|
||
result = git_fleximod("checkout") | ||
|
||
# Assertions | ||
assert result.returncode == 0 | ||
assert Path(test_repo_base / "modules/sparse_test").exists() # Did the submodule directory get created? | ||
assert Path(test_repo_base / "modules/sparse_test/m4").exists() # Did the submodule sparse directory get created? | ||
assert not Path(test_repo_base / "modules/sparse_test/README").exists() # Did only the submodule sparse directory get created? | ||
status = git_fleximod("status test_sparse_submodule") | ||
|
||
assert "test_sparse_submodule at tag MPIserial_2.5.0" in status.stdout | ||
|
||
result = git_fleximod("update") | ||
assert result.returncode == 0 | ||
|
||
status = git_fleximod("status test_sparse_submodule") | ||
assert "test_sparse_submodule at tag MPIserial_2.5.0" in status.stdout |