|
| 1 | +import sys |
1 | 2 | from datetime import datetime |
2 | 3 | from shutil import copyfile |
3 | 4 | from textwrap import dedent |
|
13 | 14 | parametrize_with_cases, |
14 | 15 | ) |
15 | 16 |
|
16 | | -from imod.formats.prj import open_projectfile_data |
| 17 | +from imod.formats.prj import open_projectfile_data, read_projectfile |
| 18 | +from imod.logging import LoggerType, LogLevel, configure |
17 | 19 | from imod.mf6 import LayeredWell, Well |
18 | 20 |
|
19 | 21 |
|
@@ -946,3 +948,47 @@ def test_from_imod5_data_wells__wells_out_of_bounds( |
946 | 948 | expected_last_rate = data[wellname]["dataframe"][0]["rate"].iloc[-2] |
947 | 949 | actual_last_rate = well.dataset["rate"].isel(index=1, time=-1).item() |
948 | 950 | assert actual_last_rate == expected_last_rate |
| 951 | + |
| 952 | + |
| 953 | +@pytest.mark.unittest_jit |
| 954 | +@parametrize("wel_case", argvalues=PRJ_ARGS) |
| 955 | +@parametrize("wel_cls", argvalues=[LayeredWell, Well]) |
| 956 | +def test_from_imod5_data_wells__empty_wells( |
| 957 | + wel_cls: Union[LayeredWell, Well], |
| 958 | + wel_case, |
| 959 | + well_empty_ipfs, |
| 960 | + tmp_path, |
| 961 | + request, |
| 962 | +): |
| 963 | + # Arrange |
| 964 | + # Replace layer number to zero if non-layered well. |
| 965 | + if wel_cls == Well: |
| 966 | + wel_case = wel_case.replace("1,2, 001", "1,2, 000") |
| 967 | + # Write prj and copy ipfs to right folder. |
| 968 | + case_name = get_case_name(request) |
| 969 | + wel_file = tmp_path / f"{case_name}.prj" |
| 970 | + setup_test_files(wel_case, wel_file, well_empty_ipfs, tmp_path) |
| 971 | + |
| 972 | + projectfile_contents = read_projectfile(wel_file) |
| 973 | + |
| 974 | + # Act |
| 975 | + logfile_path = tmp_path / "logfile.txt" |
| 976 | + with open(logfile_path, "w") as sys.stdout: |
| 977 | + configure( |
| 978 | + LoggerType.LOGURU, |
| 979 | + log_level=LogLevel.WARNING, |
| 980 | + add_default_file_handler=False, |
| 981 | + add_default_stream_handler=True, |
| 982 | + ) |
| 983 | + data, _ = open_projectfile_data(wel_file) |
| 984 | + |
| 985 | + with open(logfile_path, "r") as f: |
| 986 | + log = f.read() |
| 987 | + |
| 988 | + # Assert |
| 989 | + # Projectfile only contains empty wells, so expect empty data. |
| 990 | + assert len(data) == 0 |
| 991 | + # Expect warning about empty wells. |
| 992 | + for ipf_contents in projectfile_contents["(wel)"]["ipf"]: |
| 993 | + ipf_path = ipf_contents["path"] |
| 994 | + assert f"IPF file {ipf_path} contains no data. Skipping." in log |
0 commit comments