Skip to content

Commit

Permalink
test: use pytest temporary directories in autotests
Browse files Browse the repository at this point in the history
* switch to awvwgk/setup-fortran in CI
* set CXX and SETVARS_COMPLETED manually until setup-fortran patched
* add pytest-dependency to test dependency group in pyproject.toml
* add dependency marker to autotest/pytest.ini to avoid warnings
  • Loading branch information
wpbonelli committed Jul 28, 2023
1 parent 8f804f9 commit 57063ea
Show file tree
Hide file tree
Showing 22 changed files with 806 additions and 1,467 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
schedule:
- cron: '0 7 * * *' # run at 7 AM UTC every day
push:
branches: [ master ]
branches:
- master
pull_request:
branches:
- master
Expand All @@ -25,8 +26,18 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Intel OneAPI Compilers
uses: modflowpy/install-intelfortran-action@v1
- name: Setup Intel Fortran Classic
uses: awvwgk/setup-fortran@main
with:
compiler: intel-classic
version: 2021.7.0

- name: Set SETVARS_COMPLETED (temporary)
run: echo "SETVARS_COMPLETED=1" >> $GITHUB_ENV

- name: Set CXX (temporary)
if: runner.os == 'Windows'
run: echo "CXX=icl" >> $GITHUB_ENV

- name: Setup Graphviz
if: runner.os == 'Linux'
Expand Down Expand Up @@ -63,7 +74,7 @@ jobs:
working-directory: ./autotest
shell: cmd
run: |
pytest -v -m="base" --durations=0 --cov=pymake --cov-report=xml
pytest -v -m="base" --durations=0 --cov=pymake --cov-report=xml --basetemp=pytest_temp
- name: Print coverage report before upload
working-directory: ./autotest
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/pymake-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
schedule:
- cron: '0 7 * * *' # run at 7 AM UTC every day
push:
branches: [ master ]
branches:
- master
pull_request:
branches:
- master
Expand Down Expand Up @@ -39,8 +40,11 @@ jobs:
python -m pip install --upgrade pip
pip install ".[test]"
- name: Install GNU Fortran
uses: modflowpy/install-gfortran-action@v1
- name: Setup GNU Fortran
uses: awvwgk/setup-fortran@main
with:
compiler: gcc
version: 11

- name: Download examples for pytest runs
run: |
Expand All @@ -49,7 +53,7 @@ jobs:
- name: Run pytest
working-directory: ./autotest
run: |
pytest -v --dist=loadfile -n=auto -m="base or regression" --durations=0 --cov=pymake --cov-report=xml
pytest -v --dist=loadfile -n=auto -m="base or regression" --durations=0 --cov=pymake --cov-report=xml --basetemp=pytest_temp
- name: Print coverage report before upload
working-directory: ./autotest
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pymake-linting-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
schedule:
- cron: '0 3 * * 3' # run at 3 AM UTC every Wednesday
push:
branches: [ master ]
branches:
- master
pull_request:
branches:
- master
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pymake-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
schedule:
- cron: '0 7 * * *' # run at 7 AM UTC every day
push:
branches: [ master ]
branches:
- master
pull_request:
branches:
- master
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pymake-rtd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
schedule:
- cron: '0 3 * * 3' # run at 3 AM UTC every Wednesday
push:
branches: [ master ]
branches:
- master
pull_request:
branches:
- master
Expand Down
1 change: 1 addition & 0 deletions pytest.ini → autotest/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[pytest]
markers =
base: base tests
dependency: tests that depend on other tests (via pytest-dependency)
regression: regression tests
requests: usgsprograms requests tests
schedule: tests to run if a scheduled job
48 changes: 9 additions & 39 deletions autotest/test_cli_cmds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import pathlib as pl
import shutil
import subprocess

import pytest
Expand All @@ -13,12 +11,6 @@
"crt",
)

# set up paths
dstpth = pl.Path(
f"temp_{os.path.basename(__file__).replace('.py', '')}"
).resolve()
dstpth.mkdir(parents=True, exist_ok=True)


def run_cli_cmd(cmd: list) -> None:
process = subprocess.Popen(
Expand All @@ -39,38 +31,29 @@ def run_cli_cmd(cmd: list) -> None:
return


def clean_up() -> None:
print("Removing temporary build directories")
dirs_temp = [dstpth]
for d in dirs_temp:
if os.path.isdir(d):
shutil.rmtree(d)
return


@flaky(max_runs=RERUNS)
@pytest.mark.dependency(name="make_program")
@pytest.mark.base
@flaky(max_runs=RERUNS)
@pytest.mark.parametrize("target", targets)
def test_make_program(target: str) -> None:
def test_make_program(module_tmpdir, target: str) -> None:
cmd = [
"make-program",
target,
"--appdir",
str(dstpth),
str(module_tmpdir),
"--verbose",
]
run_cli_cmd(cmd)


@pytest.mark.dependency(name="make_program_all")
@pytest.mark.schedule
def test_make_program_all() -> None:
def test_make_program_all(module_tmpdir) -> None:
cmd = [
"make-program",
":",
"--appdir",
str(dstpth / "all"),
str(module_tmpdir / "all"),
"--verbose",
"--dryrun",
]
Expand All @@ -79,14 +62,14 @@ def test_make_program_all() -> None:

@pytest.mark.dependency(name="mfpymake")
@pytest.mark.base
def test_mfpymake() -> None:
def test_mfpymake(module_tmpdir) -> None:
src = (
"program hello\n"
+ " ! This is a comment line; it is ignored by the compiler\n"
+ " print *, 'Hello, World!'\n"
+ "end program hello\n"
)
src_file = dstpth / "mfpymake_src/hello.f90"
src_file = module_tmpdir / "mfpymake_src" / "hello.f90"
src_file.parent.mkdir(parents=True, exist_ok=True)
with open(src_file, "w") as f:
f.write(src)
Expand All @@ -97,26 +80,13 @@ def test_mfpymake() -> None:
"-mc",
"--verbose",
"--appdir",
str(dstpth),
str(module_tmpdir),
"-fc",
]
if os.environ.get("FC") is None:
cmd.append("gfortran")
else:
cmd.append(os.environ.get("FC"))
run_cli_cmd(cmd)
cmd = [dstpth / "hello"]
cmd = [module_tmpdir / "hello"]
run_cli_cmd(cmd)


@pytest.mark.dependency(name="clean", depends=["make_program"])
@pytest.mark.base
def test_clean_up() -> None:
clean_up()
return


if __name__ == "__main__":
for target in targets:
test_make_program(target)
test_clean_up()
Loading

0 comments on commit 57063ea

Please sign in to comment.