def test_factory_wateroilgas(): """Test creating discrete cases of WaterOilGas from factory""" logging.getLogger().setLevel("INFO") factory = PyscalFactory() wog = factory.create_water_oil_gas(dict(nw=2, now=3, ng=1, nog=2.5)) swof = wog.SWOF() sgof = wog.SGOF() assert sat_table_str_ok(swof) # sgof code works for swof also currently assert sat_table_str_ok(sgof) assert "Corey krg" in sgof assert "Corey krog" in sgof assert "Corey krw" in swof assert "Corey krow" in swof check_table(wog.gasoil.table) check_table(wog.wateroil.table) # Some users will mess up lower vs upper case: wog = factory.create_water_oil_gas(dict(NW=2, NOW=3, NG=1, nog=2.5)) swof = wog.SWOF() sgof = wog.SGOF() assert sat_table_str_ok(swof) # sgof code works for swof also currently assert sat_table_str_ok(sgof) assert "Corey krg" in sgof assert "Corey krog" in sgof assert "Corey krw" in swof assert "Corey krow" in swof # Mangling data with pytest.raises(ValueError): factory.create_water_oil_gas(dict(nw=2, now=3, ng=1))
def test_simple_j_petro(): """Simple test of the simple J petrophysical function correlation""" wateroil = WaterOil(swl=0.01) wateroil.add_simple_J_petro(a=1, b=-2) check_table(wateroil.table) assert wateroil.pccomment assert "etrophysic" in wateroil.pccomment # Zero gravity: wateroil.add_simple_J_petro(a=1, b=-2, g=0) assert wateroil.table.pc.unique() == 0.0 # Numerical test from sample numbers calculated independently in different tool: wateroil = WaterOil(swl=0.05, h=0.025) wateroil.add_simple_J_petro( a=1.45, b=-0.285, drho=143, g=9.81, perm_ref=15, poro_ref=0.27 ) float_df_checker(wateroil.table, "sw", 0.1, "pc", 22.36746) assert "Simplified" in wateroil.pccomment assert "etrophysic" in wateroil.pccomment wateroil.add_corey_oil() wateroil.add_corey_water() swof = wateroil.SWOF() assert isinstance(swof, str) assert swof assert sat_table_str_ok(swof) assert sat_table_str_ok(wateroil.SWFN())
def test_simple_j(): """Simple test of the simple J function correlation""" wateroil = WaterOil(swl=0.01) wateroil.add_simple_J() # swl set to zero will give infinite pc check_table(wateroil.table) assert wateroil.pccomment # Zero gravity: wateroil.add_simple_J(g=0) assert wateroil.table.pc.unique() == 0.0 # This should give back Sw: # This ensures that density and gravity scaling is correct wateroil.add_simple_J(a=1, b=1, poro_ref=1, perm_ref=1, drho=1000, g=100) assert (wateroil.table["pc"] - wateroil.table["sw"]).sum() < 0.00001 # (check_table() will fail on this, when b > 0) # Some values seen in real life: wateroil.add_simple_J(a=100, b=-1.5, poro_ref=0.12, perm_ref=100, drho=200) check_table(wateroil.table) assert "Simplified" in wateroil.pccomment assert "a=100" in wateroil.pccomment assert "b=-1.5" in wateroil.pccomment wateroil.add_corey_oil() wateroil.add_corey_water() swof = wateroil.SWOF() assert isinstance(swof, str) assert swof assert sat_table_str_ok(swof) assert sat_table_str_ok(wateroil.SWFN())
def test_xls_factory(): """Test/demonstrate how to go from data in an excel row to pyscal objects This test function predates the load_relperm_df() function, but can still be in here. """ if "__file__" in globals(): # Easen up copying test code into interactive sessions testdir = os.path.dirname(os.path.abspath(__file__)) else: testdir = os.path.abspath(".") xlsxfile = testdir + "/data/scal-pc-input-example.xlsx" scalinput = pd.read_excel(xlsxfile).set_index(["SATNUM", "CASE"]) for ((satnum, _), params) in scalinput.iterrows(): assert satnum wog = PyscalFactory.create_water_oil_gas(params.to_dict()) swof = wog.SWOF() assert "LET krw" in swof assert "LET krow" in swof assert "Simplified J" in swof sgof = wog.SGOF() sat_table_str_ok(sgof) assert "LET krg" in sgof assert "LET krog" in sgof
def test_wateroil_tag(tag): """Test that we are unlikely to crash Eclipse by having ugly tag names""" wateroil = WaterOil(h=0.5, tag=tag) wateroil.add_corey_oil() wateroil.add_corey_water() sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN())
def test_gasoil_tag(tag): """Test tagging of GasOil objects, that we are not able to produce something that can crash Eclipse""" gasoil = GasOil(h=0.5, tag=tag) gasoil.add_corey_gas() gasoil.add_corey_oil() assert sat_table_str_ok(gasoil.SGOF()) assert sat_table_str_ok(gasoil.SGFN())
def test_scalrecommendation(): """Testing making SCAL rec from dict of dict""" factory = PyscalFactory() scal_input = { "low": {"nw": 2, "now": 4, "ng": 1, "nog": 2}, "BASE": {"nw": 3, "NOW": 3, "ng": 1, "nog": 2}, "high": {"nw": 4, "now": 2, "ng": 1, "nog": 3}, } scal = factory.create_scal_recommendation(scal_input) # (not supported yet to make WaterOil only..) scal.interpolate(-0.5).SWOF() incomplete1 = scal_input.copy() del incomplete1["BASE"] with pytest.raises(ValueError): factory.create_scal_recommendation(incomplete1) go_only = scal_input.copy() del go_only["low"]["now"] del go_only["low"]["nw"] gasoil = factory.create_scal_recommendation(go_only) assert gasoil.low.wateroil is None assert gasoil.base.wateroil is not None assert gasoil.high.wateroil is not None interp = scal.interpolate(-0.5) sat_table_str_ok(interp.SWOF()) sat_table_str_ok(interp.SGOF()) sat_table_str_ok(interp.SLGOF()) sat_table_str_ok(interp.SOF3()) check_table(interp.wateroil.table) check_table(interp.gasoil.table)
def test_factory_wateroilgas_wo(): """Test making only wateroil through the wateroilgas factory""" factory = PyscalFactory() wog = factory.create_water_oil_gas( dict(nw=2, now=3, krowend=0.5, sorw=0.04, swcr=0.1) ) swof = wog.SWOF() assert "Corey krw" in swof assert "krw" in wog.wateroil.table sat_table_str_ok(swof) check_table(wog.wateroil.table) assert wog.gasoil is None wog.SGOF()
def test_slgof_hypo(swl, sorg, sgcr, h): """Shotgun-testing of slgof""" gasoil = GasOil(swl=swl, sorg=sorg, sgcr=sgcr, h=h) gasoil.add_corey_gas() gasoil.add_corey_oil() assert gasoil.selfcheck() slgof = gasoil.slgof_df() check_table(slgof) # Eclipse 100 requirement from manual: assert np.isclose(slgof["sl"].values[0], gasoil.swl + gasoil.sorg) # Eclipse 100 requirement from manual: assert np.isclose(slgof["sl"].values[-1], 1.0) slgof_str = gasoil.SLGOF() assert isinstance(slgof_str, str) assert slgof_str sat_table_str_ok(slgof_str)
def test_let_pc_pd(): """Test LET formulation for primary drainage capillary pressure""" wateroil = WaterOil(swirr=0.1) wateroil.add_LET_pc_pd(Lp=1, Ep=1, Tp=1, Lt=1, Et=1, Tt=1, Pcmax=10, Pct=5) assert np.isclose(wateroil.table["pc"].max(), 10) assert np.isclose(wateroil.table["pc"].min(), 0) # (everything is linear) wateroil.add_LET_pc_pd(Lp=10, Ep=10, Tp=10, Lt=10, Et=10, Tt=10, Pcmax=10, Pct=5) assert np.isclose(wateroil.table["pc"].max(), 10) assert np.isclose(wateroil.table["pc"].min(), 0) # On a plot, you can see a kink at Pc=5. # wateroil.plotpc() wateroil = WaterOil(swirr=0.1, sorw=0.4) wateroil.add_LET_pc_pd(Lp=10, Ep=10, Tp=10, Lt=10, Et=10, Tt=10, Pcmax=5, Pct=2) assert np.isclose(wateroil.table["pc"].max(), 5) assert np.isclose(wateroil.table["pc"].min(), 0) # On plot: hard-to-see kink at Pc=2. Linear curve from sw=0.6 to 1 due to sorw. assert ( len(wateroil.table[(wateroil.table["sw"] >= 0.6) & (wateroil.table["sw"] <= 1)]) == 2 ) wateroil.add_corey_water() wateroil.add_corey_oil() assert sat_table_str_ok(wateroil.SWOF())
def test_factory_gasoil(): """Test that we can create curves from dictionaries of parameters""" logging.getLogger().setLevel("INFO") factory = PyscalFactory() with pytest.raises(TypeError): # (this must be a dictionary) factory.create_gas_oil(swirr=0.01) # noqa gasoil = factory.create_gas_oil( dict(swirr=0.01, swl=0.1, sgcr=0.05, tag="Good sand", ng=1, nog=2)) assert isinstance(gasoil, GasOil) assert gasoil.sgcr == 0.05 assert gasoil.swl == 0.1 assert gasoil.swirr == 0.01 assert gasoil.tag == "Good sand" sgof = gasoil.SGOF() assert sat_table_str_ok(sgof) check_table(gasoil.table) assert "Corey krg" in sgof assert "Corey krog" in sgof assert "Zero capillary pressure" in sgof gasoil = factory.create_gas_oil( dict(ng=1.2, nog=2, krgend=0.8, krgmax=0.9, krogend=0.6)) sgof = gasoil.SGOF() assert sat_table_str_ok(sgof) assert "kroend=0.6" in sgof assert "krgend=0.8" in sgof check_table(gasoil.table) gasoil = factory.create_gas_oil(dict(ng=1.3, Log=2, Eog=2, Tog=2)) sgof = gasoil.SGOF() check_table(gasoil.table) assert sat_table_str_ok(sgof) assert "Corey krg" in sgof assert "LET krog" in sgof gasoil = factory.create_gas_oil(dict(Lg=1, Eg=1, Tg=1, Log=2, Eog=2, Tog=2)) sgof = gasoil.SGOF() assert sat_table_str_ok(sgof) check_table(gasoil.table) assert "LET krg" in sgof assert "LET krog" in sgof
def test_gasoil_let1(l, e, t, krgend, krgmax): """Test the LET formulation, take 1""" gasoil = GasOil() try: gasoil.add_LET_oil(l, e, t, krgend) gasoil.add_LET_gas(l, e, t, krgend, krgmax) except AssertionError: # This happens for negative values f.ex. return assert "krog" in gasoil.table assert "krg" in gasoil.table assert isinstance(gasoil.krgcomment, str) check_table(gasoil.table) check_linear_sections(gasoil) sgofstr = gasoil.SGOF() assert len(sgofstr) > 100 sat_table_str_ok(sgofstr)
def test_dump(): """Test dumping Eclipse include data to file""" if "__file__" in globals(): # Easen up copying test code into interactive sessions testdir = os.path.dirname(os.path.abspath(__file__)) else: testdir = os.path.abspath(".") relperm_data = PyscalFactory.load_relperm_df( testdir + "/data/relperm-input-example.xlsx") pyscal_list = PyscalFactory.create_pyscal_list(relperm_data) fam1 = pyscal_list.dump_family_1() sat_table_str_ok(fam1) fam2 = pyscal_list.dump_family_2() sat_table_str_ok(fam2)
def test_let_pc_imb(): """Test the LET formulation for imbibition capillary pressures""" wateroil = WaterOil(swirr=0.1) wateroil.add_LET_pc_imb(Ls=1, Es=1, Ts=1, Lf=1, Ef=1, Tf=1, Pcmax=10, Pcmin=-10, Pct=3) assert np.isclose(wateroil.table["pc"].max(), 10) assert np.isclose(wateroil.table["pc"].min(), -10) wateroil = WaterOil(swirr=0.1) wateroil.add_LET_pc_imb(Ls=5, Es=5, Ts=5, Lf=5, Ef=5, Tf=5, Pcmax=5, Pcmin=1, Pct=4) assert np.isclose(wateroil.table["pc"].max(), 5) assert np.isclose(wateroil.table["pc"].min(), 1) wateroil = WaterOil(swirr=0.1, sorw=0.3) wateroil.add_LET_pc_imb(Ls=5, Es=5, Ts=5, Lf=5, Ef=5, Tf=5, Pcmax=5, Pcmin=1, Pct=4) assert np.isclose(wateroil.table["pc"].max(), 5) assert np.isclose(wateroil.table["pc"].min(), 1) wateroil.add_corey_water() wateroil.add_corey_oil() sat_table_str_ok(wateroil.SWOF())
def test_norm_j_pc_random(swirr, swl, a_pc, b_pc, poro, perm, sigma_costau): """Test many possibilities of Pc-parameters. Outside of the tested range, there are many combination of parameters that can give infinite capillary pressure""" swl = swirr + swl # No point in getting too many AssertionErrors wateroil = WaterOil(swirr=swirr, swl=swl, h=0.01) try: wateroil.add_normalized_J(a=a_pc, b=b_pc, perm=perm, poro=poro, sigma_costau=sigma_costau) except (AssertionError, ValueError): # when poro is < 0 f.ex. return check_table(wateroil.table) wateroil.add_corey_water() wateroil.add_corey_oil() sat_table_str_ok(wateroil.SWOF())
def test_slgof(swl, sorg, sgcr): """Test dumping SLGOF records""" wog = WaterOilGas(swl=swl, sorg=sorg, sgcr=sgcr, h=0.05) wog.wateroil.add_corey_water() wog.wateroil.add_corey_oil() wog.gasoil.add_corey_gas(krgmax=1) wog.gasoil.add_corey_oil() assert wog.selfcheck() slgof = wog.gasoil.slgof_df() assert "sl" in slgof assert "krg" in slgof assert "krog" in slgof assert not slgof.empty check_table(slgof) sat_table_str_ok(wog.SLGOF()) # Requirements from E100 manual: assert np.isclose(slgof["sl"].values[0], wog.gasoil.swl + wog.gasoil.sorg) assert np.isclose(slgof["krg"].values[-1], 0) assert np.isclose(slgof["krog"].values[0], 0)
def test_gasoil_corey1(ng, nog): """Test the Corey formulation for gasoil""" gasoil = GasOil() try: gasoil.add_corey_oil(nog=nog) gasoil.add_corey_gas(ng=ng) except AssertionError: # This happens for "invalid" input return assert "krog" in gasoil.table assert "krg" in gasoil.table assert isinstance(gasoil.krgcomment, str) check_table(gasoil.table) sgofstr = gasoil.SGOF() assert len(sgofstr) > 100 assert sat_table_str_ok(sgofstr) gasoil.resetsorg() check_table(gasoil.table) sgofstr = gasoil.SGOF() assert len(sgofstr) > 100 assert sat_table_str_ok(sgofstr)
def test_make_scalrecommendation_go(): """Test that we can make scal recommendation objects from three WaterOilGas objects, but only with GasOil objects""" go_param_names = [ "swirr", "sorg", "krgend", "krgmax", "swl", "sgcr", "Lg", "Eg", "Tg", "Log", "Eog", "Tog", "krogend", ] low_let_go = slicedict(LOW_SAMPLE_LET, go_param_names) low = PyscalFactory.create_water_oil_gas(low_let_go) base_let_go = slicedict(BASE_SAMPLE_LET, go_param_names) base = PyscalFactory.create_water_oil_gas(base_let_go) high_let_go = slicedict(HIGH_SAMPLE_LET, go_param_names) assert "Lw" not in high_let_go high = PyscalFactory.create_water_oil_gas(high_let_go) rec = SCALrecommendation(low, base, high) interpolant = rec.interpolate(-0.5) check_table(interpolant.gasoil.table) assert interpolant.wateroil is None sat_table_str_ok(interpolant.SGOF()) sat_table_str_ok(interpolant.SGFN()) # This should return empty string assert not interpolant.SWOF()
def test_factory_wateroil(): """Test that we can create curves from dictionaries of parameters""" logging.getLogger().setLevel("INFO") factory = PyscalFactory() # Factory refuses to create incomplete defaulted objects. with pytest.raises(ValueError): factory.create_water_oil() with pytest.raises(TypeError): # (it must be a dictionary) factory.create_water_oil(swirr=0.01) # noqa wateroil = factory.create_water_oil( dict( swirr=0.01, swl=0.1, bogus="foobar", tag="Good sand", nw=3, now=2, krwend=0.2, krwmax=0.5, ) ) assert isinstance(wateroil, WaterOil) assert wateroil.swirr == 0.01 assert wateroil.swl == 0.1 assert wateroil.tag == "Good sand" assert "krw" in wateroil.table assert "Corey" in wateroil.krwcomment assert wateroil.table["krw"].max() == 0.2 # Because sorw==0 by default check_table(wateroil.table) sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN()) wateroil = factory.create_water_oil( dict(nw=3, now=2, sorw=0.1, krwend=0.2, krwmax=0.5) ) assert isinstance(wateroil, WaterOil) assert "krw" in wateroil.table assert "Corey" in wateroil.krwcomment assert wateroil.table["krw"].max() == 0.5 check_table(wateroil.table) sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN()) # Ambiguous works, but we don't guarantee that this results # in LET or Corey. wateroil = factory.create_water_oil(dict(nw=3, Lw=2, Ew=2, Tw=2, now=3)) assert "krw" in wateroil.table assert "Corey" in wateroil.krwcomment or "LET" in wateroil.krwcomment check_table(wateroil.table) sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN()) wateroil = factory.create_water_oil(dict(Lw=2, Ew=2, Tw=2, krwend=1, now=4)) assert isinstance(wateroil, WaterOil) assert "krw" in wateroil.table assert wateroil.table["krw"].max() == 1.0 assert "LET" in wateroil.krwcomment check_table(wateroil.table) sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN()) wateroil = factory.create_water_oil( dict(Lw=2, Ew=2, Tw=2, Low=3, Eow=3, Tow=3, krwend=0.5) ) assert isinstance(wateroil, WaterOil) assert "krw" in wateroil.table assert "krow" in wateroil.table assert wateroil.table["krw"].max() == 0.5 assert wateroil.table["krow"].max() == 1 assert "LET" in wateroil.krwcomment assert "LET" in wateroil.krowcomment check_table(wateroil.table) sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN()) # Add capillary pressure wateroil = factory.create_water_oil( dict(swl=0.1, nw=1, now=1, a=2, b=-1, poro_ref=0.2, perm_ref=100, drho=200) ) assert "pc" in wateroil.table assert wateroil.table["pc"].max() > 0.0 assert "Simplified J" in wateroil.pccomment check_table(wateroil.table) sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN()) # Test that the optional gravity g is picked up: wateroil = factory.create_water_oil( dict(swl=0.1, nw=1, now=1, a=2, b=-1, poro_ref=0.2, perm_ref=100, drho=200, g=0) ) assert "pc" in wateroil.table assert wateroil.table["pc"].max() == 0.0 check_table(wateroil.table) sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN()) # Test petrophysical simple J: wateroil = factory.create_water_oil( dict( swl=0.1, nw=1, now=1, a_petro=2, b_petro=-1, poro_ref=0.2, perm_ref=100, drho=200, ) ) assert "pc" in wateroil.table assert wateroil.table["pc"].max() > 0.0 assert "etrophysic" in wateroil.pccomment check_table(wateroil.table) sat_table_str_ok(wateroil.SWOF()) sat_table_str_ok(wateroil.SWFN()) # One pc param missing: wateroil = factory.create_water_oil( dict(swl=0.1, nw=1, now=1, a=2, b=-1, perm_ref=100, drho=200, g=0) ) assert "pc" not in wateroil.table
def test_tag_preservation(): """Test that we can preserve tags/comments through interpolation""" wo_low = WaterOil(swl=0.1) wo_high = WaterOil(swl=0.2) wo_low.add_corey_water(nw=2) wo_high.add_corey_water(nw=3) wo_low.add_corey_oil(now=2) wo_high.add_corey_oil(now=3) interpolant1 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2) assert "Interpolated to 0.1" in interpolant1.tag sat_table_str_ok(interpolant1.SWOF()) wo_high.tag = "FOOBAR" interpolant2 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2) assert "Interpolated to 0.1" in interpolant2.tag assert "between" in interpolant2.tag assert wo_high.tag in interpolant2.tag sat_table_str_ok(interpolant2.SWOF()) # wo_low.tag was empty deliberately here. # When wo_log and wo_high has the same tag: wo_low.tag = "FOOBAR" interpolant3 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2) assert "Interpolated to 0.1" in interpolant3.tag assert "between" not in interpolant3.tag assert wo_high.tag in interpolant3.tag sat_table_str_ok(interpolant3.SWOF()) # Explicit tag: interpolant4 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2, tag="Explicit tag") assert interpolant4.tag == "Explicit tag" # Tag with newline interpolant6 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2, tag="Explicit tag\non two lines") assert "Explicit tag" in interpolant6.tag print(interpolant6.SWOF()) sat_table_str_ok(interpolant6.SWOF()) # Empty tag: interpolant5 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2, tag="") assert interpolant5.tag == "" # Also sample check for GasOil (calls the same code) go_low = GasOil() go_high = GasOil() go_low.add_corey_gas(ng=2) go_high.add_corey_gas(ng=3) go_low.add_corey_oil(nog=2) go_high.add_corey_oil(nog=3) interpolant1 = utils.interpolate_go(go_low, go_high, parameter=0.1, h=0.2) assert "Interpolated to 0.1" in interpolant1.tag sat_table_str_ok(interpolant1.SGOF())
def test_pyscal_endpoint_static(tmpdir): """Test pyscal endpoint for static relperm input""" if "__file__" in globals(): # Easen up copying test code into interactive sessions testdir = os.path.dirname(os.path.abspath(__file__)) else: testdir = os.path.abspath(".") relperm_file = testdir + "/data/relperm-input-example.xlsx" tmpdir.chdir() sys.argv = ["pyscal", relperm_file] pyscalcli.main() assert os.path.exists("relperm.inc") relpermlines = "\n".join(open("relperm.inc").readlines()) assert "SWOF" in relpermlines assert "SGOF" in relpermlines assert "SLGOF" not in relpermlines assert "SOF3" not in relpermlines sat_table_str_ok(relpermlines) sys.argv = ["pyscal", relperm_file, "--output", "alt2relperm.inc"] pyscalcli.main() assert os.path.exists("alt2relperm.inc") sys.argv = ["pyscal", relperm_file, "-o", "altrelperm.inc"] pyscalcli.main() assert os.path.exists("altrelperm.inc") sys.argv = ["pyscal", relperm_file, "--family2", "-o", "relperm-fam2.inc"] pyscalcli.main() assert os.path.exists("relperm-fam2.inc") relpermlines = "\n".join(open("relperm-fam2.inc").readlines()) assert "SWFN" in relpermlines assert "SGFN" in relpermlines assert "SOF3" in relpermlines assert "SWOF" not in relpermlines assert "SGOF" not in relpermlines sat_table_str_ok(relpermlines) sys.argv = [ "pyscal", relperm_file, "--slgof", "--output", "relperm-slgof.inc" ] pyscalcli.main() assert os.path.exists("relperm-slgof.inc") relpermlines = "\n".join(open("relperm-slgof.inc").readlines()) assert "SWOF" in relpermlines assert "SGOF" not in relpermlines assert "SLGOF" in relpermlines assert "SOF3" not in relpermlines sat_table_str_ok(relpermlines) # Dump to deep directory structure that does not exists sys.argv = [ "pyscal", relperm_file, "--family2", "-o", "eclipse/include/props/relperm-fam2.inc", ] pyscalcli.main() assert os.path.exists("eclipse/include/props/relperm-fam2.inc") sys.argv = ["pyscal", relperm_file, "-o", "include/props/relperm.inc"] pyscalcli.main() assert os.path.exists("include/props/relperm.inc") # Check that we can read specific sheets sys.argv = [ "pyscal", relperm_file, "--sheet_name", "relperm", "--output", "relperm-firstsheet.inc", ] pyscalcli.main() # Identical files: assert len(open("relperm-firstsheet.inc").readlines()) == len( open("relperm.inc").readlines()) # Check that we can read specific sheets sys.argv = [ "pyscal", relperm_file, "--sheet_name", "simple", "--output", "relperm-secondsheet.inc", ] pyscalcli.main() secondsheet = "\n".join(open("relperm-secondsheet.inc").readlines()) assert "SATNUM 3" not in secondsheet assert "sand" in secondsheet assert "mud" in secondsheet # From the comment column in sheet: simple # Check that we can read specific sheets sys.argv = [ "pyscal", relperm_file, "--sheet_name", u"NOTEXISTINGÆÅ", "--output", "relperm-empty.inc", ] with pytest.raises(SystemExit): pyscalcli.main() assert not os.path.exists("relperm-empty.inc") sys.argv = [ "pyscal", relperm_file, "--delta_s", "0.1", "-o", "deltas0p1.inc" ] pyscalcli.main() linecount1 = len(open("deltas0p1.inc").readlines()) sys.argv = [ "pyscal", relperm_file, "--delta_s", "0.01", "-o", "deltas0p01.inc" ] pyscalcli.main() linecount2 = len(open("deltas0p01.inc").readlines()) assert linecount2 > linecount1 * 4 # since we don't filter out non-numerical lines sys.argv = ["pyscal", relperm_file, "--int_param_wo", "-0.5"]
def test_pyscal_endpoint_scal(tmpdir): """Test the command line endpoint on SCAL recommendation""" if "__file__" in globals(): # Easen up copying test code into interactive sessions testdir = os.path.dirname(os.path.abspath(__file__)) else: testdir = os.path.abspath(".") scalrec_file = testdir + "/data/scal-pc-input-example.xlsx" tmpdir.chdir() sys.argv = ["pyscal", scalrec_file] with pytest.raises(SystemExit): pyscalcli.main() sys.argv = [ "pyscal", scalrec_file, "--int_param_wo", 0, "-o", "relperm1.inc" ] pyscalcli.main() relpermlines = "\n".join(open("relperm1.inc").readlines()) assert "SWOF" in relpermlines assert "SGOF" in relpermlines assert "SLGOF" not in relpermlines assert "SOF3" not in relpermlines sat_table_str_ok(relpermlines) # assert "int_param_wo: 0\n" in relpermlines # this should be in the tag. sys.argv = [ "pyscal", scalrec_file, "--int_param_wo", "-0.5", "-o", "relperm2.inc" ] pyscalcli.main() # assert something about -0.5 in the comments # Only two interpolation parameters for three satnums: sys.argv = ["pyscal", scalrec_file, "--int_param_wo", "-0.5", "0"] with pytest.raises(SystemExit): pyscalcli.main() sys.argv = [ "pyscal", scalrec_file, "--int_param_wo", "-0.5", "0.0", "1.0", "-o", "relperm3.inc", ] pyscalcli.main() assert os.path.exists("relperm3.inc") # asserrt someting about three different parameters.. sys.argv = [ "pyscal", scalrec_file, "--int_param_wo", "-0.5", "0", "1", "--int_param_go", "0.9", "-o", "relperm4.inc", ] pyscalcli.main() assert os.path.exists("relperm4.inc") sys.argv = [ "pyscal", scalrec_file, "--int_param_wo", "-0.5", "0", "1", "--int_param_go", "0.9", "1", ] with pytest.raises(SystemExit): pyscalcli.main() sys.argv = [ "pyscal", scalrec_file, "--int_param_wo", "-0.5", "0", "1", "--int_param_go", "0.9", "1", "-0.5", "-o", "relperm5.inc", ] pyscalcli.main() assert os.path.exists("relperm5.inc")