Skip to content

Commit

Permalink
Addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-qb committed Jan 22, 2025
1 parent 4f5e717 commit 7ccd58a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Uncomment the section that is right (remove the HTML comment wrapper).

### Fixed

- Enable arbitrarily deep nesting of custom components within lists or dicts. ([#929](https://github.com/mckinsey/vizro/pull/929))
- Enable arbitrarily deep nesting of custom components within lists, tuples or dictionaries. ([#929](https://github.com/mckinsey/vizro/pull/929))


<!--
Expand Down
16 changes: 9 additions & 7 deletions vizro-core/tests/unit/vizro/managers/test_model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def page_1(standard_px_chart):
)


@pytest.fixture
@pytest.fixture(autouse=True)
def managers_dashboard_two_pages(vizro_app, page_1, standard_kpi_card):
return vm.Dashboard(
pages=[
Expand All @@ -34,9 +34,6 @@ def managers_dashboard_two_pages(vizro_app, page_1, standard_kpi_card):
)


pytestmark = pytest.mark.usefixtures("managers_dashboard_two_pages")


class TestGetModels:
"""Test _get_models method."""

Expand All @@ -53,6 +50,8 @@ def test_model_type_none_page_none(self):
"page_2_figure_id",
}

# model_manager._get_models() returns all models in the dashboard, all along with Layout, Navigation, Dashboard
# models. That's the reason why we assert with the 'issubset' instead of 'equal'.
assert expected.issubset(result)

def test_model_type_page_none(self):
Expand Down Expand Up @@ -138,9 +137,12 @@ class CustomGraph(vm.Graph):
assert "page_1_graph_id" in vm_graph_result

# This test checks if the model manager can find model_type under a nested model.
# Using vm.Filter with a fixed ID as a pytest fixture causes DuplicationID errors during the test collection phase.
# Lazy instantiation via a lambda avoids this issue.
@pytest.mark.parametrize(
"get_nested_control",
"make_nested_control",
[
# "x" represents the vm.Filter model that is nested under another model.
# model as a property of a custom model
(lambda x: x),
# model inside a list
Expand All @@ -157,14 +159,14 @@ class CustomGraph(vm.Graph):
(lambda x: ((x,),)),
],
)
def test_nested_models(self, page_1, get_nested_control):
def test_nested_models(self, page_1, make_nested_control):
"""Model is nested under another model and known property in different ways -> return the model."""

class ControlGroup(vm.VizroBaseModel):
controls: Any

page_1.controls.append(
ControlGroup(controls=get_nested_control(vm.Filter(id="page_1_control_1", column="year")))
ControlGroup(controls=make_nested_control(vm.Filter(id="page_1_control_1", column="year")))
)

result = [model.id for model in model_manager._get_models(model_type=vm.Filter, page=page_1)]
Expand Down

0 comments on commit 7ccd58a

Please sign in to comment.