Skip to content

Commit

Permalink
Rename assert_component_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
antonymilne committed Nov 24, 2023
1 parent c7e8b49 commit 7fa028e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions vizro-core/tests/integration/test_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import vizro.models as vm

from asserts import assert_components_equal
from asserts import assert_component_equal
from vizro import Vizro
from vizro.managers import model_manager

Expand Down Expand Up @@ -152,4 +152,4 @@ def label_cases(cases, label):
def test_navigation_build(dashboard_result, dashboard_expected):
result = dashboard_result.navigation.build()
expected = dashboard_expected.navigation.build()
assert_components_equal(result, expected)
assert_component_equal(result, expected)
2 changes: 1 addition & 1 deletion vizro-core/tests/tests_utils/asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def component_to_dict(component: dash.development.base_component.Component) -> d

# TODO: implement some sort of depth limit to comparison so can use in high level tests, roll out more widely across
# tests
def assert_components_equal(left, right, keys_to_strip=None):
def assert_component_equal(left, right, keys_to_strip=None):
# Note we check for None explicitly because {} is a valid value for keys_to_strip.
keys_to_strip = keys_to_strip if keys_to_strip is not None else {"id", "class_name", "className"}
left = strip_keys(component_to_dict(left), keys_to_strip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pydantic import ValidationError

import vizro.models as vm
from asserts import assert_components_equal
from asserts import assert_component_equal

from vizro._constants import ACCORDION_DEFAULT_TITLE

Expand Down Expand Up @@ -111,9 +111,9 @@ class TestAccordionBuild:
@pytest.mark.parametrize("pages, expected", test_cases)
def test_accordion(self, pages, expected):
accordion = vm.Accordion(id="accordion", pages=pages).build(active_page_id="Page 1")
assert_components_equal(accordion, html.Div(id="nav_panel_outer"), keys_to_strip={"children", "className"})
assert_components_equal(accordion["accordion"], expected)
assert_component_equal(accordion, html.Div(id="nav_panel_outer"), keys_to_strip={"children", "className"})
assert_component_equal(accordion["accordion"], expected)

def test_accordion_one_page(self):
accordion = vm.Accordion(pages={"Group": ["Page 1"]}).build(active_page_id="Page 1")
assert_components_equal(accordion, html.Div(hidden=True, id="nav_panel_outer"), keys_to_strip={})
assert_component_equal(accordion, html.Div(hidden=True, id="nav_panel_outer"), keys_to_strip={})
18 changes: 9 additions & 9 deletions vizro-core/tests/unit/vizro/models/_navigation/test_nav_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import vizro.models as vm
import dash_bootstrap_components as dbc

from asserts import assert_components_equal
from asserts import assert_component_equal


@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard")
Expand Down Expand Up @@ -80,8 +80,8 @@ def test_nav_bar_active_pages_as_dict(self, pages_as_dict):
nav_bar.pre_build()
built_nav_bar = nav_bar.build(active_page_id="Page 1")
expected_button = html.Div([dbc.Button(children=[html.Span(children="filter_1")], active=True, href="/")])
assert_components_equal(built_nav_bar["nav_bar_outer"], expected_button)
assert_components_equal(
assert_component_equal(built_nav_bar["nav_bar_outer"], expected_button)
assert_component_equal(
built_nav_bar["nav_panel_outer"], html.Div(id="nav_panel_outer"), keys_to_strip={"children", "className"}
)
assert all(isinstance(child, dbc.Accordion) for child in built_nav_bar["nav_panel_outer"].children)
Expand All @@ -96,8 +96,8 @@ def test_nav_bar_active_pages_as_list(self, pages_as_list):
dbc.Button(children=[html.Span(children="filter_2")], active=False, href="/page-2"),
]
)
assert_components_equal(built_nav_bar["nav_bar_outer"], expected_buttons)
assert_components_equal(
assert_component_equal(built_nav_bar["nav_bar_outer"], expected_buttons)
assert_component_equal(
built_nav_bar["nav_panel_outer"], html.Div(id="nav_panel_outer"), keys_to_strip={"children", "className"}
)
assert all(isinstance(child, dbc.Accordion) for child in built_nav_bar["nav_panel_outer"].children)
Expand All @@ -107,8 +107,8 @@ def test_nav_bar_not_active_pages_as_dict(self, pages_as_dict):
nav_bar.pre_build()
built_nav_bar = nav_bar.build(active_page_id="Page 3")
expected_button = html.Div([dbc.Button(children=[html.Span(children="filter_1")], active=False, href="/")])
assert_components_equal(built_nav_bar["nav_bar_outer"], expected_button)
assert_components_equal(
assert_component_equal(built_nav_bar["nav_bar_outer"], expected_button)
assert_component_equal(
built_nav_bar["nav_panel_outer"], html.Div(hidden=True, id="nav_panel_outer"), keys_to_strip={}
)

Expand All @@ -122,8 +122,8 @@ def test_nav_bar_active_pages_as_list(self, pages_as_list):
dbc.Button(children=[html.Span(children="filter_2")], active=False, href="/page-2"),
]
)
assert_components_equal(built_nav_bar["nav_bar_outer"], expected_buttons)
assert_components_equal(
assert_component_equal(built_nav_bar["nav_bar_outer"], expected_buttons)
assert_component_equal(
built_nav_bar["nav_panel_outer"],
html.Div(id="nav_panel_outer", hidden=True),
keys_to_strip={"children", "className"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pydantic import ValidationError

import vizro.models as vm
from asserts import assert_components_equal
from asserts import assert_component_equal


@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard")
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_nav_link_active(self, pages, request):
nav_link.pre_build()
built_nav_link = nav_link.build(active_page_id="Page 1")
expected_button = dbc.Button(id="nav_link", children=[html.Span("icon")], active=True, href="/")
assert_components_equal(built_nav_link["nav_link"], expected_button)
assert_component_equal(built_nav_link["nav_link"], expected_button)
assert all(isinstance(child, dbc.Accordion) for child in built_nav_link["nav_panel_outer"].children)

def test_nav_link_not_active(self, pages, request):
Expand All @@ -84,5 +84,5 @@ def test_nav_link_not_active(self, pages, request):
nav_link.pre_build()
built_nav_link = nav_link.build(active_page_id="Page 3")
expected_button = dbc.Button(id="nav_link", children=[html.Span("icon")], active=False, href="/")
assert_components_equal(built_nav_link["nav_link"], expected_button)
assert_component_equal(built_nav_link["nav_link"], expected_button)
assert "nav_panel_outer" not in built_nav_link
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import ValidationError

import vizro.models as vm
from asserts import assert_components_equal
from asserts import assert_component_equal

import dash_bootstrap_components as dbc

Expand Down Expand Up @@ -82,12 +82,12 @@ def test_default_nav_selector(self, pages, request):
navigation = vm.Navigation(pages=pages)
navigation.pre_build()
built_navigation = navigation.build(active_page_id="Page 1")
assert_components_equal(
assert_component_equal(
built_navigation["nav_bar_outer"],
html.Div(className="hidden", id="nav_bar_outer"),
keys_to_strip={"children"},
)
assert_components_equal(
assert_component_equal(
built_navigation["nav_panel_outer"], html.Div(id="nav_panel_outer"), keys_to_strip={"children", "className"}
)
assert all(isinstance(child, dbc.Accordion) for child in built_navigation["nav_panel_outer"].children)
Expand All @@ -96,12 +96,12 @@ def test_non_default_nav_selector_pags_as_dict(self, pages_as_dict):
navigation = vm.Navigation(pages=pages_as_dict, nav_selector=vm.NavBar())
navigation.pre_build()
built_navigation = navigation.build(active_page_id="Page 1")
assert_components_equal(
assert_component_equal(
built_navigation["nav_bar_outer"],
html.Div(id="nav_bar_outer", className="nav-bar"),
keys_to_strip={"children"},
)
assert_components_equal(
assert_component_equal(
built_navigation["nav_panel_outer"],
html.Div(id="nav_panel_outer"),
keys_to_strip={"children", "className"},
Expand All @@ -112,12 +112,12 @@ def test_non_default_nav_selector_pages_as_list(self, pages_as_list):
navigation = vm.Navigation(pages=pages_as_list, nav_selector=vm.NavBar())
navigation.pre_build()
built_navigation = navigation.build(active_page_id="Page 1")
assert_components_equal(
assert_component_equal(
built_navigation["nav_bar_outer"],
html.Div(id="nav_bar_outer", className="nav-bar"),
keys_to_strip={"children"},
)
assert_components_equal(
assert_component_equal(
built_navigation["nav_panel_outer"],
html.Div(id="nav_panel_outer", hidden=True),
keys_to_strip={"children"},
Expand Down

0 comments on commit 7fa028e

Please sign in to comment.