Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autotest/Autotesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ The space between `-n` and the number of processors can be replaced with a

pytest -v -n=auto t001_test.py

### Debugging failed tests

To debug a failed autotest rerun the failed test by running the following command from the autotest directory

python mffailedtest.py --keep

The `--keep` will retain the test directories created by the test, which will allow the input or output files to be evaluated for errors.

## Creating an autotest

Expand Down
1 change: 0 additions & 1 deletion autotest/t016_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import flopy
import numpy as np

from ci_framework import baseTestDir, flopyTest

baseDir = baseTestDir(__file__, relPath="temp", verbose=True)
Expand Down
28 changes: 17 additions & 11 deletions autotest/t017_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import os
import numpy as np
import flopy
from ci_framework import baseTestDir, flopyTest

cpth = os.path.join("temp", "t017")
# make the directory if it does not exists
if not os.path.isdir(cpth):
os.makedirs(cpth, exist_ok=True)
baseDir = baseTestDir(__file__, relPath="temp", verbose=True)


def test_formattedfile_read():
model_ws = f"{baseDir}_test_formattedfile_read"
testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True)

h = flopy.utils.FormattedHeadFile(
os.path.join("..", "examples", "data", "mf2005_test", "test1tr.githds")
Expand Down Expand Up @@ -41,7 +41,7 @@ def test_formattedfile_read():
h.close()

# Check error when reading empty file
fname = os.path.join(cpth, "empty.githds")
fname = os.path.join(model_ws, "empty.githds")
with open(fname, "w"):
pass
with pytest.raises(ValueError):
Expand All @@ -51,6 +51,8 @@ def test_formattedfile_read():


def test_binaryfile_read():
model_ws = f"{baseDir}_test_binaryfile_read"
testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True)

h = flopy.utils.HeadFile(
os.path.join("..", "examples", "data", "freyberg", "freyberg.githds")
Expand Down Expand Up @@ -81,7 +83,7 @@ def test_binaryfile_read():
h.close()

# Check error when reading empty file
fname = os.path.join(cpth, "empty.githds")
fname = os.path.join(model_ws, "empty.githds")
with open(fname, "w"):
pass
with pytest.raises(ValueError):
Expand Down Expand Up @@ -148,6 +150,8 @@ def test_cellbudgetfile_read():


def test_cellbudgetfile_position():
model_ws = f"{baseDir}_test_cellbudgetfile_position"
testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True)

fpth = os.path.join(
"..", "examples", "data", "zonbud_examples", "freyberg.gitcbc"
Expand Down Expand Up @@ -176,7 +180,7 @@ def test_cellbudgetfile_position():
length = os.path.getsize(fpth) - ipos

buffsize = 32
opth = os.path.join(cpth, "end.cbc")
opth = os.path.join(model_ws, "end.cbc")
with open(opth, "wb") as fout:
while length:
chunk = min(buffsize, length)
Expand Down Expand Up @@ -204,7 +208,7 @@ def test_cellbudgetfile_position():
assert np.array_equal(d1, d2), msg

# Check error when reading empty file
fname = os.path.join(cpth, "empty.gitcbc")
fname = os.path.join(model_ws, "empty.gitcbc")
with open(fname, "w"):
pass
with pytest.raises(ValueError):
Expand Down Expand Up @@ -324,12 +328,14 @@ def test_cellbudgetfile_readrecord_waux():


def test_binaryfile_writeread():
model_ws = f"{baseDir}_test_binaryfile_writeread"
testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True)

pth = os.path.join("..", "examples", "data", "nwt_test")
model = "Pr3_MFNWT_lower.nam"
ml = flopy.modflow.Modflow.load(model, version="mfnwt", model_ws=pth)
# change the model work space
ml.change_model_ws(os.path.join("temp", "t017"))
ml.change_model_ws(model_ws)
#
ncol = ml.dis.ncol
nrow = ml.dis.nrow
Expand All @@ -350,7 +356,7 @@ def test_binaryfile_writeread():
kper=1,
)
b = ml.dis.botm.array[0, :, :].astype(np.float64)
pth = os.path.join("temp", "t017", "bottom.hds")
pth = os.path.join(model_ws, "bottom.hds")
flopy.utils.Util2d.write_bin(b.shape, pth, b, header_data=header)

bo = flopy.utils.HeadFile(pth, precision=precision)
Expand Down Expand Up @@ -380,7 +386,7 @@ def test_binaryfile_writeread():
kper=1,
)
b = ml.dis.botm.array[0, :, :].astype(np.float32)
pth = os.path.join("temp", "t017", "bottom_single.hds")
pth = os.path.join(model_ws, "bottom_single.hds")
flopy.utils.Util2d.write_bin(b.shape, pth, b, header_data=header)

bo = flopy.utils.HeadFile(pth, precision=precision)
Expand Down
31 changes: 17 additions & 14 deletions autotest/t018_test.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import os
import numpy as np
import flopy
from ci_framework import baseTestDir, flopyTest

# import flopy.pest.templatewriter
# import flopy.pest.templatewriter as flopy.pest.templatewriter
# import flopy.pest.flopy.pest.params as flopy.pest.params

mpth = os.path.join("temp", "t018")
# make the directory if it does not exist
if not os.path.isdir(mpth):
os.makedirs(mpth, exist_ok=True)
baseDir = baseTestDir(__file__, relPath="temp", verbose=True)


def test_tpl_constant():
model_ws = f"{baseDir}_test_tpl_constant"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

# Define the model dimensions
nlay = 3
nrow = 20
ncol = 20

# Create the flopy model object and add the dis and lpf packages
m = flopy.modflow.Modflow(modelname="tpl1", model_ws=mpth)
m = flopy.modflow.Modflow(modelname="tpl1", model_ws=model_ws)
dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol)
lpf = flopy.modflow.ModflowLpf(m, hk=10.0)

Expand All @@ -46,19 +43,22 @@ def test_tpl_constant():
tw = flopy.pest.templatewriter.TemplateWriter(m, [p])
tw.write_template()

tplfile = os.path.join(mpth, "tpl1.lpf.tpl")
tplfile = os.path.join(model_ws, "tpl1.lpf.tpl")
assert os.path.isfile(tplfile)

return


def test_tpl_layered():
model_ws = f"{baseDir}_test_tpl_layered"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

nlay = 3
nrow = 20
ncol = 20

# Create the flopy model object and add the dis and lpf packages
m = flopy.modflow.Modflow(modelname="tpl2", model_ws=mpth)
m = flopy.modflow.Modflow(modelname="tpl2", model_ws=model_ws)
dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol)
lpf = flopy.modflow.ModflowLpf(m, hk=10.0)

Expand All @@ -81,19 +81,22 @@ def test_tpl_layered():
tw = flopy.pest.templatewriter.TemplateWriter(m, [p])
tw.write_template()

tplfile = os.path.join(mpth, "tpl2.lpf.tpl")
tplfile = os.path.join(model_ws, "tpl2.lpf.tpl")
assert os.path.isfile(tplfile)

return


def test_tpl_zoned():
model_ws = f"{baseDir}_test_tpl_zoned"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

nlay = 3
nrow = 20
ncol = 20

# Create the flopy model object and add the dis and lpf packages
m = flopy.modflow.Modflow(modelname="tpl3", model_ws=mpth)
m = flopy.modflow.Modflow(modelname="tpl3", model_ws=model_ws)
dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol)
lpf = flopy.modflow.ModflowLpf(m, hk=10.0)

Expand Down Expand Up @@ -144,7 +147,7 @@ def test_tpl_zoned():
tw = flopy.pest.templatewriter.TemplateWriter(m, plist)
tw.write_template()

tplfile = os.path.join(mpth, "tpl3.lpf.tpl")
tplfile = os.path.join(model_ws, "tpl3.lpf.tpl")
assert os.path.isfile(tplfile)

return
Expand Down
23 changes: 8 additions & 15 deletions autotest/t019_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import os
import numpy as np
import flopy
from ci_framework import baseTestDir, flopyTest

mpth = os.path.join("temp", "t019")
# make the directory if it does not exist
if not os.path.isdir(mpth):
os.makedirs(mpth, exist_ok=True)
baseDir = baseTestDir(__file__, relPath="temp", verbose=True)


# Test hydmod data readers
def test_hydmodfile_create():
model_ws = os.path.join(mpth)
if not os.path.isdir(model_ws):
os.makedirs(model_ws, exist_ok=True)
model_ws = f"{baseDir}_test_hydmodfile_create"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

m = flopy.modflow.Modflow("test", model_ws=model_ws)
hyd = flopy.modflow.ModflowHyd(m)
m.hyd.write_file()
Expand Down Expand Up @@ -48,6 +46,9 @@ def test_hydmodfile_create():


def test_hydmodfile_load():
model_ws = f"{baseDir}_test_hydmodfile_load"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

model = "test1tr.nam"
pth = os.path.join("..", "examples", "data", "hydmod_test")
m = flopy.modflow.Modflow.load(
Expand All @@ -58,10 +59,6 @@ def test_hydmodfile_load():
hydref, flopy.modflow.ModflowHyd
), "Did not load hydmod package...test1tr.hyd"

model_ws = os.path.join(mpth)
if not os.path.isdir(model_ws):
os.makedirs(model_ws, exist_ok=True)

m.change_model_ws(model_ws)
m.hyd.write_file()

Expand All @@ -75,8 +72,6 @@ def test_hydmodfile_load():


def test_hydmodfile_read():
import os
import flopy

pth = os.path.join(
"..", "examples", "data", "hydmod_test", "test1tr.hyd.gitbin"
Expand Down Expand Up @@ -149,8 +144,6 @@ def test_hydmodfile_read():


def test_mf6obsfile_read():
import os
import flopy

try:
import pandas as pd
Expand Down
27 changes: 13 additions & 14 deletions autotest/t020_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# Test modflow write adn run
# Test modflow write and run
import numpy as np
import matplotlib.pyplot as plt
from ci_framework import baseTestDir, flopyTest

try:
import matplotlib.pyplot as plt

# if os.getenv('TRAVIS'): # are we running https://travis-ci.org/ automated tests ?
# matplotlib.use('Agg') # Force matplotlib not to use any Xwindows backend
except:
plt = None
baseDir = baseTestDir(__file__, relPath="temp", verbose=True)


def analyticalWaterTableSolution(h1, h2, z, R, K, L, x):
Expand All @@ -34,10 +30,10 @@ def test_mfnwt_run():
print(f"Specified executable {exe_name} does not exist in path")
return

model_ws = f"{baseDir}_test_mfnwt_run"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

modelname = "watertable"
model_ws = os.path.join("temp", "t020")
if not os.path.isdir(model_ws):
os.makedirs(model_ws, exist_ok=True)

# model dimensions
nlay, nrow, ncol = 1, 1, 100
Expand Down Expand Up @@ -172,6 +168,9 @@ def test_irch():
import os
import flopy

model_ws = f"{baseDir}_test_tpl_constant"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

org_model_ws = os.path.join(
"..", "examples", "data", "freyberg_multilayer_transient"
)
Expand All @@ -197,11 +196,11 @@ def test_irch():
d = arr - aarr
assert np.abs(d).sum() == 0

new_model_ws = "temp"
m.change_model_ws(new_model_ws)
m.change_model_ws(model_ws)
m.write_input()

mm = flopy.modflow.Modflow.load(
nam_file, model_ws="temp", forgive=False, verbose=True, check=False
nam_file, model_ws=model_ws, forgive=False, verbose=True, check=False
)
for kper in range(m.nper):
arr = irch[kper]
Expand Down
30 changes: 16 additions & 14 deletions autotest/t021_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Test modflow write adn run
import os
import numpy as np
import flopy
from ci_framework import baseTestDir, flopyTest

mpth = os.path.join("temp", "t021")
# make the directory if it does not exist
if not os.path.isdir(mpth):
os.makedirs(mpth, exist_ok=True)
baseDir = baseTestDir(__file__, relPath="temp", verbose=True)


def test_mflist_external():
model_ws = f"{baseDir}_test_mflist_external"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

ml = flopy.modflow.Modflow(
"mflist_test", model_ws=mpth, external_path=os.path.join(mpth, "ref")
"mflist_test",
model_ws=model_ws,
external_path=os.path.join(model_ws, "ref"),
)
dis = flopy.modflow.ModflowDis(ml, 1, 10, 10, nper=3, perlen=1.0)
wel_data = {
Expand All @@ -36,24 +38,24 @@ def test_mflist_external():


def test_single_mflist_entry_load():
model_ws = f"{baseDir}_test_single_mflist_entry_load"
testFramework = flopyTest(verbose=True, testDirs=model_ws)

import os
import numpy as np
import flopy

model_ws = os.path.join("..", "examples", "data", "freyberg")
pth = os.path.join("..", "examples", "data", "freyberg")
m = flopy.modflow.Modflow.load(
"freyberg.nam", model_ws=model_ws, load_only=["WEL"], check=False
"freyberg.nam", model_ws=pth, load_only=["WEL"], check=False
)
w = m.wel
spd = w.stress_period_data
flopy.modflow.ModflowWel(m, stress_period_data={0: [0, 0, 0, 0.0]})
m.external_path = "."
m.change_model_ws("temp", reset_external=True)
m.change_model_ws(model_ws, reset_external=True)
m.write_input()

mm = flopy.modflow.Modflow.load(
"freyberg.nam", model_ws="temp", forgive=False
"freyberg.nam",
model_ws=model_ws,
forgive=False,
)
assert mm.wel.stress_period_data
mm.write_input()
Expand Down
Loading