"""
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)

[((10, 7, 10, 35), 'os.path.join', 'os.path.join', ({(10, 20, 10, 26): '"""temp"""', (10, 28, 10, 34): '"""t038"""'}, {}), "('temp', 't038')", False, 'import os\n'), ((15, 9, 15, 61), 'os.path.join', 'os.path.join', ({(15, 22, 15, 26): '""".."""', (15, 28, 15, 38): '"""examples"""', (15, 40, 15, 46): '"""data"""', (15, 48, 15, 60): '"""mfusg_test"""'}, {}), "('..', 'examples', 'data', 'mfusg_test')", False, 'import os\n'), ((17, 28, 17, 43), 'os.walk', 'os.walk', ({(17, 36, 17, 42): 'usgpth'}, {}), '(usgpth)', False, 'import os\n'), ((11, 7, 11, 26), 'os.path.isdir', 'os.path.isdir', ({(11, 21, 11, 25): 'tpth'}, {}), '(tpth)', False, 'import os\n'), ((12, 4, 12, 21), 'os.makedirs', 'os.makedirs', ({(12, 16, 12, 20): 'tpth'}, {}), '(tpth)', False, 'import os\n'), ((31, 8, 33, 5), 'flopy.modflow.Modflow.load', 'flopy.modflow.Modflow.load', (), '', False, 'import flopy\n'), ((25, 15, 25, 34), 'os.path.split', 'os.path.split', ({(25, 29, 25, 33): 'fusg'}, {}), '(fusg)', False, 'import os\n'), ((43, 15, 43, 34), 'os.path.split', 'os.path.split', ({(43, 29, 43, 33): 'fusg'}, {}), '(fusg)', False, 'import os\n'), ((20, 29, 20, 53), 'os.path.join', 'os.path.join', ({(20, 42, 20, 46): 'path', (20, 48, 20, 52): 'name'}, {}), '(path, name)', False, 'import os\n')]