"""
Try to load all of the MODFLOW-USG examples in ../examples/data/mfusg_test.
These are the examples that are distributed with MODFLOW-USG.
"""

import os
import flopy

# make the working directory
tpth = os.path.join("temp", "t038")
if not os.path.isdir(tpth):
    os.makedirs(tpth)

# build list of name files to try and load
usgpth = os.path.join("..", "examples", "data", "mfusg_test")
usg_files = []
for path, subdirs, files in os.walk(usgpth):
    for name in files:
        if name.endswith(".nam"):
            usg_files.append(os.path.join(path, name))

#
def test_load_usg():
    for fusg in usg_files:
        d, f = os.path.split(fusg)
        yield load_model, f, d


# function to load a MODFLOW-USG model and then write it back out
def load_model(namfile, model_ws):
    m = flopy.modflow.Modflow.load(
        namfile, model_ws=model_ws, version="mfusg", verbose=True, check=False
    )
    assert m, f"Could not load namefile {namfile}"
    assert m.load_fail is False
    m.change_model_ws(tpth)
    m.write_input()
    return


if __name__ == "__main__":
    for fusg in usg_files:
        d, f = os.path.split(fusg)
        load_model(f, d)

[((207, 235), 'os.path.join', 'os.path.join', (['"""temp"""', '"""t038"""'], {}), "('temp', 't038')\n", (219, 235), False, 'import os\n'), ((339, 391), 'os.path.join', 'os.path.join', (['""".."""', '"""examples"""', '"""data"""', '"""mfusg_test"""'], {}), "('..', 'examples', 'data', 'mfusg_test')\n", (351, 391), False, 'import os\n'), ((435, 450), 'os.walk', 'os.walk', (['usgpth'], {}), '(usgpth)\n', (442, 450), False, 'import os\n'), ((243, 262), 'os.path.isdir', 'os.path.isdir', (['tpth'], {}), '(tpth)\n', (256, 262), False, 'import os\n'), ((268, 285), 'os.makedirs', 'os.makedirs', (['tpth'], {}), '(tpth)\n', (279, 285), False, 'import os\n'), ((792, 894), 'flopy.modflow.Modflow.load', 'flopy.modflow.Modflow.load', (['namfile'], {'model_ws': 'model_ws', 'version': '"""mfusg"""', 'verbose': '(True)', 'check': '(False)'}), "(namfile, model_ws=model_ws, version='mfusg',\n    verbose=True, check=False)\n", (818, 894), False, 'import flopy\n'), ((630, 649), 'os.path.split', 'os.path.split', (['fusg'], {}), '(fusg)\n', (643, 649), False, 'import os\n'), ((1118, 1137), 'os.path.split', 'os.path.split', (['fusg'], {}), '(fusg)\n', (1131, 1137), False, 'import os\n'), ((538, 562), 'os.path.join', 'os.path.join', (['path', 'name'], {}), '(path, name)\n', (550, 562), False, 'import os\n')]