def test_mock_two_satnums_via_fam2_files(tmpdir, int_param, expected_file): tmpdir.chdir() PyscalFactory.create_pyscal_list(TWO_SATNUM_PYSCAL_MOCK.loc["low"], h=0.1).dump_family_2("pess.inc") PyscalFactory.create_pyscal_list(TWO_SATNUM_PYSCAL_MOCK.loc["base"], h=0.1).dump_family_2("base.inc") PyscalFactory.create_pyscal_list(TWO_SATNUM_PYSCAL_MOCK.loc["high"], h=0.1).dump_family_2("opt.inc") config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [{ "param_w": int_param, "param_g": int_param }], "family": 2, "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = Path("outfile.inc").read_text() outfile_df = satfunc.df(outfile_str) if expected_file is not None: expected_df = satfunc.df(Path(expected_file).read_text()) pd.testing.assert_frame_equal(outfile_df, expected_df) else: # Use test function from pyscal to assert that the produced file is # valid for Eclipse (not testing numerically that the interpolation # is correct) sat_table_str_ok(outfile_str)
def test_mock(tmpdir): """Mocked pyscal-generated input files. Note that this is using pyscal both for dumping to disk and parsing from disk, and is thus not representative for how flexible the code is for reading from include files not originating in pyscal. """ tmpdir.chdir() mock_family_1() config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [{ "param_w": -0.5, "param_g": 0.5 }], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_df = satfunc.df(open("outfile.inc").read(), ntsfun=1) assert set(outfile_df["KEYWORD"].unique()) == {"SWOF", "SGOF"} assert outfile_df["SW"].sum() > 0 assert outfile_df["SG"].sum() > 0 assert outfile_df["KRW"].sum() > 0 assert outfile_df["KROW"].sum() > 0 assert outfile_df["KRG"].sum() > 0 assert outfile_df["KROG"].sum() > 0 assert outfile_df["PCOW"].sum() > 0
def test_mock_two_satnums_via_xlsx(tmp_path): """Test initializing interp_relperm from a pyscal xlsx file""" os.chdir(tmp_path) TWO_SATNUM_PYSCAL_MOCK.reset_index().to_excel("scal_input.xlsx") config = { "pyscalfile": "scal_input.xlsx", "result_file": "outfile.inc", "interpolations": [{"param_w": -0.5, "param_g": 0.5}], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = Path("outfile.inc").read_text(encoding="utf8") assert outfile_str.find("SCAL recommendation interpolation to 0.5")
def test_family_2_output(tmp_path): """Test that we gan get family 2 ouput (from family 1 input)""" os.chdir(tmp_path) mock_family_1() config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [{"param_w": -0.5, "param_g": 0.5}], "family": 2, "delta_s": 0.1, } interp_relperm.process_config(config) output = Path("outfile.inc").read_text(encoding="utf8") assert "SWFN" in output assert "SGFN" in output assert "SOF3" in output
def test_garbled_base_input(tmp_path): """Perturb the swof_base.inc so that it does not include the SWOF keyword""" os.chdir(TESTDATA) Path(tmp_path / "swof_base_invalid.inc").write_text( "xx" + Path("swof_base.inc").read_text(encoding="utf8"), encoding="utf8" ) cfg = { "base": [str(tmp_path / "swof_base_invalid.inc"), "sgof_base.inc"], "high": ["swof_opt.inc", "sgof_opt.inc"], "low": ["swof_pes.inc", "sgof_pes.inc"], "result_file": str(tmp_path / "foo.inc"), "interpolations": [{"param_w": 0.1, "param_g": -0.1}], } parsed_cfg = configsuite.ConfigSuite( cfg, interp_relperm.get_cfg_schema(), deduce_required=True ) assert parsed_cfg.valid # Error can't be captured by schema with pytest.raises(SystemExit): interp_relperm.process_config(cfg)
def test_wrong_family(tmp_path): """Test error when wrong family type is provided""" os.chdir(tmp_path) mock_family_1() config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [{"param_w": -0.5, "param_g": 0.5}], "family": "Rockefeller", "delta_s": 0.1, } with pytest.raises( SystemExit, match="Is x a number is false on input 'Rockefeller'" ): interp_relperm.process_config(config) config["family"] = 3 with pytest.raises(SystemExit): interp_relperm.process_config(config)
def test_family_2_output(tmpdir): tmpdir.chdir() mock_family_1() config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [{ "param_w": -0.5, "param_g": 0.5 }], "family": 2, "delta_s": 0.1, } interp_relperm.process_config(config) output = Path("outfile.inc").read_text() assert "SWFN" in output assert "SGFN" in output assert "SOF3" in output
def test_mock_two_satnums_via_files(tmpdir): """Mocked pyscal-generated input files. Note that this is using pyscal both for dumping to disk and parsing from disk, and is thus not representative for how flexible the code is for reading from include files not originating in pyscal. """ # pylint: disable=no-value-for-parameter tmpdir.chdir() PyscalFactory.create_pyscal_list( TWO_SATNUM_PYSCAL_MOCK.loc["low"]).dump_family_1("pess.inc") PyscalFactory.create_pyscal_list( TWO_SATNUM_PYSCAL_MOCK.loc["base"]).dump_family_1("base.inc") PyscalFactory.create_pyscal_list( TWO_SATNUM_PYSCAL_MOCK.loc["high"]).dump_family_1("opt.inc") config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [{ "param_w": -0.5, "param_g": 0.5 }], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = Path("outfile.inc").read_text() # Assert things about the comments emitted by pyscal when interpolating: # This is used as a proxy for asserting that interpolation parameters # are used for the correct satnums assert outfile_str.find("SCAL recommendation interpolation to 0.5") assert outfile_str.find("SCAL recommendation interpolation to -0.5") # SWOF comes before SGOF: assert outfile_str.find("to -0.5") < outfile_str.find("to 0.5") outfile_df = satfunc.df(outfile_str, ntsfun=2) assert set(outfile_df["KEYWORD"].unique()) == {"SWOF", "SGOF"} assert set(outfile_df["SATNUM"].unique()) == {1, 2} config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [ { "tables": [1], "param_w": -0.9, "param_g": -0.5 }, { "tables": [2], "param_w": 0.5, "param_g": 0.8 }, ], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = open("outfile.inc").read() assert outfile_str.find("to -0.9") < outfile_str.find("to 0.5") assert outfile_str.find("to 0.5") < outfile_str.find("to -0.5") assert outfile_str.find("to 0.5") < outfile_str.find("to 0.8") config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [ # This is a user error, the latter will override the first { "param_w": -0.9, "param_g": -0.5 }, { "param_w": 0.5, "param_g": 0.8 }, ], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = open("outfile.inc").read() assert "interpolation to -0.9" not in outfile_str assert "interpolation to 0.8" in outfile_str config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [ # Here the user intentionally overwrites the first: { "param_w": -0.9, "param_g": -0.5 }, { "tables": [], "param_w": 0.5, "param_g": 0.8 }, ], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = open("outfile.inc").read() assert "interpolation to -0.9" not in outfile_str assert "interpolation to 0.8" in outfile_str
def test_mock_two_satnums(tmpdir): """Mocked pyscal-generated input files. Note that this is using pyscal both for dumping to disk and parsing from disk, and is thus not representative for how flexible the code is for reading from include files not originating in pyscal. """ # pylint: disable=no-value-for-parameter tmpdir.chdir() columns = [ "SATNUM", "Nw", "Now", "Ng", "Nog", "swl", "a", "b", "poro_ref", "perm_ref", "drho", ] dframe_pess = pd.DataFrame( columns=columns, data=[ [1, 1, 1, 1, 1, 0.1, 2, -2, 0.25, 100, 150], [1, 1, 1, 1, 1, 0.1, 2, -2, 0.25, 100, 150], ], ) dframe_base = pd.DataFrame( columns=columns, data=[ [1, 2, 2, 2, 2, 0.1, 2, -2, 0.25, 200, 150], [1, 2, 2, 2, 2, 0.1, 2, -2, 0.25, 200, 150], ], ) dframe_opt = pd.DataFrame( columns=columns, data=[ [1, 3, 3, 3, 3, 0.1, 2, -2, 0.25, 300, 150], [1, 3, 3, 3, 3, 0.1, 2, -2, 0.25, 300, 150], ], ) PyscalFactory.create_pyscal_list(dframe_pess).dump_family_1("pess.inc") PyscalFactory.create_pyscal_list(dframe_base).dump_family_1("base.inc") PyscalFactory.create_pyscal_list(dframe_opt).dump_family_1("opt.inc") config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [{ "param_w": -0.5, "param_g": 0.5 }], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = open("outfile.inc").read() # Assert things about the comments emitted by pyscal when interpolating: # This is used as a proxy for asserting that interpolation parameters # are used for the correct satnums assert outfile_str.find("SCAL recommendation interpolation to 0.5") assert outfile_str.find("SCAL recommendation interpolation to -0.5") # SWOF comes before SGOF: assert outfile_str.find("to -0.5") < outfile_str.find("to 0.5") outfile_df = satfunc.df(outfile_str, ntsfun=2) assert set(outfile_df["KEYWORD"].unique()) == {"SWOF", "SGOF"} assert set(outfile_df["SATNUM"].unique()) == {1, 2} config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [ { "tables": [1], "param_w": -0.9, "param_g": -0.5 }, { "tables": [2], "param_w": 0.5, "param_g": 0.8 }, ], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = open("outfile.inc").read() assert outfile_str.find("to -0.9") < outfile_str.find("to 0.5") assert outfile_str.find("to 0.5") < outfile_str.find("to -0.5") assert outfile_str.find("to 0.5") < outfile_str.find("to 0.8") config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [ # This is a user error, the latter will override the first { "param_w": -0.9, "param_g": -0.5 }, { "param_w": 0.5, "param_g": 0.8 }, ], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = open("outfile.inc").read() assert "interpolation to -0.9" not in outfile_str assert "interpolation to 0.8" in outfile_str config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [ # Here the user intentionally overwrites the first: { "param_w": -0.9, "param_g": -0.5 }, { "tables": [], "param_w": 0.5, "param_g": 0.8 }, ], "delta_s": 0.1, } interp_relperm.process_config(config) outfile_str = open("outfile.inc").read() assert "interpolation to -0.9" not in outfile_str assert "interpolation to 0.8" in outfile_str
def test_mock(tmpdir): """Mocked pyscal-generated input files. Note that this is using pyscal both for dumping to disk and parsing from disk, and is thus not representative for how flexible the code is for reading from include files not originating in pyscal. """ tmpdir.chdir() columns = [ "SATNUM", "Nw", "Now", "Ng", "Nog", "swl", "a", "b", "poro_ref", "perm_ref", "drho", ] dframe_pess = pd.DataFrame( columns=columns, data=[[1, 1, 1, 1, 1, 0.1, 2, -2, 0.25, 100, 150]], ) dframe_base = pd.DataFrame( columns=columns, data=[[1, 2, 2, 2, 2, 0.1, 2, -2, 0.25, 200, 150]], ) dframe_opt = pd.DataFrame( columns=columns, data=[[1, 3, 3, 3, 3, 0.1, 2, -2, 0.25, 300, 150]], ) PyscalFactory.create_pyscal_list(dframe_pess).dump_family_1("pess.inc") PyscalFactory.create_pyscal_list(dframe_base).dump_family_1("base.inc") PyscalFactory.create_pyscal_list(dframe_opt).dump_family_1("opt.inc") config = { "base": ["base.inc"], "low": ["pess.inc"], "high": ["opt.inc"], "result_file": "outfile.inc", "interpolations": [{ "param_w": -0.5, "param_g": 0.5 }], "delta_s": 0.1, } interp_relperm.process_config(config) interp_relperm.process_config(config) outfile_df = satfunc.df(open("outfile.inc").read(), ntsfun=1) assert set(outfile_df["KEYWORD"].unique()) == {"SWOF", "SGOF"} assert outfile_df["SW"].sum() > 0 assert outfile_df["SG"].sum() > 0 assert outfile_df["KRW"].sum() > 0 assert outfile_df["KROW"].sum() > 0 assert outfile_df["KRG"].sum() > 0 assert outfile_df["KROG"].sum() > 0 assert outfile_df["PCOW"].sum() > 0