Exemplo n.º 1
0
def test_date_parsing(tmpdir):
    """Check that the ambiguous "DD MM YYYY" date format
    can be parsed "correctly" in input CSV files."""
    tmpdir.chdir()
    pd.DataFrame(
        columns=["DATE", "MD", "WELL_NAME", "PRESSURE"],
        data=[["01 03 2009", "100", "A-1", "123"]],
    ).to_csv("inputframe.csv", header=True, index=False)

    minimal_config = {"input_file": "inputframe.csv"}
    processed_config = check_and_parse_config(minimal_config)
    assert processed_config["input_dframe"]["DATE"].values[0] == np.datetime64(
        datetime.date(2009, 3, 1))
Exemplo n.º 2
0
def test_parse_alias_config(tmpdir):
    """Test that alias files can be parsed"""
    tmpdir.chdir()
    minimal_config = {
        "input_dframe":
        pd.DataFrame(columns=["DATE", "MD", "WELL_NAME", "PRESSURE"])
    }

    # Alias is defaulted to empty dict
    assert check_and_parse_config(minimal_config)["alias"] == {}

    # Empty alias dict ok to submit:
    check_and_parse_config({**minimal_config, **{"alias": {}}})

    assert (check_and_parse_config({
        **minimal_config,
        **{
            "alias": {
                "foo": "bar"
            }
        }
    })["alias"]["foo"] == "bar")

    # First with no header
    alias_dframe = pd.DataFrame(
        data=[["NO 33/44 A-1", "A-1"], ["NO 33/44 A-2", "A-2"]])
    alias_dframe.to_csv("alias.csv", index=False)
    with pytest.raises(ValueError):
        # pylint: disable=expression-not-assigned
        check_and_parse_config({
            **minimal_config,
            **{
                "alias_file": "alias.csv"
            }
        })["alias"]

    # Use default header names
    alias_dframe = pd.DataFrame(
        columns=["RMS_WELL_NAME", "ECLIPSE_WELL_NAME"],
        data=[["NO 33/44 A-1", "A-1"], ["NO 33/44 A-2", "A-2"]],
    )
    alias_dframe.to_csv("alias.csv", index=False)
    assert (check_and_parse_config({
        **minimal_config,
        **{
            "alias_file": "alias.csv"
        }
    })["alias"]["NO 33/44 A-1"] == "A-1")

    # Use custom header names for alias:
    alias_dframe = pd.DataFrame(
        columns=["RMS_NAME", "ECLIPSE_NAME"],
        data=[["NO 33/44 A-1", "A-1"], ["NO 33/44 A-2", "A-2"]],
    )
    alias_dframe.to_csv("alias.csv", index=False)
    assert (check_and_parse_config({
        **minimal_config,
        **{
            "alias_file": "alias.csv",
            "rms_name": "RMS_NAME",
            "ecl_name": "ECLIPSE_NAME",
        },
    })["alias"]["NO 33/44 A-1"] == "A-1")
Exemplo n.º 3
0
def test_configparsing(tmpdir, caplog):
    """Test that the function that validates and parses the config dictionary
    gives correct error messages, and returns a dict with defaults filled in"""

    with pytest.raises(TypeError):
        # pylint: disable=no-value-for-parameter
        check_and_parse_config()
    with pytest.raises(AssertionError):
        check_and_parse_config({})

    with pytest.raises(ValueError, match="Missing columns"):
        check_and_parse_config({"input_dframe": pd.DataFrame()})

    minimal_config = {
        "input_dframe":
        pd.DataFrame(
            columns=["DATE", "MD", "WELL_NAME", "PRESSURE"],
            data=[[
                np.datetime64(datetime.date(2020, 3, 12)), 1000, "C-19", 222
            ]],
        )
    }

    processed_df = check_and_parse_config(minimal_config)["input_dframe"]
    tmpdir.chdir()

    # Dump the dataframe to CSV and reload as disk dataframe:
    processed_df.to_csv("tmp.csv", index=False)
    viadisk_df = check_and_parse_config({"input_file":
                                         "tmp.csv"})["input_dframe"]
    pd.testing.assert_frame_equal(processed_df, viadisk_df, check_dtype=False)

    with pytest.raises(ValueError):
        check_and_parse_config({
            "input_dframe": pd.DataFrame(),
            "input_file": "tmp.csv"
        })

    check_and_parse_config({**minimal_config, **{"foobar": "com"}})
    assert "Unknown options ignored: {'foobar'}" in caplog.text

    assert check_and_parse_config(minimal_config)["exportdir"] == "."

    with pytest.raises(
            AssertionError,
            match="Only linear and cubic interpolation is supported"):
        check_and_parse_config({
            **minimal_config,
            **{
                "interpolation": "bilinear"
            }
        })

    with pytest.raises(AssertionError, match="create upfront"):
        check_and_parse_config({
            **minimal_config,
            **{
                "exportdir": "nonexistingdir"
            }
        })

    assert check_and_parse_config(
        minimal_config)["welldatefile"] == "well_date_rft.txt"