|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import flopy |
1 | 4 | from lark import Lark |
2 | 5 |
|
3 | | -from flopy4.mf6.gwf.oc import Oc |
4 | | -from flopy4.mf6.io import make_parser |
| 6 | +from flopy4.mf6 import Tdis |
| 7 | +from flopy4.mf6.io import MF6Transformer, make_parser |
5 | 8 |
|
6 | 9 |
|
7 | 10 | def test_make_parser(): |
8 | | - parser = make_parser(Oc) |
| 11 | + parser = make_parser(Tdis) |
9 | 12 | assert isinstance(parser, Lark) |
| 13 | + |
| 14 | + |
| 15 | +def readme_example(name: str, workspace: Path) -> flopy.mf6.MFSimulation: |
| 16 | + sim = flopy.mf6.MFSimulation( |
| 17 | + sim_name=name, sim_ws=workspace, exe_name="mf6" |
| 18 | + ) |
| 19 | + tdis = flopy.mf6.ModflowTdis(sim) |
| 20 | + ims = flopy.mf6.ModflowIms(sim) |
| 21 | + gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True) |
| 22 | + dis = flopy.mf6.ModflowGwfdis(gwf, nrow=10, ncol=10) |
| 23 | + ic = flopy.mf6.ModflowGwfic(gwf) |
| 24 | + npf = flopy.mf6.ModflowGwfnpf(gwf, save_specific_discharge=True) |
| 25 | + chd = flopy.mf6.ModflowGwfchd( |
| 26 | + gwf, stress_period_data=[[(0, 0, 0), 1.0], [(0, 9, 9), 0.0]] |
| 27 | + ) |
| 28 | + budget_file = name + ".bud" |
| 29 | + head_file = name + ".hds" |
| 30 | + oc = flopy.mf6.ModflowGwfoc( |
| 31 | + gwf, |
| 32 | + budget_filerecord=budget_file, |
| 33 | + head_filerecord=head_file, |
| 34 | + saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], |
| 35 | + ) |
| 36 | + return sim |
| 37 | + |
| 38 | + |
| 39 | +def test_parse(tmp_path): |
| 40 | + sim = readme_example("test", Path(tmp_path)) |
| 41 | + sim.write_simulation() |
| 42 | + parser = make_parser(Tdis) |
| 43 | + transformer = MF6Transformer() |
| 44 | + with open(tmp_path / "test.tdis", "r") as f: |
| 45 | + tree = parser.parse(f.read()) |
| 46 | + data = transformer.transform(tree) |
0 commit comments