Esempio n. 1
0
def test_df2vol(dframe, expected_lines):
    """Direct test of the dataframe to vol conversion, including a bonus test
    using ofmvol2csv to see that we can go back again and obtain the same
    dataframe."""
    volstr = csv2ofmvol.df2vol(dframe)
    assert isinstance(volstr, str)
    assert volstr

    # Compare strings, but ignore whitespace differences.
    assert [re.sub(r"\s+", " ", line) for line in volstr.split("\n")
            if line] == [re.sub(r"\s+", " ", line) for line in expected_lines]

    # Bonus test, convert back to dataframe with ofmvol2str:

    # Ensure dates in the multiindes are datetime types, needed for comparison.
    if not dframe.empty:
        dframe.index = dframe.index.set_levels(
            [dframe.index.levels[0],
             pd.to_datetime(dframe.index.levels[1])])

    # Need to convert column names also as in ofmvol2csv for comparison:
    dframe = dframe.rename(columns=csv2ofmvol.PDMCOLS2VOL)

    backagain_df = ofmvol2csv.process_volstr(volstr)
    if dframe.empty:
        assert backagain_df.empty
    else:
        # (bogus columns in dframe must be ignored)
        pd.testing.assert_frame_equal(
            dframe[backagain_df.columns].fillna(value=0.0), backagain_df)
Esempio n. 2
0
def test_process_volstr(inputlines, expected):
    """Test processing ofmvol strings, consisting of header data
    and well data"""
    if "DATE" in expected:
        expected["DATE"] = pd.to_datetime(expected["DATE"])
        expected.set_index(["WELL", "DATE"], inplace=True)
    dframe = ofmvol2csv.process_volstr("\n".join(inputlines))
    pd.testing.assert_frame_equal(dframe, expected)
Esempio n. 3
0
def test_errors(inputlines, expected_error):
    """Test some erros from ofmvol"""
    with pytest.raises(expected_error):
        ofmvol2csv.process_volstr("\n".join(inputlines))
Esempio n. 4
0
def test_errors(inputlines, expected_error):
    with pytest.raises(expected_error):
        ofmvol2csv.process_volstr("\n".join(inputlines))
Esempio n. 5
0
def test_process_volstr(inputlines, expected):
    if "DATE" in expected:
        expected["DATE"] = pd.to_datetime(expected["DATE"])
        expected.set_index(["WELL", "DATE"], inplace=True)
    dframe = ofmvol2csv.process_volstr("\n".join(inputlines))
    pd.testing.assert_frame_equal(dframe, expected)