Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/subscript/fmuobs/fmuobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ def fmuobs(
starttime=starttime,
)
else:
dframe = ertobs2df(input_str, cwd=includedir)
dframe = ertobs2df(input_str, cwd=includedir, starttime=starttime)

if starttime:
dframe = compute_date_from_days(dframe)
dframe = compute_date_from_days(dframe, starttime=starttime)

if not validate_internal_dframe(dframe):
logger.error("Observation dataframe is invalid!")
Expand Down
49 changes: 49 additions & 0 deletions tests/test_fmuobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,55 @@ def test_integration():
assert subprocess.check_output(["fmuobs", "-h"])


@pytest.mark.integration
def test_startdate_argument(tmp_path, mocker, monkeypatch):
"""Test that the startdate argument is handled correctly"""
monkeypatch.chdir(tmp_path)
# Test that summary observations without a date are not valid without
# startdate argument
mocker.patch(
"sys.argv",
[
"fmuobs",
"--yml",
"output.yml",
str(
TESTDATA_DIR / "summary_obs_without_date.obs",
),
],
)
with pytest.raises(
ValueError, match=r"Can't have summary observation without a date"
):
main()
# Test that summary observations without a date are valid with startdate argument
start_date = "2020-01-01"
mocker.patch(
"sys.argv",
[
"fmuobs",
"--startdate",
start_date,
"--yml",
"output.yml",
str(
TESTDATA_DIR / "summary_obs_without_date.obs",
),
],
)
main()
assert Path("output.yml").exists()
# Test that the dates in the output are correctly calculated
# from the startdate and the days in the input
with open(Path("output.yml"), encoding="utf8") as stream:
config = yaml.safe_load(stream)
for smry in config["smry"]:
for obs in smry["observations"]:
assert pd.to_datetime(obs["date"]) == pd.to_datetime(
start_date
) + pd.to_timedelta(obs["days"], unit="D")


@pytest.mark.integration
@pytest.mark.parametrize("verbose", ["", "--verbose", "--debug"])
def test_commandline(tmp_path, verbose, mocker, caplog, monkeypatch):
Expand Down
28 changes: 28 additions & 0 deletions tests/testdata_fmuobs/summary_obs_without_date.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- These observations are modified from ert-doc.obs
-- and stripped down to demonstrate summary observations without dates

SUMMARY_OBSERVATION SEP_TEST_2005
{
VALUE = 100.0;
ERROR = 5;
DAYS = 135;
KEY = GOPR:BRENT;
};

SUMMARY_OBSERVATION SEP_TEST_2006
{
VALUE = 100.0;
ERROR = 5;
DAYS = 500;
KEY = GOPR:BRENT;
};

SUMMARY_OBSERVATION SEP_TEST_2008
{
VALUE = 213;
ERROR = 10;
DAYS = 911;
KEY = GOPR:NESS;
};