Skip to content

Commit

Permalink
Catch a possible error in STATUS files
Browse files Browse the repository at this point in the history
Instead of crashing, we should ignore the line in a garbled STATUS file
like we do for other ways it can be garbled.
  • Loading branch information
berland committed Aug 23, 2024
1 parent 71b2dc7 commit 0b1f308
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/fmu/ensemble/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ def load_status(self):
# We get where if STARTIME.split(':') does not contain
# integers only:
durations.append(np.nan)
except IndexError:
# We get here if a clock time string is invalid, like missing seconds.
print("got indexerror")
durations.append(np.nan)
status["DURATION"] = durations

# Augment data from jobs.json if that file is available:
Expand Down
15 changes: 6 additions & 9 deletions tests/test_realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,15 @@ def test_status_load(tmpdir):
assert status["DURATION"].values[0] == 0 # in seconds
# NB: The current code is not able to pick this error string

with open(str(tmpdir.join("realization-0/STATUS")), "w") as status_fh:
status_fh.write("first line always ignored\n")
status_fh.write("INCLUDE_PC : 12:XX:55 .... 12:40:55 \n")
real = ensemble.ScratchRealization(str(tmpdir.join("realization-0")))
status = real.get_df("STATUS")
assert len(status) == 1
assert "FORWARD_MODEL" in status
assert np.isnan(status["DURATION"].values[0])

@pytest.mark.parametrize(
"timeinfo", ["12:XX:55 .... 12:40:55", "12:40 .... 12:40:55", "12:40:33 .... 12:41"]
)
def test_status_load_wrong_time_syntax(tmpdir, timeinfo: str):
tmpdir.join("realization-0").mkdir()
with open(str(tmpdir.join("realization-0/STATUS")), "w") as status_fh:
status_fh.write("first line always ignored\n")
status_fh.write("INCLUDE_PC : 12:40.... 12:40:55 \n")
status_fh.write(f"INCLUDE_PC :  {timeinfo} \n")
real = ensemble.ScratchRealization(str(tmpdir.join("realization-0")))
status = real.get_df("STATUS")
assert len(status) == 1
Expand Down

0 comments on commit 0b1f308

Please sign in to comment.