From 9ec0e0d120863619d2ef187376e87d3eb825a262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Thu, 25 Feb 2021 13:29:38 +0100 Subject: [PATCH] Fix output to subdirectories in csv2ecl summary --- ecl2df/csv2ecl.py | 2 +- ecl2df/summary.py | 11 ++++++++++- tests/test_summary.py | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ecl2df/csv2ecl.py b/ecl2df/csv2ecl.py index 0c372c7e5..02fc98e38 100644 --- a/ecl2df/csv2ecl.py +++ b/ecl2df/csv2ecl.py @@ -24,7 +24,7 @@ "CSV2ECL(=equil, =equil.csv, " "=eclipse/include/equil.inc)``" "CSV2ECL(=summary, =summary-monthly.csv, " - "=MONTHLYSUMMARY)``" + "=eclipse/model/MONTHLYSUMMARY)``" ) diff --git a/ecl2df/summary.py b/ecl2df/summary.py index c65df273a..57b09e276 100644 --- a/ecl2df/summary.py +++ b/ecl2df/summary.py @@ -1,4 +1,5 @@ """Provide a two-way Pandas DataFrame interface to Eclipse summary data (UNSMRY)""" +import os import logging from pathlib import Path @@ -694,6 +695,14 @@ def summary_reverse_main(args): summary_df = pd.read_csv(args.csvfile) logger.info("Parsed %s", args.csvfile) - eclsum = df2eclsum(summary_df, args.output) + outputdir = Path(args.output).parent + eclbase = Path(args.output).name + + # EclSum.fwrite can only write to current directory: + cwd = os.getcwd() + os.chdir(outputdir) + eclsum = df2eclsum(summary_df, eclbase) EclSum.fwrite(eclsum) + os.chdir(cwd) + logger.info("Wrote to %s and %s", args.output + ".UNSMRY", args.output + ".SMSPEC") diff --git a/tests/test_summary.py b/tests/test_summary.py index f76ebb44f..07c6896e3 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -747,7 +747,7 @@ def test_df2eclsum_errors(): @pytest.mark.integration -def test_csv2ecl_summary(tmpdir): +def test_csv2ecl_summary(tmpdir, mocker): """Check that we can call df2eclsum through the csv2ecl command line utility""" dframe = pd.DataFrame( @@ -758,14 +758,34 @@ def test_csv2ecl_summary(tmpdir): ) tmpdir.chdir() dframe.to_csv("summary.csv") - sys.argv = [ - "csv2ecl", - "summary", - "-v", - "summary.csv", - "--output", - "SYNTHETIC", - ] + mocker.patch( + "sys.argv", + [ + "csv2ecl", + "summary", + "-v", + "summary.csv", + "--output", + "SYNTHETIC", + ], + ) csv2ecl.main() assert Path("SYNTHETIC.UNSMRY").is_file() assert Path("SYNTHETIC.SMSPEC").is_file() + + # Check that we can write to a subdirectory + Path("foo").mkdir() + mocker.patch( + "sys.argv", + [ + "csv2ecl", + "summary", + "-v", + "summary.csv", + "--output", + str(Path("foo") / Path("SYNTHETIC")), + ], + ) + csv2ecl.main() + assert ("foo" / Path("SYNTHETIC.UNSMRY")).is_file() + assert ("foo" / Path("SYNTHETIC.SMSPEC")).is_file()