New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(HeadUFile): repro & fix #1503, add tests #1510
Merged
Merged
Conversation
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
Codecov Report
@@ Coverage Diff @@
## develop #1510 +/- ##
=========================================
- Coverage 72.4% 72.4% -0.1%
=========================================
Files 250 251 +1
Lines 54039 54055 +16
=========================================
+ Hits 39174 39183 +9
- Misses 14865 14872 +7
|
wpbonelli
force-pushed
the
tests
branch
11 times, most recently
from
August 25, 2022 20:15
ff87d59
to
12e9909
Compare
Hypothesis is compatible with pytest. We use it successfully in multiple projects. |
* add flopy.utils.grid.py and get_lni(ncpl, *nodes) function ('layer node index') * add get_lni(*nodes) method to grids * add tests for new functions & methods * use get_lni in HeadUFile.get_ts(idx) (fix modflowpy#1503) * test HeadUFile.get_ts(idx) for every grid node * run linter on examples and tests * add addopts = -ra to pytest.ini (show info for skipped/xfailed tests) * add pytest-cases to setup.cfg and environment.yml test dependencies * use pytest-cases to define grids & parametrize grid tests * mark EPSG test cases flaky
jdhughes-usgs
approved these changes
Aug 26, 2022
langevin-usgs
approved these changes
Aug 26, 2022
@w-bonelli go ahead and merge this in. |
This was referenced Aug 29, 2022
wpbonelli
added a commit
to wpbonelli/flopy
that referenced
this pull request
Dec 14, 2022
* add flopy.utils.grid.py and get_lni(ncpl, *nodes) function ('layer node index') * add get_lni(*nodes) method to grids * add tests for new functions & methods * use get_lni in HeadUFile.get_ts(idx) (fix modflowpy#1503) * test HeadUFile.get_ts(idx) for every grid node * run linter on examples and tests * add addopts = -ra to pytest.ini (show info for skipped/xfailed tests) * add pytest-cases to setup.cfg and environment.yml test dependencies * use pytest-cases to define grids & parametrize grid tests * mark EPSG test cases flaky
wpbonelli
added a commit
to wpbonelli/flopy
that referenced
this pull request
Dec 14, 2022
* add flopy.utils.grid.py and get_lni(ncpl, *nodes) function ('layer node index') * add get_lni(*nodes) method to grids * add tests for new functions & methods * use get_lni in HeadUFile.get_ts(idx) (fix modflowpy#1503) * test HeadUFile.get_ts(idx) for every grid node * run linter on examples and tests * add addopts = -ra to pytest.ini (show info for skipped/xfailed tests) * add pytest-cases to setup.cfg and environment.yml test dependencies * use pytest-cases to define grids & parametrize grid tests * mark EPSG test cases flaky
wpbonelli
added a commit
that referenced
this pull request
Dec 14, 2022
* add flopy.utils.grid.py and get_lni(ncpl, *nodes) function ('layer node index') * add get_lni(*nodes) method to grids * add tests for new functions & methods * use get_lni in HeadUFile.get_ts(idx) (fix #1503) * test HeadUFile.get_ts(idx) for every grid node * run linter on examples and tests * add addopts = -ra to pytest.ini (show info for skipped/xfailed tests) * add pytest-cases to setup.cfg and environment.yml test dependencies * use pytest-cases to define grids & parametrize grid tests * mark EPSG test cases flaky
wpbonelli
added a commit
to wpbonelli/flopy
that referenced
this pull request
Dec 14, 2022
* add flopy.utils.grid.py and get_lni(ncpl, *nodes) function ('layer node index') * add get_lni(*nodes) method to grids * add tests for new functions & methods * use get_lni in HeadUFile.get_ts(idx) (fix modflowpy#1503) * test HeadUFile.get_ts(idx) for every grid node * run linter on examples and tests * add addopts = -ra to pytest.ini (show info for skipped/xfailed tests) * add pytest-cases to setup.cfg and environment.yml test dependencies * use pytest-cases to define grids & parametrize grid tests * mark EPSG test cases flaky
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes:
get_lni(ncpl, *nodes)
function inflopy.utils.gridutil.py
(convert node number to within-layer node index)get_lni(ncpl, *nodes)
inHeadUFile.get_ts(idx)
(fix bug: error when call get_ts() function of class HeadUFile #1503)get_lni(*nodes)
method toGrid
nlay
property onGrid
addopts -ra
topytest.ini
(show more info about skipped and xfailed tests)pytest-cases
to testing dependencies insetup.cfg
andetc/environment.yml
pytest-cases
to define grids intest_grid_cases.py
and parametrize tests intest_grid.py
HeadUFile.get_ts()
fixAs reported in #1503
HeadUFile.get_ts()
was converting node number to within-layer node index incorrectly, causing anIndexError
. This wasn't revealed before because it only happened for nodes in layers 2+ and tests only calledget_ts()
on nodes in layer 1. Now the index conversion is done in functionget_lni(ncpl, *nodes)
(for "layer-node-index") in new moduleflopy.utils.gridutil.py
. The function's parameters are:ncpl
: singleint
or collection ofint
if node count varies per layer*nodes
zero or more node numbersThe return value is a tuple
(layer, node index)
if a single node number was provided, otherwise a list of tuples. If no node numbers are provided, the values for all nodes will be returned in ascending order by node number.HeadUFile.get_ts(idx)
is now tested for every node of a sample gridGrid updates
Adds corresponding method
get_lni(*nodes)
toGrid
, which uses the standalone function above internally.Also adds unimplemented
nlay
property toGrid
, following convention for other props shared by all grid types.Test fixtures & parametrization
Per @Hofer-Julian's suggestion I tried out
pytest-cases
on some tests intest_grid.py
. This plugin provides mechanisms to extend or work around limitations ofpytest
fixtures (e.g. the inability to use them to parametrize a test function).A number of tests in
test_grid.py
previously built and tested their own custom grids. Some of these have been pulled into theGridCases
class intest_grid_cases.py
, which now holds a few examples of each grid type. Some tests intest_grid.py
are now parametrized with some or allGridCases
, depending whether properties under test are shared or specific to a grid type —pytest-cases
lets you subset via prefix, e.g. naming structured gridsstructured_*
and selecting with e.g.@parametrize_with_cases("grid", cases=GridCases, prefix="structured")
.The grids are still defined by hand. A future option might be generating grids from a random seed and some size/complexity parameters.
pytest-cases
supports dynamically generating cases, ifpytest_generate_tests
is not sufficient. Maybe something like hypothesis could be useful, assuming it's compatible with pytest.