def test_df2ecl_equil(tmp_path): """Test the underlying function directly""" dframe = pd.DataFrame([ { "Z": 2469.0, "PRESSURE": 382.4, "OWC": 1700.0, "PCOWC": 0.0, "GOC": 0.0, "EQLNUM": 1, "KEYWORD": "EQUIL", }, ]) # Check that we don't need the KEYWORD in the underlying function assert equil.df2ecl_equil(dframe) == equil.df2ecl_equil( dframe.drop("KEYWORD", axis="columns")) # Can also drop EQLNUM since we have only one row: assert equil.df2ecl_equil(dframe) == equil.df2ecl_equil( dframe.drop("EQLNUM", axis="columns")) # Problem if we have two rows, nothing is returned and a critical error is logged assert (equil.df2ecl_equil( pd.concat([dframe, dframe]).drop("EQLNUM", axis="columns")) == "")
def test_decks(): """Test some string decks""" deckstr = """ OIL WATER GAS EQUIL 2000 200 2200 / """ df = equil.df(deckstr) assert df["OWC"].values == 2200 assert len(df) == 1 assert "IGNORE1" not in df assert df["EQLNUM"].unique()[0] == 1 inc = equil.df2ecl(df, withphases=True) df_from_inc = equil.df(inc) # 0 columns can be both integers and floats. pd.testing.assert_frame_equal(df, df_from_inc, check_dtype=False) # Test empty data: inc = equil.df2ecl_equil(equil.df("")) assert "No data" in inc assert equil.df(inc).empty deckstr = """ OIL WATER EQUIL 2000 200 2200 / """ df = equil.df(deckstr) assert df["OWC"].values == 2200 assert len(df) == 1 assert "IGNORE1" not in df inc = equil.df2ecl(df, withphases=True) df_from_inc = equil.df(inc) # 0 columns can be both integers and floats. pd.testing.assert_frame_equal(df, df_from_inc, check_dtype=False) deckstr = """ GAS WATER EQUIL 2000 200 2200 / """ df = equil.df(deckstr) assert df["GWC"].values == 2200 assert "OWC" not in df assert len(df) == 1 assert "IGNORE2" not in df inc = equil.df2ecl(df, withphases=True) df_from_inc = equil.df(inc) # 0 columns can be both integers and floats. pd.testing.assert_frame_equal(df, df_from_inc, check_dtype=False) deckstr = """ GAS OIL EQUIL 2000 200 2200 1 2100 3 / """ df = equil.df(deckstr) assert df["GOC"].values == 2100 assert "GWC" not in df assert "OWC" not in df assert len(df) == 1 assert "IGNORE2" not in df inc = equil.df2ecl(df, withphases=True) df_from_inc = equil.df(inc) # 0 columns can be both integers and floats. pd.testing.assert_frame_equal(df, df_from_inc, check_dtype=False) deckstr = """ OIL WATER GAS -- Output file printed by ecl2df.equil 0.5.2.dev12+g785dc0d.d20200402 -- at 2020-04-03 16:18:57.450100 EQUIL -- DATUM PRESSURE OWC PCOWC GOC PCGOC INITRS INITRV ACCURACY 2469.0 382.4 1700.0 0.0 0.0 0.0 1 0 20 / 2469.0 382.4 1000.0 0.0 0.0 0.0 2 0 20 / """ df = equil.df(deckstr) assert set(df["GOC"].values) == {0.0} assert "GWC" not in df assert "OWC" in df assert len(df) == 2 assert "IGNORE2" not in df inc = equil.df2ecl(df, withphases=True) df_from_inc = equil.df(inc) # 0 columns can be both integers and floats. pd.testing.assert_frame_equal(df, df_from_inc, check_dtype=False)
def df2ecl_equil(dframe, comment: str = None): """Wrapper function to be able to test df2ecl (it asks for a function in the calling module)""" return equil.df2ecl_equil(dframe, comment)