def test_csv2ecl(tmpdir, mocker): """Test command line interface for csv to Eclipse include files""" tmpdir.chdir() tmpcsvfile = "satfunc.csv" swof_df = pd.DataFrame( columns=["KEYWORD", "SW", "KRW", "KROW", "PCOW"], data=[["SWOF", 0.0, 0.0, 1.0, 0.0], ["SWOF", 1.0, 1.0, 0.0, 0.0]], ) swof_df.to_csv(tmpcsvfile, index=False) mocker.patch("sys.argv", ["csv2ecl", "satfunc", "--output", "swof.inc", tmpcsvfile]) csv2ecl.main() pd.testing.assert_frame_equal( satfunc.df(open("swof.inc").read()).drop("SATNUM", axis="columns"), swof_df, check_like=True, ) # Test writing to stdout: result = subprocess.run( ["csv2ecl", "satfunc", "--output", "-", tmpcsvfile], stdout=subprocess.PIPE) pd.testing.assert_frame_equal( satfunc.df(result.stdout.decode()).drop("SATNUM", axis="columns"), swof_df, check_like=True, )
def test_main_subparser(tmpdir, mocker): """Test command line interface""" tmpdir.chdir() tmpcsvfile = "equil.csv" mocker.patch("sys.argv", ["ecl2csv", "equil", "-v", DATAFILE, "-o", tmpcsvfile]) ecl2csv.main() assert Path(tmpcsvfile).is_file() disk_df = pd.read_csv(tmpcsvfile) assert not disk_df.empty # Test the reverse operation: mocker.patch( "sys.argv", ["csv2ecl", "equil", "-v", "--output", "equil.inc", tmpcsvfile]) csv2ecl.main() # NB: cvs2ecl does not output the phase configuration! phases = "WATER\nGAS\nOIL\n\n" ph_equil_inc = Path("phasesequil.inc") ph_equil_inc.write_text(phases + Path("equil.inc").read_text()) pd.testing.assert_frame_equal(equil.df(ph_equil_inc.read_text()), disk_df) # Test via stdout: result = subprocess.run( ["csv2ecl", "equil", "--output", "-", tmpcsvfile], stdout=subprocess.PIPE, ) pd.testing.assert_frame_equal( equil.df(phases + result.stdout.decode()), disk_df, check_like=True, )
def test_main(tmp_path, mocker): """Test command line interface""" os.chdir(tmp_path) tmpcsvfile = tmp_path / "pvt.csv" mocker.patch( "sys.argv", ["ecl2csv", "pvt", "-v", EIGHTCELLS, "-o", str(tmpcsvfile)] ) ecl2csv.main() assert Path(tmpcsvfile).is_file() disk_df = pd.read_csv(tmpcsvfile) assert "PVTNUM" in disk_df assert "KEYWORD" in disk_df assert not disk_df.empty # Write back to include file: incfile = tmp_path / "pvt.inc" mocker.patch( "sys.argv", ["csv2ecl", "pvt", "-v", str(tmpcsvfile), "-o", str(incfile)] ) csv2ecl.main() # Reparse the include file on disk back to dataframe # and check dataframe equality assert Path(incfile).is_file() disk_inc_df = pvt.df(open(incfile).read()) pd.testing.assert_frame_equal(disk_df, disk_inc_df) # Test entry point towards include file: (Path(tmp_path) / "pvto.inc").write_text( """PVTO 0 1 1.0001 1 200 1.000 1.001 / 18 25 1.14 0.59 / / """ ) mocker.patch("sys.argv", ["ecl2csv", "pvt", "-v", "pvto.inc", "-o", "pvto.csv"]) ecl2csv.main() assert Path("pvto.csv").is_file() # Empty data: (Path(tmp_path) / "empty.inc").write_text( """SWOF 0 1 1.0001 1 / / """ ) mocker.patch("sys.argv", ["ecl2csv", "pvt", "-v", "empty.inc", "-o", "empty.csv"]) ecl2csv.main() assert not Path("empty.csv").read_text().strip()
def test_csv2ecl_summary(tmpdir, mocker): """Check that we can call df2eclsum through the csv2ecl command line utility""" dframe = pd.DataFrame([ { "DATE": "2016-01-01", "FOPT": 1000, "FOPR": 100 }, { "DATE": "2017-01-01", "FOPT": 1000, "FOPR": 100 }, ]) tmpdir.chdir() dframe.to_csv("summary.csv") 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", "--debug", "summary.csv", "--output", str(Path("foo") / Path("SYNTHETIC")), ], ) csv2ecl.main() assert ("foo" / Path("SYNTHETIC.UNSMRY")).is_file() assert ("foo" / Path("SYNTHETIC.SMSPEC")).is_file()
def test_main(tmpdir): """Test command line interface""" tmpcsvfile = str(tmpdir.join("pvt.csv")) sys.argv = ["ecl2csv", "pvt", "-v", DATAFILE, "-o", tmpcsvfile] ecl2csv.main() assert os.path.exists(tmpcsvfile) disk_df = pd.read_csv(tmpcsvfile) assert "PVTNUM" in disk_df assert "KEYWORD" in disk_df assert not disk_df.empty # Write back to include file: incfile = str(tmpdir.join("pvt.inc")) sys.argv = ["csv2ecl", "pvt", "-v", str(tmpcsvfile), "-o", incfile] csv2ecl.main() # Reparse the include file on disk back to dataframe # and check dataframe equality assert os.path.exists(incfile) disk_inc_df = pvt.df(open(incfile).read()) pd.testing.assert_frame_equal(disk_df, disk_inc_df)
def test_main(tmpdir): """Test command line interface""" tmpdir.chdir() tmpcsvfile = ".TMP-satfunc.csv" sys.argv = ["satfunc2csv", DATAFILE, "-o", tmpcsvfile] satfunc.main() assert os.path.exists(tmpcsvfile) disk_df = pd.read_csv(tmpcsvfile) assert not disk_df.empty # Write back to include file: incfile = str(tmpdir.join("relperm.inc")) sys.argv = ["csv2ecl", "satfunc", "-v", tmpcsvfile, "-o", incfile] csv2ecl.main() # Reparse the include file on disk back to dataframe # and check dataframe equality assert os.path.exists(incfile) disk_inc_df = satfunc.df(open(incfile).read()) pd.testing.assert_frame_equal( disk_df.sort_values(["SATNUM", "KEYWORD"]).reset_index(drop=True), disk_inc_df.sort_values(["SATNUM", "KEYWORD"]).reset_index(drop=True), )