From 89177a1e823e93a79b04ede3a5d135047183c4ba Mon Sep 17 00:00:00 2001 From: Per Olav Eide Svendsen Date: Fri, 8 Dec 2023 11:23:43 +0100 Subject: [PATCH 1/3] Test the methods in the Table class. --- ...regated_table.py => test_objects_table.py} | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) rename tests/{test_aggregated_table.py => test_objects_table.py} (72%) diff --git a/tests/test_aggregated_table.py b/tests/test_objects_table.py similarity index 72% rename from tests/test_aggregated_table.py rename to tests/test_objects_table.py index 0f5d955e..80434e51 100644 --- a/tests/test_aggregated_table.py +++ b/tests/test_objects_table.py @@ -1,4 +1,10 @@ -"""Testing of Aggregated table class""" +"""Test table objects. + + * Table + * AggregatedTable + * TableCollection + +""" import pandas as pd import pyarrow as pa from fmu.sumo.explorer import Explorer, AggregatedTable @@ -11,12 +17,37 @@ def fixture_explorer(token: str) -> Explorer: return Explorer("dev", token=token) -# @pytest.fixture(name="case") -# def case_fixture(): -# """Init of case""" -# exp = Explorer("dev") -# case = exp.cases.filter(name="drogon_ahm-2023-02-22")[0] -# return case +@pytest.fixture(name="table") +def fixture_table(token: str, explorer: Explorer): + """Get one table for further testing.""" + case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] + return case.tables[0] + + +def test_table_dataframe(table): + """Test the dataframe property.""" + with pytest.warns(DeprecationWarning, match=".dataframe is deprecated"): + df = table.dataframe + assert isinstance(df, pd.DataFrame) + + +def test_table_to_pandas(table): + """Test the to_pandas property.""" + df = table.to_pandas + assert isinstance(df, pd.DataFrame) + + +def test_arrowtable(table): + """Test the arrowtable property.""" + with pytest.warns(DeprecationWarning, match=".arrowtable is deprecated"): + arrow = table.arrowtable + assert isinstance(arrow, pa.Table) + + +def test_table_to_arrow(table): + """Test the to_arrow() method""" + arrow = table.to_arrow() + assert isinstance(arrow, pa.Table) def test_aggregated_summary_arrow(explorer: Explorer): From 569857a814d3efdc5154ce014c3f667f5cd49424 Mon Sep 17 00:00:00 2001 From: Per Olav Eide Svendsen Date: Fri, 8 Dec 2023 11:55:37 +0100 Subject: [PATCH 2/3] Make Tables.to_pandas a method, not a property. --- src/fmu/sumo/explorer/objects/table.py | 7 ++----- tests/test_objects_table.py | 20 ++++++-------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/fmu/sumo/explorer/objects/table.py b/src/fmu/sumo/explorer/objects/table.py index 71d02ef4..1fafaeb4 100644 --- a/src/fmu/sumo/explorer/objects/table.py +++ b/src/fmu/sumo/explorer/objects/table.py @@ -35,9 +35,9 @@ def dataframe(self) -> pd.DataFrame: DeprecationWarning, stacklevel=2, ) - return self.to_pandas + return self.to_pandas() + - @property def to_pandas(self) -> pd.DataFrame: """Return object as a pandas DataFrame @@ -106,9 +106,6 @@ async def to_pandas_async(self) -> pd.DataFrame: self._logger.debug("Read blob as %s to return pandas", worked) return self._dataframe - @to_pandas.setter - def to_pandas(self, frame: pd.DataFrame): - self._dataframe = frame @property def arrowtable(self) -> pa.Table: diff --git a/tests/test_objects_table.py b/tests/test_objects_table.py index 80434e51..e1076f29 100644 --- a/tests/test_objects_table.py +++ b/tests/test_objects_table.py @@ -23,6 +23,7 @@ def fixture_table(token: str, explorer: Explorer): case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] return case.tables[0] +### Table def test_table_dataframe(table): """Test the dataframe property.""" @@ -32,8 +33,8 @@ def test_table_dataframe(table): def test_table_to_pandas(table): - """Test the to_pandas property.""" - df = table.to_pandas + """Test the to_pandas method.""" + df = table.to_pandas() assert isinstance(df, pd.DataFrame) @@ -50,6 +51,8 @@ def test_table_to_arrow(table): assert isinstance(arrow, pa.Table) +### Aggregated Table + def test_aggregated_summary_arrow(explorer: Explorer): """Test usage of Aggregated class with default type""" @@ -96,18 +99,7 @@ def test_aggregated_summary_pandas(explorer: Explorer): """Test usage of Aggregated class with item_type=pandas""" case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] table = AggregatedTable(case, "summary", "eclipse", "iter-0") - assert isinstance(table["FOPT"].to_pandas, pd.DataFrame) - - -def test_aggregated_summary_pandas_with_deprecated_function_name( - explorer: Explorer, -): - """Test usage of Aggregated class with item_type=pandas with deprecated function name""" - case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] - table = AggregatedTable(case, "summary", "eclipse", "iter-0") - with pytest.warns(match=".dataframe is deprecated, renamed to .to_pandas()"): - mydata = table["FOPT"].dataframe - assert isinstance(mydata, pd.DataFrame) + assert isinstance(table["FOPT"].to_pandas(), pd.DataFrame) def test_get_fmu_iteration_parameters(explorer: Explorer): From a76cc90b58abbb9c7fa9aecdbcf40be38adb8c54 Mon Sep 17 00:00:00 2001 From: Per Olav Eide Svendsen Date: Fri, 8 Dec 2023 13:11:46 +0100 Subject: [PATCH 3/3] Use uuid for testcase and provide case with fixture. --- tests/test_objects_table.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/test_objects_table.py b/tests/test_objects_table.py index e1076f29..aecf2263 100644 --- a/tests/test_objects_table.py +++ b/tests/test_objects_table.py @@ -10,17 +10,22 @@ from fmu.sumo.explorer import Explorer, AggregatedTable import pytest +# Fixed test case ("Drogon_AHM_2023-02-22") in Sumo/DEV +TESTCASE_UUID = "10f41041-2c17-4374-a735-bb0de62e29dc" @pytest.fixture(name="explorer") def fixture_explorer(token: str) -> Explorer: """Returns explorer""" return Explorer("dev", token=token) +@pytest.fixture(name="case") +def fixture_case(explorer: Explorer): + """Return fixed testcase.""" + return explorer.get_case_by_uuid(TESTCASE_UUID) @pytest.fixture(name="table") -def fixture_table(token: str, explorer: Explorer): +def fixture_table(case): """Get one table for further testing.""" - case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] return case.tables[0] ### Table @@ -53,11 +58,9 @@ def test_table_to_arrow(table): ### Aggregated Table -def test_aggregated_summary_arrow(explorer: Explorer): +def test_aggregated_summary_arrow(case): """Test usage of Aggregated class with default type""" - case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] - table = AggregatedTable(case, "summary", "eclipse", "iter-0") assert len(table.columns) == 972 + 2 @@ -71,13 +74,9 @@ def test_aggregated_summary_arrow(explorer: Explorer): ) -def test_aggregated_summary_arrow_with_deprecated_function_name( - explorer: Explorer, -): +def test_aggregated_summary_arrow_with_deprecated_function_name(case): """Test usage of Aggregated class with default type with deprecated function name""" - case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] - table = AggregatedTable(case, "summary", "eclipse", "iter-0") assert len(table.columns) == 972 + 2 @@ -95,15 +94,13 @@ def test_aggregated_summary_arrow_with_deprecated_function_name( ) -def test_aggregated_summary_pandas(explorer: Explorer): +def test_aggregated_summary_pandas(case): """Test usage of Aggregated class with item_type=pandas""" - case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] table = AggregatedTable(case, "summary", "eclipse", "iter-0") assert isinstance(table["FOPT"].to_pandas(), pd.DataFrame) -def test_get_fmu_iteration_parameters(explorer: Explorer): +def test_get_fmu_iteration_parameters(case): """Test getting the metadata of of an object""" - case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0] table = AggregatedTable(case, "summary", "eclipse", "iter-0") assert isinstance(table.parameters, dict)