Skip to content

Commit

Permalink
chore: format tests, colorize pytest CI output (#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli authored Sep 23, 2023
1 parent 1a862d3 commit b0a9481
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
working-directory: ./autotest
run: |
mkdir -p .benchmarks
pytest -v --durations=0 --benchmark-only --benchmark-json .benchmarks/${{ matrix.os }}_python${{ matrix.python-version }}.json --keep-failed=.failed
pytest -v --color=yes --durations=0 --benchmark-only --benchmark-json .benchmarks/${{ matrix.os }}_python${{ matrix.python-version }}.json --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -79,7 +79,7 @@ jobs:
working-directory: ./autotest
run: |
mkdir -p .benchmarks
pytest -v --durations=0 --benchmark-only --benchmark-json .benchmarks/${{ matrix.os }}_python${{ matrix.python-version }}.json --keep-failed=.failed
pytest -v --color=yes --durations=0 --benchmark-only --benchmark-json .benchmarks/${{ matrix.os }}_python${{ matrix.python-version }}.json --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:

- name: Smoke test
working-directory: autotest
run: pytest -v -n=auto --smoke --cov=flopy --cov-report=xml --durations=0 --keep-failed=.failed
run: pytest -v -n=auto --smoke --color=yes --cov=flopy --cov-report=xml --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -226,7 +226,7 @@ jobs:
if: runner.os != 'Windows'
working-directory: ./autotest
run: |
pytest -v -m="not example and not regression" -n=auto --cov=flopy --cov-append --cov-report=xml --durations=0 --keep-failed=.failed --dist loadfile
pytest -v -m="not example and not regression" -n=auto --color=yes --cov=flopy --cov-append --cov-report=xml --durations=0 --keep-failed=.failed --dist loadfile
coverage report
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -236,7 +236,7 @@ jobs:
shell: bash -l {0}
working-directory: ./autotest
run: |
pytest -v -m="not example and not regression" -n=auto --cov=flopy --cov-append --cov-report=xml --durations=0 --keep-failed=.failed --dist loadfile
pytest -v -m="not example and not regression" -n=auto --color=yes --cov=flopy --cov-append --cov-report=xml --durations=0 --keep-failed=.failed --dist loadfile
coverage report
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
if: runner.os != 'Windows'
working-directory: ./autotest
run: |
pytest -v -m="example" -n=auto -s --durations=0 --keep-failed=.failed
pytest -v -m="example" -n=auto -s --color=yes --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -106,7 +106,7 @@ jobs:
shell: bash -l {0}
working-directory: ./autotest
run: |
pytest -v -m="example" -n=auto -s --durations=0 --keep-failed=.failed
pytest -v -m="example" -n=auto -s --color=yes --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/mf6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
pytest -v --durations=0 get_exes.py
pytest -v --color=yes --durations=0 get_exes.py
- name: Run tests
working-directory: modflow6/autotest
run: |
pytest -v -n auto -k "test_gw" --durations=0 --cov=flopy --cov-report=xml
pytest -v --color=yes --cov=flopy --cov-report=xml --durations=0 -k "test_gw" -n auto
- name: Print coverage report before upload
working-directory: ./modflow6/autotest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/optional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:

- name: Smoke test (${{ matrix.optdeps }})
working-directory: autotest
run: pytest -v -n=auto --smoke --cov=flopy --cov-report=xml --durations=0 --keep-failed=.failed
run: pytest -v -n=auto --smoke --color=yes --cov=flopy --cov-report=xml --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ jobs:
- name: Run regression tests
if: runner.os != 'Windows'
working-directory: ./autotest
run: pytest -v -m="regression" -n=auto --durations=0 --keep-failed=.failed
run: pytest -v -m="regression" -n=auto --color=yes --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run regression tests
if: runner.os == 'Windows'
shell: bash -l {0}
working-directory: ./autotest
run: pytest -v -m="regression" -n=auto --durations=0 --keep-failed=.failed
run: pytest -v -m="regression" -n=auto --color=yes --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:

- name: Run tests
working-directory: autotest
run: pytest -v -m="not example and not regression" -n=auto --durations=0 --keep-failed=.failed --dist loadfile
run: pytest -v -m="not example and not regression" -n=auto --color=yes --durations=0 --keep-failed=.failed --dist loadfile
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rtd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:

- name: Run tutorial and example notebooks
working-directory: autotest
run: pytest -v -n auto test_notebooks.py
run: pytest -v -n auto --color=yes test_notebooks.py

- name: Upload notebooks artifact for ReadtheDocs
if: github.repository_owner == 'modflowpy' && github.event_name == 'push' && runner.os == 'Linux'
Expand Down
60 changes: 23 additions & 37 deletions autotest/test_model_splitter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np
import flopy
import pytest
from autotest.conftest import get_example_data_path
from modflow_devtools.markers import requires_exe, requires_pkg

import flopy
from flopy.mf6 import MFSimulation
from flopy.mf6.utils import Mf6Splitter

Expand Down Expand Up @@ -260,11 +260,7 @@ def test_control_records(function_tmpdir):
tdis = flopy.mf6.ModflowTdis(
sim,
nper=nper,
perioddata=(
(1., 1, 1.),
(1., 1, 1.),
(1., 1, 1.)
)
perioddata=((1.0, 1, 1.0), (1.0, 1, 1.0), (1.0, 1, 1.0)),
)

gwf = flopy.mf6.ModflowGwf(sim, save_flows=True)
Expand All @@ -279,20 +275,20 @@ def test_control_records(function_tmpdir):
delc=1,
top=35,
botm=[30, botm2],
idomain=1
idomain=1,
)

ic = flopy.mf6.ModflowGwfic(gwf, strt=32)
npf = flopy.mf6.ModflowGwfnpf(
gwf,
k=[
1.,
1.0,
{
"data": np.ones((10, 10)) * 0.75,
"filename": "k.l2.txt",
"iprn": 1,
"factor": 1
}
"factor": 1,
},
],
k33=[
np.ones((nrow, ncol)),
Expand All @@ -301,41 +297,29 @@ def test_control_records(function_tmpdir):
"filename": "k33.l2.bin",
"iprn": 1,
"factor": 1,
"binary": True
}
]

"binary": True,
},
],
)

wel_rec = [((0, 4, 5), -10), ]
wel_rec = [
((0, 4, 5), -10),
]

spd = {
0: wel_rec,
1: {
"data": wel_rec,
"filename": "wel.1.txt"
},
2: {
"data": wel_rec,
"filename": "wel.2.bin",
"binary": True
}
1: {"data": wel_rec, "filename": "wel.1.txt"},
2: {"data": wel_rec, "filename": "wel.2.bin", "binary": True},
}

wel = flopy.mf6.ModflowGwfwel(
gwf,
stress_period_data=spd
)
wel = flopy.mf6.ModflowGwfwel(gwf, stress_period_data=spd)

chd_rec = []
for cond, j in ((30, 0), (22, 9)):
for i in range(10):
chd_rec.append(((0, i, j), cond))

chd = flopy.mf6.ModflowGwfchd(
gwf,
stress_period_data={0: chd_rec}
)
chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data={0: chd_rec})

arr = np.zeros((10, 10), dtype=int)
arr[0:5, :] = 1
Expand All @@ -354,14 +338,18 @@ def test_control_records(function_tmpdir):
"External ascii files not being preserved for MFArray"
)

k33ls = ml1.npf.k33._data_storage.layer_storage.multi_dim_list
k33ls = ml1.npf.k33._data_storage.layer_storage.multi_dim_list
if k33ls[1].data_storage_type.value != 3 or not k33ls[1].binary:
raise AssertionError(
"Binary file input not being preserved for MFArray"
)

spd_ls1 = ml1.wel.stress_period_data._data_storage[1].layer_storage.multi_dim_list[0]
spd_ls2 = ml1.wel.stress_period_data._data_storage[2].layer_storage.multi_dim_list[0]
spd_ls1 = ml1.wel.stress_period_data._data_storage[
1
].layer_storage.multi_dim_list[0]
spd_ls2 = ml1.wel.stress_period_data._data_storage[
2
].layer_storage.multi_dim_list[0]

if spd_ls1.data_storage_type.value != 3 or spd_ls1.binary:
raise AssertionError(
Expand All @@ -372,5 +360,3 @@ def test_control_records(function_tmpdir):
raise AssertionError(
"External binary file input not being preseved for MFList"
)


2 changes: 1 addition & 1 deletion autotest/test_modflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import numpy as np
import pytest
from autotest.conftest import get_example_data_path
from modflow_devtools.misc import has_pkg
from modflow_devtools.markers import excludes_platform, requires_exe
from modflow_devtools.misc import has_pkg

from flopy.discretization import StructuredGrid
from flopy.mf6 import MFSimulation
Expand Down

0 comments on commit b0a9481

Please sign in to comment.