예제 #1
0
def test_fm_pyscal_errors(raises, dframe, runargs, tmpdir):
    """Test that fm_pyscal or pyscal gives correct errors to
    common misusages"""
    tmpdir.chdir()
    if dframe is not None:
        if runargs[0].endswith("csv"):
            dframe.to_csv(runargs[0])
        else:
            dframe.to_excel(runargs[0])
    if dframe is not None and "CASE" in dframe:
        with open("parameters.txt", "w") as p_file:
            p_file.write("INTERPOLATE_WO 0.1\nINTERPOLATE_GO 0.5")

    with pytest.raises(raises):
        run(*runargs)
예제 #2
0
def test_fm_pyscal_errors(dframe, runargs, err_str, tmpdir, caplog):
    """Test that fm_pyscal sys.exits and gives a correct error message
    to common mistakes"""
    tmpdir.chdir()
    if dframe is not None:
        if runargs[0].endswith("csv"):
            dframe.to_csv(runargs[0])
        else:
            dframe.to_excel(runargs[0])
    if dframe is not None and "CASE" in dframe:
        with open("parameters.txt", "w") as p_file:
            p_file.write("INTERPOLATE_WO 0.1\nINTERPOLATE_GO 0.5")

    with pytest.raises(SystemExit):
        run(*runargs)

    assert err_str in caplog.text
예제 #3
0
def test_fm_pyscal(dframe, runargs, tmpdir):
    """Parametrized test function for fm_pyscal"""
    tmpdir.chdir()
    dframe.to_csv("relperm-input.csv", index=False)

    # Insert a genkw-prefix in some parameters.txt files:
    if random.randint(0, 1):
        genkw_prefix = "FOO:"
    else:
        genkw_prefix = ""

    if "CASE" in dframe:
        with open("parameters.txt", "w") as p_file:
            p_file.write("INTERPOLATE_WO 0.1\n" + genkw_prefix +
                         "INTERPOLATE_GO 0.5")

    run(*(["relperm-input.csv", "relperm.inc"] + runargs))
    assert os.path.exists("relperm.inc")
    assert len(open("relperm.inc").readlines()) > 20
예제 #4
0
def test_fm_pysal_static_xlsx(tmpdir):
    """Test fm_pyscal on a static xlsx file"""
    tmpdir.chdir()
    EXAMPLE_STATIC_DFRAME.to_excel("relperm-input.xlsx")
    run("relperm-input.xlsx", "relperm.inc", "", "__NONE__", "__NONE__",
        "slgof", 1)

    # pylint: disable=abstract-class-instantiated
    with pd.ExcelWriter("relperm-sheets.xlsx") as writer:
        EXAMPLE_STATIC_DFRAME.to_excel(writer, sheet_name="static")
        EXAMPLE_WATEROIL.to_excel(writer, sheet_name="wateroil")
    run("relperm-sheets.xlsx", "static.inc", "static", "__NONE__", "__NONE__",
        "sgof", 1)
    assert os.path.exists("static.inc")
    assert "SGOF" in "".join(open("static.inc").readlines())
    run(
        "relperm-sheets.xlsx",
        "wateroil.inc",
        "wateroil",
        "__NONE__",
        "__NONE__",
        "sgof",
        1,
    )
    assert os.path.exists("wateroil.inc")
    assert "SGOF" not in "".join(open("wateroil.inc").readlines())