From 21ae973200e4ea5cf9fd57c59e002a6b06f58b3a Mon Sep 17 00:00:00 2001 From: huong-li-nguyen Date: Thu, 18 Jul 2024 15:53:58 +0200 Subject: [PATCH] Update test example --- vizro-core/examples/scratch_dev/app.py | 1 + .../unit/vizro/models/_components/test_figure.py | 10 ---------- vizro-core/tests/unit/vizro/models/conftest.py | 11 +++++++++++ .../tests/unit/vizro/models/test_models_utils.py | 8 +++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/vizro-core/examples/scratch_dev/app.py b/vizro-core/examples/scratch_dev/app.py index 6790994e5..f946e85dd 100644 --- a/vizro-core/examples/scratch_dev/app.py +++ b/vizro-core/examples/scratch_dev/app.py @@ -18,6 +18,7 @@ home = vm.Page( title="Page Title", components=[ + # kpi_card(data_frame=df_kpi, value_column="Actual", title="KPI with value"), vm.Figure(figure=kpi_card(data_frame=df_kpi, value_column="Actual", title="KPI with value")), ], ) diff --git a/vizro-core/tests/unit/vizro/models/_components/test_figure.py b/vizro-core/tests/unit/vizro/models/_components/test_figure.py index 45ebdf215..f432cb336 100644 --- a/vizro-core/tests/unit/vizro/models/_components/test_figure.py +++ b/vizro-core/tests/unit/vizro/models/_components/test_figure.py @@ -16,16 +16,6 @@ from vizro.managers import data_manager -@pytest.fixture -def kpi_card_with_dataframe(gapminder): - return kpi_card( - data_frame=gapminder, - value_column="lifeExp", - agg_func="mean", - value_format="{value:.3f}", - ) - - @pytest.fixture def kpi_card_with_str_dataframe(): return kpi_card( diff --git a/vizro-core/tests/unit/vizro/models/conftest.py b/vizro-core/tests/unit/vizro/models/conftest.py index a54540e6a..20ebfd650 100644 --- a/vizro-core/tests/unit/vizro/models/conftest.py +++ b/vizro-core/tests/unit/vizro/models/conftest.py @@ -1,5 +1,6 @@ import pytest import vizro.models as vm +from vizro.figures import kpi_card from vizro.models.types import capture @@ -15,3 +16,13 @@ def _identity_action_function(arg=None): @pytest.fixture(params=[vm.Container, vm.Page]) def model_with_layout(request): return request.param + + +@pytest.fixture +def kpi_card_with_dataframe(gapminder): + return kpi_card( + data_frame=gapminder, + value_column="lifeExp", + agg_func="mean", + value_format="{value:.3f}", + ) diff --git a/vizro-core/tests/unit/vizro/models/test_models_utils.py b/vizro-core/tests/unit/vizro/models/test_models_utils.py index 238cab404..689ae2ded 100644 --- a/vizro-core/tests/unit/vizro/models/test_models_utils.py +++ b/vizro-core/tests/unit/vizro/models/test_models_utils.py @@ -15,12 +15,14 @@ def test_validate_min_length(self, model_with_layout): with pytest.raises(ValidationError, match="Ensure this value has at least 1 item."): model_with_layout(title="Title", components=[]) - def test_check_captured_callable(self, model_with_layout, standard_px_chart): + def test_check_captured_callable(self, model_with_layout, kpi_card_with_dataframe): with pytest.raises( ValidationError, - match="A callable of mode `graph` has been provided. " "Please wrap it inside the `vm.Graph(figure=...)`.", + match=re.escape( + "A callable of mode `figure` has been provided. Please wrap it inside the `vm.Figure(figure=...)`." + ), ): - model_with_layout(title="Title", components=[standard_px_chart]) + model_with_layout(title="Title", components=[kpi_card_with_dataframe]) def test_check_for_valid_component_types(self, model_with_layout): with pytest.raises(