Skip to content

Commit

Permalink
Update test example
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen committed Jul 18, 2024
1 parent d99def7 commit 21ae973
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions vizro-core/examples/scratch_dev/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
],
)
Expand Down
10 changes: 0 additions & 10 deletions vizro-core/tests/unit/vizro/models/_components/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions vizro-core/tests/unit/vizro/models/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import vizro.models as vm
from vizro.figures import kpi_card
from vizro.models.types import capture


Expand All @@ -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}",
)
8 changes: 5 additions & 3 deletions vizro-core/tests/unit/vizro/models/test_models_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 21ae973

Please sign in to comment.