From 5964558fd09d3cd06c202cc7c7be80c3d1a31fe8 Mon Sep 17 00:00:00 2001 From: Joseph D Hughes Date: Mon, 20 Dec 2021 12:53:07 -0600 Subject: [PATCH 1/2] ci: update t058 to fix issue on macos with python 3.9 --- autotest/t058_test_mp7.py | 137 ++++++++++++++++----------- autotest/t065_test_gridintersect.py | 6 +- autotest/t069_test_vtkexportmodel.py | 4 +- autotest/t080_test.py | 4 +- 4 files changed, 90 insertions(+), 61 deletions(-) diff --git a/autotest/t058_test_mp7.py b/autotest/t058_test_mp7.py index 0fc6f3461f..0acd615fc6 100644 --- a/autotest/t058_test_mp7.py +++ b/autotest/t058_test_mp7.py @@ -2,10 +2,9 @@ import numpy as np import flopy -model_ws = os.path.join("temp", "t058") -# make the directory if it does not exist -if not os.path.isdir(model_ws): - os.makedirs(model_ws, exist_ok=True) +from ci_framework import base_test_dir, FlopyTestSetup + +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) exe_names = {"mf6": "mf6", "mp7": "mp7"} run = True @@ -15,7 +14,6 @@ run = False break -ws = model_ws nm = "ex01b_mf6" # model data @@ -56,19 +54,22 @@ ) -def test_mf6(): - # build and run MODPATH 7 with MODFLOW 6 - build_mf6() - - def test_default_modpath(): + model_ws = f"{base_dir}_test_default_modpath" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_default" pg = flopy.modpath.ParticleGroup(particlegroupname="DEFAULT") - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) return def test_faceparticles_is1(): + model_ws = f"{base_dir}_test_faceparticles_is1" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_face_t1node" locs = [] localx = [] @@ -87,11 +88,29 @@ def test_faceparticles_is1(): pg = flopy.modpath.ParticleGroup( particlegroupname="T1NODEPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) + + # set base file name + fpth0 = os.path.join(model_ws, "ex01b_mf6_mp_face_t1node.mpend") + + # get list of node endpath files + epf = [ + os.path.join(model_ws, name) + for name in os.listdir(model_ws) + if ".mpend" in name and "_face_" in name and "_t2a" not in name + ] + epf.remove(fpth0) + + endpoint_compare(fpth0, epf) + return def test_facenode_is3(): + model_ws = f"{base_dir}_test_facenode_is2" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_face_t3node" locs = [] for i in range(nrow): @@ -118,11 +137,15 @@ def test_facenode_is3(): pg = flopy.modpath.ParticleGroupNodeTemplate( particlegroupname="T3NODEPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) return def test_facenode_is3a(): + model_ws = f"{base_dir}_test_facenode_is3a" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_face_t3anode" locsa = [] for i in range(11): @@ -156,11 +179,15 @@ def test_facenode_is3a(): pg = flopy.modpath.ParticleGroupNodeTemplate( particlegroupname="T3ANODEPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) return def test_facenode_is2a(): + model_ws = f"{base_dir}_test_facenode_is2a" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_face_t2anode" locsa = [[0, 0, 0, 0, 10, ncol - 1]] locsb = [[0, 11, 0, 0, nrow - 1, ncol - 1]] @@ -186,11 +213,15 @@ def test_facenode_is2a(): pg = flopy.modpath.ParticleGroupNodeTemplate( particlegroupname="T2ANODEPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) return def test_cellparticles_is1(): + model_ws = f"{base_dir}_test_cellparticles_is1" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_cell_t1node" locs = [] for k in range(nlay): @@ -205,11 +236,29 @@ def test_cellparticles_is1(): pg = flopy.modpath.ParticleGroup( particlegroupname="T1NODEPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) + + # set base file name + fpth0 = os.path.join(model_ws, "ex01b_mf6_mp_cell_t1node.mpend") + + # get list of node endpath files + epf = [ + os.path.join(model_ws, name) + for name in os.listdir(model_ws) + if ".mpend" in name and "_cell_" in name and "_t2a" not in name + ] + epf.remove(fpth0) + + endpoint_compare(fpth0, epf) + return def test_cellparticleskij_is1(): + model_ws = f"{base_dir}_test_cellparticleskij_is1" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_cell_t1kij" locs = [] for k in range(nlay): @@ -223,11 +272,15 @@ def test_cellparticleskij_is1(): pg = flopy.modpath.ParticleGroup( particlegroupname="T1KIJPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) return def test_cellnode_is3(): + model_ws = f"{base_dir}_test_cellnode_is3" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_cell_t3node" locs = [] for k in range(nlay): @@ -246,11 +299,15 @@ def test_cellnode_is3(): pg = flopy.modpath.ParticleGroupNodeTemplate( particlegroupname="T3CELLPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) return def test_cellnode_is3a(): + model_ws = f"{base_dir}_test_cellnode_is3a" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_cell_t3anode" locsa = [] for k in range(1): @@ -283,11 +340,15 @@ def test_cellnode_is3a(): pg = flopy.modpath.ParticleGroupNodeTemplate( particlegroupname="T3ACELLPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) + build_modpath(model_ws, mpnam, pg) return def test_cellnode_is2a(): + model_ws = f"{base_dir}_test_cellnode_is2a" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_cell_t2anode" locsa = [ [0, 0, 0, 0, nrow - 1, ncol - 1], @@ -307,39 +368,7 @@ def test_cellnode_is2a(): pg = flopy.modpath.ParticleGroupLRCTemplate( particlegroupname="T2ACELLPG", particledata=p, filename=fpth ) - build_modpath(mpnam, pg) - return - - -def test_face_endpoint_output(): - # set base file name - fpth0 = os.path.join(model_ws, "ex01b_mf6_mp_face_t1node.mpend") - - # get list of node endpath files - epf = [ - os.path.join(model_ws, name) - for name in os.listdir(model_ws) - if ".mpend" in name and "_face_" in name and "_t2a" not in name - ] - epf.remove(fpth0) - - endpoint_compare(fpth0, epf) - return - - -def test_cell_endpoint_output(): - # set base file name - fpth0 = os.path.join(model_ws, "ex01b_mf6_mp_cell_t1node.mpend") - - # get list of node endpath files - epf = [ - os.path.join(model_ws, name) - for name in os.listdir(model_ws) - if ".mpend" in name and "_cell_" in name and "_t2a" not in name - ] - epf.remove(fpth0) - - endpoint_compare(fpth0, epf) + build_modpath(model_ws, mpnam, pg) return @@ -408,7 +437,7 @@ def endpoint_compare(fpth0, epf): return -def build_mf6(): +def build_mf6(ws): """ MODPATH 7 example 1 for MODFLOW 6 """ @@ -492,7 +521,7 @@ def build_mf6(): assert success, "mf6 model did not run" -def build_modpath(mpn, particlegroups): +def build_modpath(ws, mpn, particlegroups): # load the MODFLOW 6 model sim = flopy.mf6.MFSimulation.load("mf6mod", "mf6", "mf6", ws) gwf = sim.get_model(nm) diff --git a/autotest/t065_test_gridintersect.py b/autotest/t065_test_gridintersect.py index c1bc084e4c..f37a7f2466 100644 --- a/autotest/t065_test_gridintersect.py +++ b/autotest/t065_test_gridintersect.py @@ -1402,14 +1402,12 @@ def test_raster_sampling_methods(): "median": 2097.36254, "nearest": 2097.81079, "linear": 2097.81079, - "cubic": 2097.81079 + "cubic": 2097.81079, } for method, value in methods.items(): data = rio.resample_to_grid( - ml.modelgrid, - band=rio.bands[0], - method=method + ml.modelgrid, band=rio.bands[0], method=method ) print(data[30, 37]) diff --git a/autotest/t069_test_vtkexportmodel.py b/autotest/t069_test_vtkexportmodel.py index 641b634dcd..d4258778f8 100644 --- a/autotest/t069_test_vtkexportmodel.py +++ b/autotest/t069_test_vtkexportmodel.py @@ -17,7 +17,9 @@ def test_vtk_export_model_without_packages_names(): test_setup = FlopyTestSetup(verbose=True, test_dirs=base_dir) name = "mymodel" - sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=base_dir, exe_name="mf6") + sim = flopy.mf6.MFSimulation( + sim_name=name, sim_ws=base_dir, exe_name="mf6" + ) tdis = flopy.mf6.ModflowTdis(sim) ims = flopy.mf6.ModflowIms(sim) gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True) diff --git a/autotest/t080_test.py b/autotest/t080_test.py index 9e5675d95a..f2dabf908e 100644 --- a/autotest/t080_test.py +++ b/autotest/t080_test.py @@ -140,7 +140,7 @@ def test_usg_iverts(): [8, 12, 20, 19, 18, 9], [22, 14, 13, 12, 20, 21], [24, 17, 18, 19, 23, None], - [21, 20, 19, 23, 25, None] + [21, 20, 19, 23, 25, None], ] verts = [ [0.0, 22.5], @@ -168,7 +168,7 @@ def test_usg_iverts(): [15.0, 0.0], [30.0, 7.5], [30.0, 15.0], - [30.0, 0.0] + [30.0, 0.0], ] grid = flopy.discretization.UnstructuredGrid( From 75643b0a6f6b43a46e9a27ebe4f43666556d3665 Mon Sep 17 00:00:00 2001 From: Joseph D Hughes Date: Mon, 20 Dec 2021 14:45:29 -0600 Subject: [PATCH 2/2] ci: update t058 to fix issue on macos with python 3.9 update remaining tests to use new testing functionality to avoid possible race conditions with parallel pytest --- autotest/t043_test.py | 1 - autotest/t044_test.py | 42 +++++++---------- autotest/t045_test.py | 47 +++++++++---------- autotest/t046_test.py | 48 +++++++++---------- autotest/t047_test.py | 30 +++++++----- autotest/t049_test.py | 71 +++++++++++++++++------------ autotest/t051_test.py | 20 ++++---- autotest/t052_test.py | 35 +++++++------- autotest/t053_test.py | 5 -- autotest/t054_test_mfnwt.py | 28 ++++++------ autotest/t056_test_pcg_fmt.py | 4 +- autotest/t057_test_mp7.py | 86 +++++++---------------------------- autotest/t059_test_mp7.py | 31 +++++++------ autotest/t060_test_lkt.py | 23 +++++----- autotest/t061_test_gridgen.py | 16 ++++--- autotest/t063_test_lgrutil.py | 7 --- 16 files changed, 221 insertions(+), 273 deletions(-) diff --git a/autotest/t043_test.py b/autotest/t043_test.py index 209a507b28..04607fc617 100644 --- a/autotest/t043_test.py +++ b/autotest/t043_test.py @@ -2,7 +2,6 @@ Test the observation process load and write """ import os -import shutil import filecmp import flopy import pymake diff --git a/autotest/t044_test.py b/autotest/t044_test.py index fc255f66fe..5b75e90ea1 100644 --- a/autotest/t044_test.py +++ b/autotest/t044_test.py @@ -4,18 +4,12 @@ import pytest import os import flopy +import pymake +from ci_framework import base_test_dir, FlopyTestSetup -try: - import pymake -except ImportError: - print("could not import pymake") - pymake = False +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) path = os.path.join("..", "examples", "data", "pcgn_test") -cpth = os.path.join("temp", "t044") -# make the directory if it does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) mf_items = ["twri.nam", "MNW2.nam"] pths = [] @@ -29,21 +23,19 @@ def load_and_write_pcgn(mfnam, pth): """ exe_name = "mf2005" v = flopy.which(exe_name) + run = v is not None - if pymake: - run = v is not None - lpth = os.path.join(cpth, os.path.splitext(mfnam)[0]) - apth = os.path.join(lpth, "flopy") - compth = lpth - pymake.setup(os.path.join(pth, mfnam), lpth) - else: - run = False - lpth = pth - apth = cpth - compth = cpth + model_ws = f"{base_dir}_{mfnam}" + compth = os.path.join(model_ws, "flopy") + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + + pymake.setup(os.path.join(pth, mfnam), model_ws) m = flopy.modflow.Modflow.load( - mfnam, model_ws=lpth, verbose=True, exe_name=exe_name + mfnam, + model_ws=model_ws, + verbose=True, + exe_name=exe_name, ) assert m.load_fail is False if mfnam in ["twri.nam"]: # update this list for fixed models @@ -57,10 +49,10 @@ def load_and_write_pcgn(mfnam, pth): except: success = False assert success, "base model run did not terminate successfully" - fn0 = os.path.join(lpth, mfnam) + fn0 = os.path.join(model_ws, mfnam) # rewrite files - m.change_model_ws(apth) + m.change_model_ws(compth) m.write_input() if run: try: @@ -68,10 +60,10 @@ def load_and_write_pcgn(mfnam, pth): except: success = False assert success, "new model run did not terminate successfully" - fn1 = os.path.join(apth, mfnam) + fn1 = os.path.join(compth, mfnam) if run: - fsum = os.path.join(compth, f"{os.path.splitext(mfnam)[0]}.head.out") + fsum = os.path.join(model_ws, f"{os.path.splitext(mfnam)[0]}.head.out") success = False try: success = pymake.compare_heads(fn0, fn1, outfile=fsum, htol=0.005) diff --git a/autotest/t045_test.py b/autotest/t045_test.py index be0e286654..c6c575afbf 100644 --- a/autotest/t045_test.py +++ b/autotest/t045_test.py @@ -4,18 +4,13 @@ import pytest import os import flopy +import pymake +from ci_framework import base_test_dir, FlopyTestSetup + +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) -try: - import pymake -except ImportError: - print("could not import pymake") - pymake = False path = os.path.join("..", "examples", "data", "secp") -cpth = os.path.join("temp", "t045") -# make the directory if is does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) mf_items = ["secp.nam"] pths = [] @@ -29,21 +24,19 @@ def load_and_write_gmg(mfnam, pth): """ exe_name = "mf2005" v = flopy.which(exe_name) + run = v is not None + + model_ws = f"{base_dir}_{mfnam}" + compth = os.path.join(model_ws, "flopy") + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) - if pymake: - run = v is not None - lpth = os.path.join(cpth, os.path.splitext(mfnam)[0]) - apth = os.path.join(lpth, "flopy") - compth = lpth - pymake.setup(os.path.join(pth, mfnam), lpth) - else: - run = False - lpth = pth - apth = cpth - compth = cpth + pymake.setup(os.path.join(pth, mfnam), model_ws) m = flopy.modflow.Modflow.load( - mfnam, model_ws=lpth, verbose=True, exe_name=exe_name + mfnam, + model_ws=model_ws, + verbose=True, + exe_name=exe_name, ) assert m.load_fail is False @@ -53,10 +46,10 @@ def load_and_write_gmg(mfnam, pth): except: success = False assert success, "base model run did not terminate successfully" - fn0 = os.path.join(lpth, mfnam) + fn0 = os.path.join(model_ws, mfnam) # rewrite files - m.change_model_ws(apth) + m.change_model_ws(compth) m.write_input() if run: try: @@ -64,10 +57,10 @@ def load_and_write_gmg(mfnam, pth): except: success = False assert success, "new model run did not terminate successfully" - fn1 = os.path.join(apth, mfnam) + fn1 = os.path.join(compth, mfnam) if run: - fsum = os.path.join(compth, f"{os.path.splitext(mfnam)[0]}.head.out") + fsum = os.path.join(model_ws, f"{os.path.splitext(mfnam)[0]}.head.out") success = False try: success = pymake.compare_heads(fn0, fn1, outfile=fsum) @@ -77,7 +70,9 @@ def load_and_write_gmg(mfnam, pth): assert success, "head comparison failure" - fsum = os.path.join(compth, f"{os.path.splitext(mfnam)[0]}.budget.out") + fsum = os.path.join( + model_ws, f"{os.path.splitext(mfnam)[0]}.budget.out" + ) success = False try: success = pymake.compare_budget( diff --git a/autotest/t046_test.py b/autotest/t046_test.py index f28465e58c..4e3f3bcb28 100644 --- a/autotest/t046_test.py +++ b/autotest/t046_test.py @@ -4,18 +4,12 @@ import pytest import os import flopy +import pymake +from ci_framework import base_test_dir, FlopyTestSetup -try: - import pymake -except ImportError: - print("could not import pymake") - pymake = False +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) path = os.path.join("..", "examples", "data", "freyberg") -cpth = os.path.join("temp", "t046") -# make the directory if it does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) mf_items = ["freyberg.nam"] pths = [] @@ -29,21 +23,19 @@ def load_and_write(mfnam, pth): """ exe_name = "mf2005" v = flopy.which(exe_name) + run = v is not None - if pymake: - run = v is not None - lpth = os.path.join(cpth, os.path.splitext(mfnam)[0]) - apth = os.path.join(lpth, "flopy") - compth = lpth - pymake.setup(os.path.join(pth, mfnam), lpth) - else: - run = False - lpth = pth - apth = cpth - compth = cpth + model_ws = f"{base_dir}_{mfnam}" + compth = os.path.join(model_ws, "flopy") + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + + pymake.setup(os.path.join(pth, mfnam), model_ws) m = flopy.modflow.Modflow.load( - mfnam, model_ws=lpth, verbose=True, exe_name=exe_name + mfnam, + model_ws=model_ws, + verbose=True, + exe_name=exe_name, ) assert m.load_fail is False @@ -53,10 +45,10 @@ def load_and_write(mfnam, pth): except: success = False assert success, "base model run did not terminate successfully" - fn0 = os.path.join(lpth, mfnam) + fn0 = os.path.join(model_ws, mfnam) # change model workspace - m.change_model_ws(apth) + m.change_model_ws(compth) # recreate oc file oc = m.oc @@ -81,11 +73,11 @@ def load_and_write(mfnam, pth): except: success = False assert success, "new model run did not terminate successfully" - fn1 = os.path.join(apth, mfnam) + fn1 = os.path.join(compth, mfnam) if run: # compare heads - fsum = os.path.join(compth, f"{os.path.splitext(mfnam)[0]}.head.out") + fsum = os.path.join(model_ws, f"{os.path.splitext(mfnam)[0]}.head.out") success = False try: success = pymake.compare_heads(fn0, fn1, outfile=fsum) @@ -96,7 +88,7 @@ def load_and_write(mfnam, pth): assert success, "head comparison failure" # compare heads - fsum = os.path.join(compth, f"{os.path.splitext(mfnam)[0]}.ddn.out") + fsum = os.path.join(model_ws, f"{os.path.splitext(mfnam)[0]}.ddn.out") success = False try: success = pymake.compare_heads( @@ -109,7 +101,9 @@ def load_and_write(mfnam, pth): assert success, "head comparison failure" # compare budgets - fsum = os.path.join(compth, f"{os.path.splitext(mfnam)[0]}.budget.out") + fsum = os.path.join( + model_ws, f"{os.path.splitext(mfnam)[0]}.budget.out" + ) success = False try: success = pymake.compare_budget( diff --git a/autotest/t047_test.py b/autotest/t047_test.py index 0abf08b1df..e47ec91ce2 100644 --- a/autotest/t047_test.py +++ b/autotest/t047_test.py @@ -4,11 +4,9 @@ import os import flopy from flopy.utils.recarray_utils import recarray +from ci_framework import base_test_dir, FlopyTestSetup -cpth = os.path.join("temp", "t047") -# make the directory if it does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) def get_namefile_entries(fpth): @@ -49,10 +47,12 @@ def get_namefile_entries(fpth): def test_gage(): + model_ws = f"{base_dir}_test_gage" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) mnam = "gage_test" - m = flopy.modflow.Modflow(modelname=mnam, model_ws=cpth) + m = flopy.modflow.Modflow(modelname=mnam, model_ws=model_ws) dis = flopy.modflow.ModflowDis(m) spd = { (0, 0): ["print head"], @@ -73,7 +73,7 @@ def test_gage(): m.write_input() # check that the gage output units entries are in the name file - fpth = os.path.join(cpth, f"{mnam}.nam") + fpth = os.path.join(model_ws, f"{mnam}.nam") entries = get_namefile_entries(fpth) for idx, g in enumerate(gages): if g[0] < 0: @@ -93,10 +93,12 @@ def test_gage(): def test_gage_files(): + model_ws = f"{base_dir}_test_gage_files" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) mnam = "gage_test_files" - m = flopy.modflow.Modflow(modelname=mnam, model_ws=cpth) + m = flopy.modflow.Modflow(modelname=mnam, model_ws=model_ws) dis = flopy.modflow.ModflowDis(m) spd = { (0, 0): ["print head"], @@ -120,7 +122,7 @@ def test_gage_files(): m.write_input() # check that the gage output file entries are in the name file - fpth = os.path.join(cpth, f"{mnam}.nam") + fpth = os.path.join(model_ws, f"{mnam}.nam") entries = get_namefile_entries(fpth) for idx, f in enumerate(files): found = False @@ -142,10 +144,12 @@ def test_gage_files(): def test_gage_filenames0(): + model_ws = f"{base_dir}_test_gage_filenames0" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) mnam = "gage_test_filenames0" - m = flopy.modflow.Modflow(modelname=mnam, model_ws=cpth) + m = flopy.modflow.Modflow(modelname=mnam, model_ws=model_ws) dis = flopy.modflow.ModflowDis(m) spd = { (0, 0): ["print head"], @@ -169,7 +173,7 @@ def test_gage_filenames0(): m.write_input() # check that the gage output units entries are in the name file - fpth = os.path.join(cpth, f"{mnam}.nam") + fpth = os.path.join(model_ws, f"{mnam}.nam") entries = get_namefile_entries(fpth) for idx, g in enumerate(gages): if g[0] < 0: @@ -189,10 +193,12 @@ def test_gage_filenames0(): def test_gage_filenames(): + model_ws = f"{base_dir}_test_gage_filenames" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) mnam = "gage_test_filenames" - m = flopy.modflow.Modflow(modelname=mnam, model_ws=cpth) + m = flopy.modflow.Modflow(modelname=mnam, model_ws=model_ws) dis = flopy.modflow.ModflowDis(m) spd = { (0, 0): ["print head"], @@ -216,7 +222,7 @@ def test_gage_filenames(): m.write_input() # check that the gage output file entries are in the name file - fpth = os.path.join(cpth, f"{mnam}.nam") + fpth = os.path.join(model_ws, f"{mnam}.nam") entries = get_namefile_entries(fpth) for idx, f in enumerate(filenames[1:]): found = False diff --git a/autotest/t049_test.py b/autotest/t049_test.py index 511579f031..0dfe08f1b2 100644 --- a/autotest/t049_test.py +++ b/autotest/t049_test.py @@ -1,19 +1,11 @@ # Test loading of MODFLOW and MT3D models that come with MT3D distribution import os -import flopy import numpy as np import matplotlib.pyplot as plt +import flopy +from ci_framework import base_test_dir, FlopyTestSetup -try: - import pymake -except ImportError: - print("could not import pymake") - pymake = False - -cpth = os.path.join("temp", "t049") -# make the directory if it does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) mf2005_exe = "mf2005" v = flopy.which(mf2005_exe) @@ -27,17 +19,22 @@ def test_modpath(): + model_ws = f"{base_dir}_test_modpath" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + pth = os.path.join("..", "examples", "data", "freyberg") mfnam = "freyberg.nam" - lpth = os.path.join(cpth, "test_mp") - m = flopy.modflow.Modflow.load( - mfnam, model_ws=pth, verbose=True, exe_name=mf2005_exe + mfnam, + model_ws=pth, + verbose=True, + exe_name=mf2005_exe, + check=False, ) assert m.load_fail is False - m.change_model_ws(lpth) + m.change_model_ws(model_ws) m.write_input() if run: @@ -47,7 +44,10 @@ def test_modpath(): # create the forward modpath file mpnam = "freybergmp" mp = flopy.modpath.Modpath6( - mpnam, exe_name=mpth_exe, modflowmodel=m, model_ws=lpth + mpnam, + exe_name=mpth_exe, + modflowmodel=m, + model_ws=model_ws, ) mpbas = flopy.modpath.Modpath6Bas( mp, @@ -72,7 +72,10 @@ def test_modpath(): mpnam = "freybergmpp" mpp = flopy.modpath.Modpath6( - mpnam, exe_name=mpth_exe, modflowmodel=m, model_ws=lpth + mpnam, + exe_name=mpth_exe, + modflowmodel=m, + model_ws=model_ws, ) mpbas = flopy.modpath.Modpath6Bas( mpp, @@ -97,8 +100,8 @@ def test_modpath(): # load modpath output files if run and success: - endfile = os.path.join(lpth, mp.sim.endpoint_file) - pthfile = os.path.join(lpth, mpp.sim.pathline_file) + endfile = os.path.join(model_ws, mp.sim.endpoint_file) + pthfile = os.path.join(model_ws, mpp.sim.pathline_file) # load the endpoint data try: @@ -118,7 +121,7 @@ def test_modpath(): len(plines) == 576 ), "there are not 576 particle pathlines in file" - eval_pathline_plot(lpth) + eval_pathline_plot(model_ws) return @@ -185,13 +188,16 @@ def eval_pathline_plot(lpth): def test_pathline_plot_xc(): from matplotlib.collections import LineCollection + model_ws = f"{base_dir}_test_pathline_plot_xc" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + # test with multi-layer example - model_ws = os.path.join("..", "examples", "data", "mp6") + load_ws = os.path.join("..", "examples", "data", "mp6") ml = flopy.modflow.Modflow.load( - "EXAMPLE.nam", model_ws=model_ws, exe_name=mf2005_exe + "EXAMPLE.nam", model_ws=load_ws, exe_name=mf2005_exe ) - ml.change_model_ws(os.path.join(".", "temp")) + ml.change_model_ws(model_ws) ml.write_input() ml.run_model() @@ -199,7 +205,7 @@ def test_pathline_plot_xc(): modelname="ex6", exe_name=mpth_exe, modflowmodel=ml, - model_ws=os.path.join(".", "temp"), + model_ws=model_ws, dis_file=f"{ml.name}.DIS", head_file=f"{ml.name}.hed", budget_file=f"{ml.name}.bud", @@ -219,7 +225,7 @@ def test_pathline_plot_xc(): mp.run_model(silent=False) - pthobj = flopy.utils.PathlineFile(os.path.join("temp", "ex6.mppth")) + pthobj = flopy.utils.PathlineFile(os.path.join(model_ws, "ex6.mppth")) well_pathlines = pthobj.get_destination_pathline_data( dest_cells=[(4, 12, 12)] ) @@ -238,11 +244,18 @@ def test_pathline_plot_xc(): def test_mp5_load(): + model_ws = f"{base_dir}_test_mf5_load" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + # load the base freyberg model - pth = os.path.join("..", "examples", "data", "freyberg") + load_ws = os.path.join("..", "examples", "data", "freyberg") # load the modflow files for model map m = flopy.modflow.Modflow.load( - "freyberg.nam", model_ws=pth, check=False, verbose=True, forgive=False + "freyberg.nam", + model_ws=load_ws, + check=False, + verbose=True, + forgive=False, ) # load the pathline data @@ -296,7 +309,7 @@ def test_mp5_load(): assert False, "could not plot grid and ibound" try: - fpth = os.path.join(cpth, "mp5.pathline.png") + fpth = os.path.join(model_ws, "mp5.pathline.png") plt.savefig(fpth, dpi=300) plt.close() except: @@ -415,8 +428,8 @@ def eval_timeseries(file): if __name__ == "__main__": - test_modpath() test_pathline_plot_xc() + test_modpath() test_mp5_load() test_mp5_timeseries_load() test_mp6_timeseries_load() diff --git a/autotest/t051_test.py b/autotest/t051_test.py index f4f9f017d9..806cb5d30d 100644 --- a/autotest/t051_test.py +++ b/autotest/t051_test.py @@ -1,15 +1,16 @@ import os import numpy as np import flopy +from ci_framework import base_test_dir, FlopyTestSetup -cpth = os.path.join("temp", "t051") -# make the directory if it does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) def test_default_oc_stress_period_data(): - m = flopy.modflow.Modflow(model_ws=cpth, verbose=True) + model_ws = f"{base_dir}_test_default_oc_stress_period_data" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + + m = flopy.modflow.Modflow(model_ws=model_ws, verbose=True) dis = flopy.modflow.ModflowDis(m, nper=10, perlen=10.0, nstp=5) bas = flopy.modflow.ModflowBas(m) lpf = flopy.modflow.ModflowLpf(m, ipakcb=100) @@ -28,7 +29,10 @@ def test_default_oc_stress_period_data(): def test_mfcbc(): - m = flopy.modflow.Modflow(verbose=True) + model_ws = f"{base_dir}_test_mfcbc" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + + m = flopy.modflow.Modflow(verbose=True, model_ws=model_ws) dis = flopy.modflow.ModflowDis(m) bas = flopy.modflow.ModflowBas(m) lpf = flopy.modflow.ModflowLpf(m, ipakcb=100) @@ -42,7 +46,7 @@ def test_mfcbc(): nlay = 3 nrow = 3 ncol = 3 - ml = flopy.modflow.Modflow(modelname="t1", model_ws=cpth, verbose=True) + ml = flopy.modflow.Modflow(modelname="t1", model_ws=model_ws, verbose=True) dis = flopy.modflow.ModflowDis( ml, nlay=nlay, nrow=nrow, ncol=ncol, top=0, botm=[-1.0, -2.0, -3.0] ) @@ -67,5 +71,5 @@ def test_mfcbc(): if __name__ == "__main__": - # test_mfcbc() + test_mfcbc() test_default_oc_stress_period_data() diff --git a/autotest/t052_test.py b/autotest/t052_test.py index a85310bac6..4516cdd968 100644 --- a/autotest/t052_test.py +++ b/autotest/t052_test.py @@ -1,17 +1,10 @@ import os import numpy as np import flopy +import pymake +from ci_framework import base_test_dir, FlopyTestSetup -try: - import pymake -except: - print("could not import pymake") - - -cpth = os.path.join("temp", "t052") -# make the directory if it does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) exe_name = "mf2005" v = flopy.which(exe_name) @@ -22,13 +15,18 @@ def test_binary_well(): + model_ws = f"{base_dir}_test_binary_well" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) nlay = 3 nrow = 3 ncol = 3 mfnam = "t1" ml = flopy.modflow.Modflow( - modelname=mfnam, model_ws=cpth, verbose=True, exe_name=exe_name + modelname=mfnam, + model_ws=model_ws, + verbose=True, + exe_name=exe_name, ) dis = flopy.modflow.ModflowDis( ml, nlay=nlay, nrow=nrow, ncol=ncol, top=0, botm=[-1.0, -2.0, -3.0] @@ -64,11 +62,14 @@ def test_binary_well(): if run: success, buff = ml.run_model(silent=False) assert success, "could not run MODFLOW-2005 model" - fn0 = os.path.join(cpth, f"{mfnam}.nam") + fn0 = os.path.join(model_ws, f"{mfnam}.nam") # load the model m = flopy.modflow.Modflow.load( - f"{mfnam}.nam", model_ws=cpth, verbose=True, exe_name=exe_name + f"{mfnam}.nam", + model_ws=model_ws, + verbose=True, + exe_name=exe_name, ) wl = m.wel.stress_period_data[0] @@ -79,7 +80,7 @@ def test_binary_well(): assert np.array_equal(wel.stress_period_data[0], wl), msg # change model work space - pth = os.path.join(cpth, "flopy") + pth = os.path.join(model_ws, "flopy") m.change_model_ws(new_pth=pth) # remove the existing well package @@ -101,7 +102,7 @@ def test_binary_well(): # compare the files if run: - fsum = os.path.join(cpth, f"{os.path.splitext(mfnam)[0]}.head.out") + fsum = os.path.join(model_ws, f"{os.path.splitext(mfnam)[0]}.head.out") success = False try: success = pymake.compare_heads(fn0, fn1, outfile=fsum) @@ -110,7 +111,9 @@ def test_binary_well(): assert success, "head comparison failure" - fsum = os.path.join(cpth, f"{os.path.splitext(mfnam)[0]}.budget.out") + fsum = os.path.join( + model_ws, f"{os.path.splitext(mfnam)[0]}.budget.out" + ) success = False try: success = pymake.compare_budget( diff --git a/autotest/t053_test.py b/autotest/t053_test.py index a336213258..a6d2db8951 100644 --- a/autotest/t053_test.py +++ b/autotest/t053_test.py @@ -4,11 +4,6 @@ import numpy as np import flopy -tpth = os.path.join("temp", "t053") -# make the directory if it does not exist -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) - def test_headu_file(): fname = os.path.join( diff --git a/autotest/t054_test_mfnwt.py b/autotest/t054_test_mfnwt.py index a77a683238..093b55f7a0 100644 --- a/autotest/t054_test_mfnwt.py +++ b/autotest/t054_test_mfnwt.py @@ -8,11 +8,9 @@ import flopy import pymake import pytest +from ci_framework import base_test_dir, FlopyTestSetup -# make the working directory -tpth = os.path.join("temp", "t054") -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) # build list of name files to try and load nwtpth = os.path.join("..", "examples", "data", "mf2005_test") @@ -58,11 +56,15 @@ def test_mfnwt_model(fnwt): # function to load a MODFLOW-2005 model, convert to a MFNWT model, # write it back out, run the MFNWT model, load the MFNWT model, # and compare the results. -def mfnwt_model(namfile, model_ws): +def mfnwt_model(namfile, load_ws): + base_name = os.path.splitext(namfile)[0] + model_ws = f"{base_dir}_{base_name}" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + # load MODFLOW-2005 models as MODFLOW-NWT models m = flopy.modflow.Modflow.load( namfile, - model_ws=model_ws, + model_ws=load_ws, version="mfnwt", verbose=True, check=False, @@ -122,9 +124,7 @@ def mfnwt_model(namfile, model_ws): wel.iunitramp = 2 # change workspace and write MODFLOW-NWT model - tdir = os.path.splitext(namfile)[0] - pth = os.path.join(tpth, tdir) - m.change_model_ws(pth) + m.change_model_ws(model_ws) m.write_input() if run: try: @@ -132,12 +132,12 @@ def mfnwt_model(namfile, model_ws): except: success = False assert success, "base model run did not terminate successfully" - fn0 = os.path.join(pth, namfile) + fn0 = os.path.join(model_ws, namfile) # reload the model just written m = flopy.modflow.Modflow.load( namfile, - model_ws=pth, + model_ws=model_ws, version="mfnwt", verbose=True, check=False, @@ -147,7 +147,7 @@ def mfnwt_model(namfile, model_ws): assert m.load_fail is False # change workspace and write MODFLOW-NWT model - pthf = os.path.join(pth, "flopy") + pthf = os.path.join(model_ws, "flopy") m.change_model_ws(pthf) m.write_input() if run: @@ -159,7 +159,7 @@ def mfnwt_model(namfile, model_ws): fn1 = os.path.join(pthf, namfile) if run: - fsum = os.path.join(pth, f"{tdir}.head.out") + fsum = os.path.join(model_ws, f"{base_name}.head.out") success = False try: success = pymake.compare_heads(fn0, fn1, outfile=fsum) @@ -169,7 +169,7 @@ def mfnwt_model(namfile, model_ws): assert success, "head comparison failure" - fsum = os.path.join(pth, f"{tdir}.budget.out") + fsum = os.path.join(model_ws, f"{base_name}.budget.out") success = False try: success = pymake.compare_budget( diff --git a/autotest/t056_test_pcg_fmt.py b/autotest/t056_test_pcg_fmt.py index 0e2cd44c53..8b2fad512e 100644 --- a/autotest/t056_test_pcg_fmt.py +++ b/autotest/t056_test_pcg_fmt.py @@ -15,7 +15,7 @@ ) -def pcg_fmt_test(): +def test_pcg_fmt(): # mf2k container - this will pass m2k = fp.modflow.Modflow(version="mf2k") m2k.pcg = fp.modflow.ModflowPcg.load(model=m2k, f=pcg_fname) @@ -32,4 +32,4 @@ def pcg_fmt_test(): if __name__ == "__main__": - pcg_fmt_test() + test_pcg_fmt() diff --git a/autotest/t057_test_mp7.py b/autotest/t057_test_mp7.py index fa3db59312..ad3e794b72 100644 --- a/autotest/t057_test_mp7.py +++ b/autotest/t057_test_mp7.py @@ -1,11 +1,9 @@ import os import numpy as np import flopy +from ci_framework import base_test_dir, FlopyTestSetup -model_ws = os.path.join("temp", "t057") -# make the directory if it does not exist -if not os.path.isdir(model_ws): - os.makedirs(model_ws, exist_ok=True) +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) exe_names = {"mf2005": "mf2005", "mf6": "mf6", "mp7": "mp7"} run = True @@ -43,26 +41,12 @@ part0 = flopy.modpath.ParticleData( partlocs, structured=True, particleids=partids ) -# part0 = flopy.modpath.ParticleGroup.get_particledata_empty(ncells=21, -# particleid=True) -# part0['k'] = 0 -# part0['j'] = 2 -# part0['localx'] = 0.5 -# part0['localy'] = 0.5 -# part0['localz'] = 0. -# part0['timeoffset'] = 0. -# part0['drape'] = 0 -# for idx in range(part0.shape[0]): -# part0['id'][idx] = idx -# part0['i'][idx] = idx pg0 = flopy.modpath.ParticleGroup( particlegroupname="PG1", particledata=part0, filename="ex01a.sloc" ) v = [(0,), (400,)] pids = [1, 2] # [1000, 1001] -# part1 = flopy.modpath.ParticleGroup.create_particledata(v, drape=1, -# particleids=pids) part1 = flopy.modpath.ParticleData( v, structured=False, drape=1, particleids=pids ) @@ -76,17 +60,13 @@ defaultiface6 = {"RCH": 6, "EVT": 6} -def test_mf2005(): - # build and run MODPATH 7 with MODFLOW-2005 - build_mf2005() - - -def test_mf6(): - # build and run MODPATH 7 with MODFLOW 6 - build_mf6() - - def test_pathline_output(): + model_ws = f"{base_dir}_test_pathline_output" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + + # build and run the models + build_mf2005(model_ws) + build_mf6(model_ws) # if models not run then there will be no output if not run: @@ -103,14 +83,6 @@ def test_pathline_output(): maxid1 = p.get_maxid() p1 = p.get_alldata() - # # check maxtimes - # msg = 'pathline maxtime ({}) '.format(maxtime0) + \ - # 'in {} '.format(os.path.basename(fpth0)) + \ - # 'are not equal to the ' + \ - # 'pathline maxtime ({}) '.format(maxtime1) + \ - # 'in {}'.format(os.path.basename(fpth1)) - # assert maxtime0 == maxtime1, msg - # check maxid msg = ( f"pathline maxid ({maxid0}) in {os.path.basename(fpth0)} are not " @@ -118,24 +90,16 @@ def test_pathline_output(): ) assert maxid0 == maxid1, msg - # check that pathline data are approximately the same - # names = ['x', 'y', 'z'] - # dtype = np.dtype([('x', np.float32), ('y', np.float32), - # ('z', np.float32)]) - # for jdx, (pl0, pl1) in enumerate(zip(p0, p1)): - # t0 = np.rec.fromarrays((pl0[name] for name in names), dtype=dtype) - # t1 = np.rec.fromarrays((pl1[name] for name in names), dtype=dtype) - # for name in names: - # msg = 'pathline {} in {} '.format(jdx, os.path.basename(fpth0)) + \ - # 'are not equal (within 1e-5) to the ' + \ - # 'pathline {} in {} '.format(jdx, os.path.basename(fpth1)) + \ - # 'for column {}.'.format(name) - # assert np.allclose(t0[name], t1[name]), msg - return def test_endpoint_output(): + model_ws = f"{base_dir}_test_endpoint_output" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + + # build and run the models + build_mf2005(model_ws) + build_mf6(model_ws) # if models not run then there will be no output if not run: @@ -161,22 +125,6 @@ def test_endpoint_output(): ) assert maxid0 == maxid1, msg - # # check maxtravel - # msg = 'endpoint maxtraveltime ({}) '.format(maxtravel0) + \ - # 'in {} '.format(os.path.basename(fpth0)) + \ - # 'are not equal to the ' + \ - # 'endpoint maxtraveltime ({}) '.format(maxtravel1) + \ - # 'in {}'.format(os.path.basename(fpth1)) - # assert e0 != e1, msg - # - # # check maxtimes - # msg = 'endpoint maxtime ({}) '.format(maxtime0) + \ - # 'in {} '.format(os.path.basename(fpth0)) + \ - # 'are not equal to the ' + \ - # 'endpoint maxtime ({}) '.format(maxtime1) + \ - # 'in {}'.format(os.path.basename(fpth1)) - # assert e0 != e1, msg - # check that endpoint data are approximately the same names = ["x", "y", "z", "x0", "y0", "z0"] dtype = np.dtype( @@ -199,7 +147,7 @@ def test_endpoint_output(): return -def build_mf2005(): +def build_mf2005(model_ws): """ MODPATH 7 example 1 for MODFLOW-2005 """ @@ -289,7 +237,7 @@ def build_mf2005(): return -def build_mf6(): +def build_mf6(model_ws): """ MODPATH 7 example 1 for MODFLOW 6 """ @@ -419,7 +367,5 @@ def build_mf6(): if __name__ == "__main__": - test_mf2005() - test_mf6() test_pathline_output() test_endpoint_output() diff --git a/autotest/t059_test_mp7.py b/autotest/t059_test_mp7.py index 30c50160a5..77d19a6963 100644 --- a/autotest/t059_test_mp7.py +++ b/autotest/t059_test_mp7.py @@ -1,10 +1,8 @@ import os import flopy +from ci_framework import base_test_dir, FlopyTestSetup -model_ws = os.path.join("temp", "t059") -# make the directory if it does not exist -if not os.path.isdir(model_ws): - os.makedirs(model_ws, exist_ok=True) +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) exe_names = {"mf6": "mf6", "mp7": "mp7"} run = True @@ -14,7 +12,6 @@ run = False break -ws = model_ws nm = "ex01_mf6" # model data @@ -34,17 +31,16 @@ riv_c = 1.0e5 -def test_mf6(): - # build and run MODPATH 7 with MODFLOW 6 - build_mf6() - - def test_forward(): + model_ws = f"{base_dir}_test_forward" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_forward" exe_name = exe_names["mp7"] # load the MODFLOW 6 model - sim = flopy.mf6.MFSimulation.load("mf6mod", "mf6", "mf6", ws) + sim = flopy.mf6.MFSimulation.load("mf6mod", "mf6", "mf6", model_ws) gwf = sim.get_model(nm) mp = flopy.modpath.Modpath7.create_mp7( @@ -64,11 +60,15 @@ def test_forward(): def test_backward(): + model_ws = f"{base_dir}_test_backward" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + build_mf6(model_ws) + mpnam = f"{nm}_mp_backward" exe_name = exe_names["mp7"] # load the MODFLOW 6 model - sim = flopy.mf6.MFSimulation.load("mf6mod", "mf6", "mf6", ws) + sim = flopy.mf6.MFSimulation.load("mf6mod", "mf6", "mf6", model_ws) gwf = sim.get_model(nm) mp = flopy.modpath.Modpath7.create_mp7( @@ -87,7 +87,7 @@ def test_backward(): return -def build_mf6(): +def build_mf6(model_ws): """ MODPATH 7 example 1 for MODFLOW 6 """ @@ -96,7 +96,10 @@ def build_mf6(): # Create the Flopy simulation object sim = flopy.mf6.MFSimulation( - sim_name=nm, exe_name="mf6", version="mf6", sim_ws=ws + sim_name=nm, + exe_name="mf6", + version="mf6", + sim_ws=model_ws, ) # Create the Flopy temporal discretization object diff --git a/autotest/t060_test_lkt.py b/autotest/t060_test_lkt.py index 8fb088f189..f1e8107eed 100644 --- a/autotest/t060_test_lkt.py +++ b/autotest/t060_test_lkt.py @@ -3,15 +3,11 @@ """ import os -import sys -import platform import numpy as np import flopy +from ci_framework import base_test_dir, FlopyTestSetup -# make the working directory -tpth = os.path.join("temp", "t060") -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) mfnwt_exe = "mfnwt" mt3d_usgs_exe = "mt3dusgs" @@ -20,14 +16,19 @@ def test_lkt_with_multispecies(): - modelpth = tpth + model_ws = f"{base_dir}_test_gage_load_and_write" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + modelname = "lkttest" mfexe = "mfnwt" mtexe = "mt3dusgs" # Instantiate MODFLOW object in flopy mf = flopy.modflow.Modflow( - modelname=modelname, exe_name=mfexe, model_ws=modelpth, version="mfnwt" + modelname=modelname, + exe_name=mfexe, + model_ws=model_ws, + version="mfnwt", ) Lx = 27500.0 @@ -17206,7 +17207,7 @@ def test_lkt_with_multispecies(): mt = flopy.mt3d.Mt3dms( modflowmodel=mf, modelname=modelname, - model_ws=modelpth, + model_ws=model_ws, version="mt3d-usgs", namefile_ext="mtnam", exe_name=mtexe, @@ -17327,7 +17328,7 @@ def test_lkt_with_multispecies(): namfile = f"{modelname}.nam" mf = flopy.modflow.Modflow.load( namfile, - model_ws=tpth, + model_ws=model_ws, version="mfnwt", verbose=True, exe_name=mfnwt_exe, @@ -17335,7 +17336,7 @@ def test_lkt_with_multispecies(): namfile = f"{modelname}.mtnam" mt = flopy.mt3d.mt.Mt3dms.load( namfile, - model_ws=tpth, + model_ws=model_ws, verbose=True, version="mt3d-usgs", exe_name=mt3d_usgs_exe, diff --git a/autotest/t061_test_gridgen.py b/autotest/t061_test_gridgen.py index 46fd9de0f1..432ad05f31 100644 --- a/autotest/t061_test_gridgen.py +++ b/autotest/t061_test_gridgen.py @@ -11,10 +11,9 @@ except ImportError: shapefile = None -cpth = os.path.join("temp", "t061") -# make the directory if it does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) +from ci_framework import base_test_dir, FlopyTestSetup + +base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) exe_name = "gridgen" v = flopy.which(exe_name) @@ -25,6 +24,8 @@ def test_gridgen(): + model_ws = f"{base_dir}_test_gridgen" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) # define the base grid and then create a couple levels of nested # refinement @@ -64,7 +65,10 @@ def test_gridgen(): botm=botm, ) - ms_u = flopy.mfusg.MfUsg(modelname="mymfusgmodel", model_ws=cpth) + ms_u = flopy.mfusg.MfUsg( + modelname="mymfusgmodel", + model_ws=model_ws, + ) dis_usg = flopy.modflow.ModflowDis( ms_u, nlay=nlay, @@ -76,7 +80,7 @@ def test_gridgen(): botm=botm, ) - gridgen_ws = cpth + gridgen_ws = model_ws g = Gridgen(dis5, model_ws=gridgen_ws, exe_name=exe_name) g6 = Gridgen(dis6, model_ws=gridgen_ws, exe_name=exe_name) gu = Gridgen( diff --git a/autotest/t063_test_lgrutil.py b/autotest/t063_test_lgrutil.py index 4c90ae295d..4adaec5965 100644 --- a/autotest/t063_test_lgrutil.py +++ b/autotest/t063_test_lgrutil.py @@ -1,15 +1,8 @@ import os import numpy as np -import flopy from flopy.utils.lgrutil import Lgr -tpth = os.path.join("temp", "t063") -# make the directory if it does not exist -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) - - def test_lgrutil(): nlayp = 5 nrowp = 5