From 43178ce1eb79ddab805d92c8e5e0aca23b5ddb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Wed, 26 May 2021 13:37:54 +0200 Subject: [PATCH] Add parametrized tests for rmsvolumetrics --- setup.cfg | 1 - tests/rms/test_rmsvolumetrics.py | 108 +++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index bbed6581..8b8bcc95 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,7 +12,6 @@ ignore = E203, W503 test = pytest [tool:pytest] -addopts = --verbose -x markers = integration: marks a test as an integration test skipunlessroxar: skip this test unless Roxar license diff --git a/tests/rms/test_rmsvolumetrics.py b/tests/rms/test_rmsvolumetrics.py index 0860df6d..191131dc 100755 --- a/tests/rms/test_rmsvolumetrics.py +++ b/tests/rms/test_rmsvolumetrics.py @@ -14,6 +14,114 @@ TESTDIR = Path(__file__).parent / "volumetricsdata" +@pytest.mark.parametrize( + "multiline_str, filename, expected_df", + [ + pytest.param( + "", + "foo.txt", + None, + marks=pytest.mark.xfail(raises=pd.errors.EmptyDataError), + ), + pytest.param( + "foo bar", + "foo.txt", + None, + marks=pytest.mark.xfail(raises=pd.errors.EmptyDataError), + ), + pytest.param( + "Zone Bulk\nUpper 1", + "foo.txt", + pd.DataFrame([{"BULK": 1}]), + marks=pytest.mark.xfail( + raises=ValueError, reason="Not able to guess phase" + ), + ), + pytest.param( + "Zone Bulk\nUpper 1", + "oil.txt", + # This "fails" as there was not a double space between Zone and Bulk + pd.DataFrame([{"Zone Bulk": "Upper 1"}]), + ), + ( + # Two spaces: + "Zone Bulk\nUpper 1.0", + "oil.txt", + pd.DataFrame([{"ZONE": "Upper", "BULK_OIL": 1.0}]), + ), + ( + # Three spaces: + "Zone Bulk\nUpper 1.0", + "oil.txt", + pd.DataFrame([{"ZONE": "Upper", "BULK_OIL": 1.0}]), + ), + ( + # Tabs don't work: + "Zone\tBulk\nUpper\t1.0", + "oil.txt", + pd.DataFrame([{"Zone\tBulk": "Upper\t1.0"}]), + ), + ( + "Zone Bulk\nUpper 1.0", + "gas.txt", + pd.DataFrame([{"ZONE": "Upper", "BULK_GAS": 1.0}]), + ), + ( + # All supported columns: + "Zone Region index Facies License boundaries " + "Bulk Net Hcpv Pore Stoiip Assoc.Gas\n" + "Upper West GoodSand NO 2 1 1 1 1 0.1", + "oil.txt", + pd.DataFrame( + [ + { + "ZONE": "Upper", + "REGION": "West", + "FACIES": "GoodSand", + "LICENSE": "NO", + "BULK_OIL": 2, + "NET_OIL": 1, + "HCPV_OIL": 1, + "PORV_OIL": 1, + "STOIIP_OIL": 1, + "ASSOCIATEDGAS_OIL": 0.1, + } + ] + ), + ), + ( + # All supported columns: + "Zone Region index Facies License boundaries " + "Bulk Net Hcpv Pore Giip Assoc.Liquid\n" + "Upper West GoodSand NO 2 1 1 1 1 0.1", + "gas.txt", + pd.DataFrame( + [ + { + "ZONE": "Upper", + "REGION": "West", + "FACIES": "GoodSand", + "LICENSE": "NO", + "BULK_GAS": 2, + "NET_GAS": 1, + "HCPV_GAS": 1, + "PORV_GAS": 1, + "GIIP_GAS": 1, + "ASSOCIATEDOIL_GAS": 0.1, + } + ] + ), + ), + ], +) +def test_rms_to_volumetrics(multiline_str, filename, expected_df, tmpdir): + tmpdir.chdir() + Path(filename).write_text(multiline_str) + pd.testing.assert_frame_equal( + volumetrics.rmsvolumetrics_txt2df(filename), expected_df, check_like=True + ) + + def test_volumetrics(): """Test parsing of many real examples from RMS"""