diff --git a/vizro-core/src/vizro/models/_components/_components_utils.py b/vizro-core/src/vizro/models/_components/_components_utils.py index 8723d2664..6f6e7c275 100644 --- a/vizro-core/src/vizro/models/_components/_components_utils.py +++ b/vizro-core/src/vizro/models/_components/_components_utils.py @@ -4,6 +4,7 @@ logger = logging.getLogger(__name__) + def _process_callable_data_frame(captured_callable, values): data_frame = captured_callable["data_frame"] diff --git a/vizro-core/src/vizro/models/types.py b/vizro-core/src/vizro/models/types.py index 5e204e66d..06272bcd3 100644 --- a/vizro-core/src/vizro/models/types.py +++ b/vizro-core/src/vizro/models/types.py @@ -225,6 +225,7 @@ def wrapped(*args, **kwargs): return wrapped elif self._mode == "table": + @functools.wraps(func) def wrapped(*args, **kwargs): if "data_frame" not in inspect.signature(func).parameters: diff --git a/vizro-core/src/vizro/tables/dash_table.py b/vizro-core/src/vizro/tables/dash_table.py index 31b197f4b..0ee68440c 100644 --- a/vizro-core/src/vizro/tables/dash_table.py +++ b/vizro-core/src/vizro/tables/dash_table.py @@ -9,7 +9,7 @@ from vizro.models.types import capture -def _set_defaults_nested(supplied: Mapping[str,Any], defaults: Mapping[str,Any]) -> dict[str,Any]: +def _set_defaults_nested(supplied: Mapping[str, Any], defaults: Mapping[str, Any]) -> dict[str, Any]: supplied = defaultdict(dict, supplied) for default_key, default_value in defaults.items(): if isinstance(default_value, Mapping): diff --git a/vizro-core/tests/unit/vizro/conftest.py b/vizro-core/tests/unit/vizro/conftest.py index 1048465f0..ba3cff2bd 100644 --- a/vizro-core/tests/unit/vizro/conftest.py +++ b/vizro-core/tests/unit/vizro/conftest.py @@ -25,6 +25,7 @@ def standard_px_chart(gapminder): size_max=60, ) + @pytest.fixture def standard_dash_table(gapminder): return dash_data_table(data_frame=gapminder) diff --git a/vizro-core/tests/unit/vizro/models/_components/test_table.py b/vizro-core/tests/unit/vizro/models/_components/test_table.py index e1c8d8ff1..db6aa1612 100644 --- a/vizro-core/tests/unit/vizro/models/_components/test_table.py +++ b/vizro-core/tests/unit/vizro/models/_components/test_table.py @@ -1,7 +1,6 @@ """Unit tests for vizro.models.Table.""" import json -import pandas as pd import plotly import pytest from dash import dash_table, html @@ -27,12 +26,12 @@ def dash_table_with_str_dataframe(): @pytest.fixture def expected_table(): return html.Div( - [ - None, - html.Div(dash_table.DataTable(), id="text_table"), - ], - className="table-container", - ) + [ + None, + html.Div(dash_table.DataTable(), id="text_table"), + ], + className="table-container", + ) class TestDunderMethodsTable: diff --git a/vizro-core/tests/unit/vizro/models/test_page.py b/vizro-core/tests/unit/vizro/models/test_page.py index 18d18ed5d..71313fb58 100644 --- a/vizro-core/tests/unit/vizro/models/test_page.py +++ b/vizro-core/tests/unit/vizro/models/test_page.py @@ -90,10 +90,15 @@ def test_set_layout_invalid(self): with pytest.raises(ValidationError, match="Number of page and grid components need to be the same."): vm.Page(title="Page 4", components=[vm.Button()], layout=vm.Layout(grid=[[0, 1]])) - def test_valid_component_types(self, standard_px_chart,standard_dash_table): + def test_valid_component_types(self, standard_px_chart, standard_dash_table): vm.Page( title="Page Title", - components=[vm.Graph(figure=standard_px_chart), vm.Card(text="""# Header 1"""), vm.Button(),vm.Table(figure=standard_dash_table)], + components=[ + vm.Graph(figure=standard_px_chart), + vm.Card(text="""# Header 1"""), + vm.Button(), + vm.Table(figure=standard_dash_table), + ], ) @pytest.mark.parametrize( diff --git a/vizro-core/tests/unit/vizro/tables/test_dash_table.py b/vizro-core/tests/unit/vizro/tables/test_dash_table.py index f95d38921..776c387a5 100644 --- a/vizro-core/tests/unit/vizro/tables/test_dash_table.py +++ b/vizro-core/tests/unit/vizro/tables/test_dash_table.py @@ -1,16 +1,22 @@ -from vizro.tables.dash_table import _set_defaults_nested import pytest +from vizro.tables.dash_table import _set_defaults_nested + + @pytest.fixture def default_dictionary(): - return {"a": {"b": {"c": 1, "d": 2}},"e": 3} + return {"a": {"b": {"c": 1, "d": 2}}, "e": 3} + -@pytest.mark.parametrize("input, expected_output", [ - ({},{"a": {"b": {"c": 1, "d": 2}},"e": 3}), # nothing supplied - ({'e': 10},{"a": {"b": {"c": 1, "d": 2}},"e": 10}), # flat main key - ({"a": {"b": {"c": 11, "d": 12}}},{"a": {"b": {"c": 11, "d": 12}},"e": 3}), # updated multiple nested keys - ({"a": {"b": {"c": 1, "d": {"f":42}}}},{"a": {"b": {"c": 1, "d": {"f":42}}},"e": 3}), # add new dict - ({"a": {"b": {"c": 5}}},{'a': {'b': {'c': 5, 'd': 2}},"e": 3}) #arbitrary nesting - ]) +@pytest.mark.parametrize( + "input, expected_output", + [ + ({}, {"a": {"b": {"c": 1, "d": 2}}, "e": 3}), # nothing supplied + ({"e": 10}, {"a": {"b": {"c": 1, "d": 2}}, "e": 10}), # flat main key + ({"a": {"b": {"c": 11, "d": 12}}}, {"a": {"b": {"c": 11, "d": 12}}, "e": 3}), # updated multiple nested keys + ({"a": {"b": {"c": 1, "d": {"f": 42}}}}, {"a": {"b": {"c": 1, "d": {"f": 42}}}, "e": 3}), # add new dict + ({"a": {"b": {"c": 5}}}, {"a": {"b": {"c": 5, "d": 2}}, "e": 3}), # arbitrary nesting + ], +) def test_set_defaults_nested(default_dictionary, input, expected_output): - assert _set_defaults_nested(input, default_dictionary) == expected_output \ No newline at end of file + assert _set_defaults_nested(input, default_dictionary) == expected_output