Skip to content

Commit

Permalink
refactor: use awvwgk/setup-fortran, use pytest tempdirs
Browse files Browse the repository at this point in the history
* switch from install-[g/intel]fortran-action to awvwgk/setup-fortran
* temporarily set SETVARS_COMPLETED until setup-fortran is updated
  • Loading branch information
wpbonelli committed Jul 27, 2023
1 parent 8f804f9 commit 2b43529
Show file tree
Hide file tree
Showing 22 changed files with 787 additions and 1,469 deletions.
15 changes: 11 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,14 @@ 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
run: echo "SETVARS_COMPLETED=1" >> $GITHUB_ENV

- name: Setup Graphviz
if: runner.os == 'Linux'
Expand Down Expand Up @@ -63,7 +70,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=${{ runner.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=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 2b43529

Please sign in to comment.