diff --git a/pyproject.toml b/pyproject.toml index 1535a28ad..1ce3d8ab7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,6 @@ init_typed = true warn_required_dynamic_aliases = true warn_untyped_fields = true - [tool.ruff] # see: https://beta.ruff.rs/docs/rules/ ignore = [ diff --git a/vizro-core/docs/pages/tutorials/explore_components.md b/vizro-core/docs/pages/tutorials/explore_components.md index 6d750ae65..091f3277d 100644 --- a/vizro-core/docs/pages/tutorials/explore_components.md +++ b/vizro-core/docs/pages/tutorials/explore_components.md @@ -710,7 +710,7 @@ and how to bring them together. For future dashboard creations, you can explore more about the available dashboard `components` by going through the [user guide](../user_guides/components.md). To gain more in-depth knowledge about the usage and configuration details of `controls`, check out the user guides dedicated to [Filters](../user_guides/filters.md), [Parameters](../user_guides/parameters.md) -and [Selectors](../user_guides/selectors.md). If you'd like to understand more about different ways to configure the navigation of your dashboard, head +and [Selectors](../user_guides/selectors.md). If you'd like to understand more about different ways to configure the navigation of your dashboard, head to [Navigation](../user_guides/navigation.md). Vizro doesn't end here, and we only covered the key features, but there is still much more to explore! You can learn: diff --git a/vizro-core/docs/pages/user_guides/components.md b/vizro-core/docs/pages/user_guides/components.md index 2446fa3cb..7aea43d8a 100755 --- a/vizro-core/docs/pages/user_guides/components.md +++ b/vizro-core/docs/pages/user_guides/components.md @@ -402,8 +402,8 @@ and provide an attribute selector to select images with that matching URL hash. !!! note - This section describes how to use the [`Card`][vizro.models.Card] component to create a navigation - card. To configure the navigation panel on the left hand side of the screen, refer to the + This section describes how to use the [`Card`][vizro.models.Card] component to create a navigation + card. To configure the navigation panel on the left hand side of the screen, refer to the [guide on navigation](navigation.md). diff --git a/vizro-core/docs/pages/user_guides/navigation.md b/vizro-core/docs/pages/user_guides/navigation.md index 4771415ef..fd9a00166 100644 --- a/vizro-core/docs/pages/user_guides/navigation.md +++ b/vizro-core/docs/pages/user_guides/navigation.md @@ -2,7 +2,7 @@ This guide shows you how to use and customize the navigation that appears on the left of your dashboard. -The [`Dashboard`][vizro.models.Dashboard] model accepts a `navigation` argument, where you can enter a [`Navigation`][vizro.models.Navigation] model. This enables you to group pages together and customise how they appear in your navigation. +The [`Dashboard`][vizro.models.Dashboard] model accepts a `navigation` argument, where you can enter a [`Navigation`][vizro.models.Navigation] model. This enables you to group pages together and customize how they appear in your navigation. ## Using the default navigation @@ -14,9 +14,9 @@ By default, if the `navigation` argument is not specified, Vizro creates a navig from vizro import Vizro import vizro.plotly.express as px import vizro.models as vm - + iris = px.data.iris() - + page_1 = vm.Page( title="My first page", components=[ @@ -35,7 +35,7 @@ By default, if the `navigation` argument is not specified, Vizro creates a navig vm.Graph(figure=px.scatter(iris, x="sepal_length", y="sepal_width", color="species")), ], ) - + dashboard = vm.Dashboard(pages=[page_1, page_2, page_3]) Vizro().build(dashboard).run() ``` @@ -143,7 +143,7 @@ Another way to group together pages in the navigation is to use a [`NavBar`][viz !!! example "Using `NavBar`" === "app.py" ```py - # page_1, page_2, page_3 defined as in default example + # page_1, page_2, page_3 defined as in default example dashboard = vm.Dashboard( pages=[page_1, page_2, page_3], navigation=vm.Navigation( @@ -178,7 +178,7 @@ Here, the first level of the navigation hierarchy ("Group A" and "Group B") is r ## Customizing the navigation bar -Under the hood, [`NavBar`][vizro.models.NavBar] uses [`NavLink`][vizro.models.NavLink] to build the icons in the navigation bar. It is possible to customise the navigation further by providing the `NavLink`s yourself. +Under the hood, [`NavBar`][vizro.models.NavBar] uses [`NavLink`][vizro.models.NavLink] to build the icons in the navigation bar. It is possible to customize the navigation further by providing the `NavLink`s yourself. ### `NavLink` examples @@ -187,7 +187,7 @@ The same configuration for [grouping pages](#grouping-your-pages) applies inside !!! example "Accordions inside a `Navlink`" === "app.py" ```py - # page_1, page_2, page_3 defined as in default example + # page_1, page_2, page_3 defined as in default example dashboard = vm.Dashboard( pages=[page_1, page_2, page_3], navigation=vm.Navigation( @@ -213,7 +213,7 @@ The same configuration for [grouping pages](#grouping-your-pages) applies inside nav_selector: type: nav_bar items: - - label: Section 1 + - label: Section 1 pages: Group A: - My first page @@ -231,7 +231,7 @@ You can alter the icons used by specifying the name of the icon in the [Google M !!! example "Custom icon" === "app.py" ```py - # page_1, page_2, page_3 defined as in default example + # page_1, page_2, page_3 defined as in default example dashboard = vm.Dashboard( pages=[page_1, page_2, page_3], navigation=vm.Navigation( @@ -258,12 +258,12 @@ You can alter the icons used by specifying the name of the icon in the [Google M nav_selector: type: nav_bar items: - - label: Section 1 + - label: Section 1 icon: bar_chart pages: - My first page - My second page - - label: Section 1 + - label: Section 1 icon: pie_chart pages: - My third page @@ -271,4 +271,4 @@ You can alter the icons used by specifying the name of the icon in the [Google M === "Result" [![CustomIcons]][CustomIcons] - [CustomIcons]: ../../assets/user_guides/navigation/custom_icons.png \ No newline at end of file + [CustomIcons]: ../../assets/user_guides/navigation/custom_icons.png diff --git a/vizro-core/examples/from_yaml/dashboard.yaml b/vizro-core/examples/from_yaml/dashboard.yaml index 6e01fa8ca..b081f14ea 100644 --- a/vizro-core/examples/from_yaml/dashboard.yaml +++ b/vizro-core/examples/from_yaml/dashboard.yaml @@ -11,8 +11,8 @@ pages: type: graph title: My first page - components: - - text: My text here - type: card + - text: My text here + type: card title: My second page - components: - figure: @@ -36,4 +36,3 @@ navigation: icon: pie_chart pages: - My third page - diff --git a/vizro-core/hatch.toml b/vizro-core/hatch.toml index 866284d47..707b62da8 100644 --- a/vizro-core/hatch.toml +++ b/vizro-core/hatch.toml @@ -64,7 +64,7 @@ test-integration = [ "- pytest tests/integration/test_examples.py::test_json_dashboard --headless", "- pytest tests/integration/test_examples.py::test_yaml_dashboard --headless", "pytest tests/integration/test_navigation.py" - ] +] test-js = "./tools/run_jest.sh {args}" test-unit = "pytest tests/unit {args}" update-snyk-requirements = "python ../tools/generate_snyk_requirements.py {args}" diff --git a/vizro-core/pyproject.toml b/vizro-core/pyproject.toml index c323749bc..b65a2586f 100644 --- a/vizro-core/pyproject.toml +++ b/vizro-core/pyproject.toml @@ -66,7 +66,6 @@ branch = true parallel = true source_pkgs = ["vizro"] - [tool.pytest.ini_options] addopts = [ # Allow test files to have the same name in different directories. diff --git a/vizro-core/src/vizro/models/_dashboard.py b/vizro-core/src/vizro/models/_dashboard.py index d4c9d12fd..7619dfafa 100644 --- a/vizro-core/src/vizro/models/_dashboard.py +++ b/vizro-core/src/vizro/models/_dashboard.py @@ -15,12 +15,10 @@ from vizro.actions._action_loop._action_loop import ActionLoop from vizro.models import Navigation, VizroBaseModel from vizro.models._models_utils import _log_call - from vizro.models._navigation._navigation_utils import _NavBuildType if TYPE_CHECKING: from vizro.models import Page - from vizro.models._page import _PageBuildType logger = logging.getLogger(__name__) diff --git a/vizro-core/src/vizro/models/_navigation/_navigation_utils.py b/vizro-core/src/vizro/models/_navigation/_navigation_utils.py index 1d89eb50e..7bac806cd 100644 --- a/vizro-core/src/vizro/models/_navigation/_navigation_utils.py +++ b/vizro-core/src/vizro/models/_navigation/_navigation_utils.py @@ -29,7 +29,7 @@ def _validate_pages(pages): # This is just used for type checking. Ideally it would inherit from some dash.development.base_component.Component # (e.g. html.Div) as well as TypedDict, but that's not possible, and Dash does not have typing support anyway. When # this type is used, the object is actually still a dash.development.base_component.Component, but this makes it easier -# to see what contract the component fulfils by making the expected keys explicit. +# to see what contract the component fulfills by making the expected keys explicit. class _NavBuildType(TypedDict): nav_bar_outer: html.Div nav_panel_outer: html.Div diff --git a/vizro-core/src/vizro/models/_navigation/nav_bar.py b/vizro-core/src/vizro/models/_navigation/nav_bar.py index 32485578c..cdbc93427 100644 --- a/vizro-core/src/vizro/models/_navigation/nav_bar.py +++ b/vizro-core/src/vizro/models/_navigation/nav_bar.py @@ -8,7 +8,7 @@ from vizro.models import VizroBaseModel from vizro.models._models_utils import _log_call -from vizro.models._navigation._navigation_utils import _validate_pages, _NavBuildType +from vizro.models._navigation._navigation_utils import _NavBuildType, _validate_pages from vizro.models._navigation.nav_link import NavLink diff --git a/vizro-core/src/vizro/models/_navigation/navigation.py b/vizro-core/src/vizro/models/_navigation/navigation.py index 6b6f13102..d9ad6d22f 100644 --- a/vizro-core/src/vizro/models/_navigation/navigation.py +++ b/vizro-core/src/vizro/models/_navigation/navigation.py @@ -5,7 +5,7 @@ from vizro.models import VizroBaseModel from vizro.models._models_utils import _log_call -from vizro.models._navigation._navigation_utils import _validate_pages, _NavBuildType +from vizro.models._navigation._navigation_utils import _NavBuildType, _validate_pages from vizro.models._navigation.accordion import Accordion from vizro.models.types import NavPagesType, NavSelectorType diff --git a/vizro-core/src/vizro/models/_page.py b/vizro-core/src/vizro/models/_page.py index da84cf9da..06f36ddbd 100644 --- a/vizro-core/src/vizro/models/_page.py +++ b/vizro-core/src/vizro/models/_page.py @@ -18,7 +18,7 @@ # This is just used for type checking. Ideally it would inherit from some dash.development.base_component.Component # (e.g. html.Div) as well as TypedDict, but that's not possible, and Dash does not have typing support anyway. When # this type is used, the object is actually still a dash.development.base_component.Component, but this makes it easier -# to see what contract the component fulfils by making the expected keys explicit. +# to see what contract the component fulfills by making the expected keys explicit. class _PageBuildType(TypedDict): control_panel_outer: html.Div component_container_outer: html.Div diff --git a/vizro-core/tests/conftest.py b/vizro-core/tests/conftest.py index 7aaf6d0ab..3b71a917f 100644 --- a/vizro-core/tests/conftest.py +++ b/vizro-core/tests/conftest.py @@ -2,7 +2,6 @@ from vizro import Vizro - # Allow our custom assert functions in tests_utils/asserts.py to do introspection nicely still. # See https://pytest.org/en/7.4.x/how-to/assert.html#assertion-introspection-details pytest.register_assert_rewrite("asserts") @@ -16,10 +15,3 @@ def reset_managers(): Vizro._reset() yield Vizro._reset() - - -# AM: simplify this and dashboard fixtures -@pytest.fixture() -def vizro_app(): - """Fixture to instantiate Vizro/Dash app. Required when needing to register pages.""" - yield Vizro() diff --git a/vizro-core/tests/integration/test_navigation.py b/vizro-core/tests/integration/test_navigation.py index 771a02eaa..1910fd6e2 100644 --- a/vizro-core/tests/integration/test_navigation.py +++ b/vizro-core/tests/integration/test_navigation.py @@ -1,8 +1,7 @@ import pytest +from asserts import assert_component_equal import vizro.models as vm - -from asserts import assert_component_equal from vizro import Vizro from vizro.managers import model_manager diff --git a/vizro-core/tests/tests_utils/asserts.py b/vizro-core/tests/tests_utils/asserts.py index 5445dd733..1a32c93dd 100644 --- a/vizro-core/tests/tests_utils/asserts.py +++ b/vizro-core/tests/tests_utils/asserts.py @@ -9,7 +9,6 @@ def strip_keys(object, keys): This makes it easy to compare dictionaries generated from Dash components we've created that contain random IDs. """ - if isinstance(object, dict): object = {key: strip_keys(value, keys) for key, value in object.items() if key not in keys} elif isinstance(object, list): diff --git a/vizro-core/tests/unit/vizro/actions/_action_loop/test_get_action_loop_components.py b/vizro-core/tests/unit/vizro/actions/_action_loop/test_get_action_loop_components.py index d7698380f..9db0d3e4b 100644 --- a/vizro-core/tests/unit/vizro/actions/_action_loop/test_get_action_loop_components.py +++ b/vizro-core/tests/unit/vizro/actions/_action_loop/test_get_action_loop_components.py @@ -68,7 +68,7 @@ def trigger_to_actions_chain_mapper_component(request): @pytest.fixture -def managers_one_page_two_components_two_controls(dash_data_table_with_id): +def managers_one_page_two_components_two_controls(vizro_app, dash_data_table_with_id): """Instantiates managers with one page that contains two controls and two components.""" vm.Dashboard( pages=[ @@ -116,7 +116,7 @@ def managers_one_page_two_components_two_controls(dash_data_table_with_id): @pytest.fixture -def managers_one_page_no_actions(): +def managers_one_page_no_actions(vizro_app): """Instantiates managers with one "empty" page.""" vm.Dashboard( pages=[ @@ -134,7 +134,7 @@ def managers_one_page_no_actions(): class TestGetActionLoopComponents: """Tests getting required components for the action loop.""" - @pytest.mark.usefixtures("vizro_app", "managers_one_page_no_actions") + @pytest.mark.usefixtures("managers_one_page_no_actions") def test_no_components(self): result = _get_action_loop_components() result = json.loads(json.dumps(result, cls=plotly.utils.PlotlyJSONEncoder)) @@ -143,7 +143,7 @@ def test_no_components(self): assert result == expected - @pytest.mark.usefixtures("vizro_app", "managers_one_page_two_components_two_controls") + @pytest.mark.usefixtures("managers_one_page_two_components_two_controls") @pytest.mark.parametrize( "gateway_components, " "action_trigger_components, " diff --git a/vizro-core/tests/unit/vizro/conftest.py b/vizro-core/tests/unit/vizro/conftest.py index 92e7bb625..4d6914e6b 100644 --- a/vizro-core/tests/unit/vizro/conftest.py +++ b/vizro-core/tests/unit/vizro/conftest.py @@ -5,6 +5,7 @@ import vizro.models as vm import vizro.plotly.express as px +from vizro import Vizro from vizro.tables import dash_data_table @@ -42,16 +43,28 @@ def standard_go_chart(gapminder): @pytest.fixture() -def page1(): - return vm.Page(title="Page 1", components=[vm.Button(), vm.Button()]) +def page_1(): + return vm.Page(title="Page 1", components=[vm.Button()]) @pytest.fixture() -def page2(): - return vm.Page(title="Page 2", components=[vm.Button(), vm.Button()]) +def page_2(): + return vm.Page(title="Page 2", components=[vm.Button()]) @pytest.fixture() -def dashboard(page1, page2): - dashboard = vm.Dashboard(pages=[page1, page2]) +def vizro_app(): + """Fixture to instantiate Vizro/Dash app. + + Required if Vizro._pre_build or dashboard.pre_build is called since dash.register_page can only be called after + app instantiation.pages. + """ + return Vizro() + + +@pytest.fixture() +def prebuilt_two_page_dashboard(vizro_app, page_1, page_2): + """Minimal two page dashboard, used mainly for testing navigation.""" + dashboard = vm.Dashboard(pages=[page_1, page_2]) + dashboard.pre_build() return dashboard diff --git a/vizro-core/tests/unit/vizro/models/_navigation/conftest.py b/vizro-core/tests/unit/vizro/models/_navigation/conftest.py index 6f010a015..200ada86e 100644 --- a/vizro-core/tests/unit/vizro/models/_navigation/conftest.py +++ b/vizro-core/tests/unit/vizro/models/_navigation/conftest.py @@ -3,11 +3,6 @@ import pytest -@pytest.fixture() -def prebuilt_dashboard(dashboard): - dashboard.pre_build() - - @pytest.fixture() def pages_as_list(): return ["Page 1", "Page 2"] diff --git a/vizro-core/tests/unit/vizro/models/_navigation/test_accordion.py b/vizro-core/tests/unit/vizro/models/_navigation/test_accordion.py index 739660285..894275c73 100644 --- a/vizro-core/tests/unit/vizro/models/_navigation/test_accordion.py +++ b/vizro-core/tests/unit/vizro/models/_navigation/test_accordion.py @@ -1,19 +1,18 @@ """Unit tests for vizro.models.Accordion.""" -import json import re import dash_bootstrap_components as dbc import pytest +from asserts import assert_component_equal from dash import html from pydantic import ValidationError import vizro.models as vm -from asserts import assert_component_equal - from vizro._constants import ACCORDION_DEFAULT_TITLE +pytestmark = pytest.mark.usefixtures("prebuilt_two_page_dashboard") + -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestAccordionInstantiation: """Tests accordion model instantiation.""" @@ -49,7 +48,6 @@ def test_invalid_page(self, pages): vm.Accordion(pages=pages) -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestAccordionBuild: """Tests accordion build method.""" diff --git a/vizro-core/tests/unit/vizro/models/_navigation/test_nav_bar.py b/vizro-core/tests/unit/vizro/models/_navigation/test_nav_bar.py index 0a629534b..d8b40515c 100644 --- a/vizro-core/tests/unit/vizro/models/_navigation/test_nav_bar.py +++ b/vizro-core/tests/unit/vizro/models/_navigation/test_nav_bar.py @@ -1,17 +1,17 @@ """Unit tests for vizro.models.NavBar.""" import re +import dash_bootstrap_components as dbc import pytest +from asserts import assert_component_equal from dash import html from pydantic import ValidationError import vizro.models as vm -import dash_bootstrap_components as dbc -from asserts import assert_component_equal +pytestmark = pytest.mark.usefixtures("prebuilt_two_page_dashboard") -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestNavBarInstantiation: """Tests NavBar model instantiation.""" @@ -51,7 +51,6 @@ def test_invalid_page(self, pages): vm.NavBar(pages=pages) -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestNavBarPreBuildMethod: def test_default_items(self, pages_as_dict): nav_bar = vm.NavBar(pages=pages_as_dict) @@ -71,7 +70,6 @@ def test_items_with_with_pages_icons(self, pages_as_dict): assert nav_bar.items[1].icon == "filter_2" -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestNavBarBuildMethod: """Tests NavBar model build method.""" @@ -112,7 +110,7 @@ def test_nav_bar_not_active_pages_as_dict(self, pages_as_dict): built_nav_bar["nav_panel_outer"], html.Div(hidden=True, id="nav_panel_outer"), keys_to_strip={} ) - def test_nav_bar_active_pages_as_list(self, pages_as_list): + def test_nav_bar_not_active_pages_as_list(self, pages_as_list): nav_bar = vm.NavBar(pages=pages_as_list) nav_bar.pre_build() built_nav_bar = nav_bar.build(active_page_id="Page 3") diff --git a/vizro-core/tests/unit/vizro/models/_navigation/test_nav_item.py b/vizro-core/tests/unit/vizro/models/_navigation/test_nav_item.py index 010e79377..6e54e3bc9 100644 --- a/vizro-core/tests/unit/vizro/models/_navigation/test_nav_item.py +++ b/vizro-core/tests/unit/vizro/models/_navigation/test_nav_item.py @@ -3,14 +3,15 @@ import dash_bootstrap_components as dbc import pytest +from asserts import assert_component_equal from dash import html from pydantic import ValidationError import vizro.models as vm -from asserts import assert_component_equal + +pytestmark = pytest.mark.usefixtures("prebuilt_two_page_dashboard") -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestNavLinkInstantiation: """Tests NavLink model instantiation.""" @@ -55,7 +56,6 @@ def test_invalid_page(self, pages): vm.NavLink(pages=pages) -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestNavLinkPreBuildMethod: def test_nav_link(self, pages_as_dict): nav_link = vm.NavLink(label="Label", pages=pages_as_dict) @@ -64,7 +64,6 @@ def test_nav_link(self, pages_as_dict): assert nav_link._nav_selector.pages == pages_as_dict -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") @pytest.mark.parametrize("pages", ["pages_as_dict", "pages_as_list"]) class TestNavLinkBuildMethod: """Tests NavLink model build method.""" diff --git a/vizro-core/tests/unit/vizro/models/_navigation/test_navigation.py b/vizro-core/tests/unit/vizro/models/_navigation/test_navigation.py index 86577ec11..73abd6fdc 100644 --- a/vizro-core/tests/unit/vizro/models/_navigation/test_navigation.py +++ b/vizro-core/tests/unit/vizro/models/_navigation/test_navigation.py @@ -1,17 +1,17 @@ """Unit tests for vizro.models.Navigation.""" import re +import dash_bootstrap_components as dbc import pytest +from asserts import assert_component_equal from dash import html from pydantic import ValidationError import vizro.models as vm -from asserts import assert_component_equal -import dash_bootstrap_components as dbc +pytestmark = pytest.mark.usefixtures("prebuilt_two_page_dashboard") -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestNavigationInstantiation: def test_navigation_mandatory_only(self): navigation = vm.Navigation() @@ -45,7 +45,6 @@ def test_invalid_page(self, pages): vm.Navigation(pages=pages) -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestNavigationPreBuildMethod: def test_default_nav_selector(self, pages_as_dict): navigation = vm.Navigation(pages=pages_as_dict) @@ -72,7 +71,6 @@ def test_non_default_nav_selector_with_pages(self, pages_as_dict): assert navigation.nav_selector.pages == {"Group": ["Page 1"]} -@pytest.mark.usefixtures("vizro_app", "prebuilt_dashboard") class TestNavigationBuildMethod: """Tests navigation model build method.""" diff --git a/vizro-core/tests/unit/vizro/models/test_dashboard.py b/vizro-core/tests/unit/vizro/models/test_dashboard.py index 59320b2f6..1977b6419 100644 --- a/vizro-core/tests/unit/vizro/models/test_dashboard.py +++ b/vizro-core/tests/unit/vizro/models/test_dashboard.py @@ -29,7 +29,7 @@ def dashboard_container(): @pytest.fixture() -def mock_page_registry(dashboard, page1, page2): +def mock_page_registry(prebuilt_two_page_dashboard, page_1, page_2): return OrderedDict( { "Page 1": { @@ -44,12 +44,12 @@ def mock_page_registry(dashboard, page1, page2): "description": "", "order": 0, "supplied_order": 0, - "supplied_layout": partial(dashboard._make_page_layout, page1), + "supplied_layout": partial(prebuilt_two_page_dashboard._make_page_layout, page_1), "supplied_image": None, "image": None, "image_url": None, "redirect_from": None, - "layout": partial(dashboard._make_page_layout, page1), + "layout": partial(prebuilt_two_page_dashboard._make_page_layout, page_1), "relative_path": "/", }, "Page 2": { @@ -64,12 +64,12 @@ def mock_page_registry(dashboard, page1, page2): "description": "", "order": 1, "supplied_order": 1, - "supplied_layout": partial(dashboard._make_page_layout, page2), + "supplied_layout": partial(prebuilt_two_page_dashboard._make_page_layout, page_2), "supplied_image": None, "image": None, "image_url": None, "redirect_from": None, - "layout": partial(dashboard._make_page_layout, page2), + "layout": partial(prebuilt_two_page_dashboard._make_page_layout, page_2), "relative_path": "/page-2", }, "not_found_404": { @@ -84,12 +84,12 @@ def mock_page_registry(dashboard, page1, page2): "description": "", "order": None, "supplied_order": None, - "supplied_layout": dashboard._make_page_404_layout(), + "supplied_layout": prebuilt_two_page_dashboard._make_page_404_layout(), "supplied_image": None, "image": None, "image_url": None, "redirect_from": None, - "layout": dashboard._make_page_404_layout(), + "layout": prebuilt_two_page_dashboard._make_page_404_layout(), "relative_path": "/not-found-404", }, } @@ -99,30 +99,30 @@ def mock_page_registry(dashboard, page1, page2): class TestDashboardInstantiation: """Tests model instantiation and the validators run at that time.""" - def test_create_dashboard_mandatory_only(self, page1, page2): - dashboard = vm.Dashboard(pages=[page1, page2]) + def test_create_dashboard_mandatory_only(self, page_1, page_2): + dashboard = vm.Dashboard(pages=[page_1, page_2]) assert hasattr(dashboard, "id") - assert dashboard.pages == [page1, page2] + assert dashboard.pages == [page_1, page_2] assert dashboard.theme == "vizro_dark" assert dashboard.title is None assert isinstance(dashboard.navigation, vm.Navigation) assert dashboard.navigation.pages == ["Page 1", "Page 2"] - def test_create_dashboard_mandatory_and_optional(self, page1, page2): - dashboard = vm.Dashboard(pages=[page1, page2], theme="vizro_light", title="Vizro") + def test_create_dashboard_mandatory_and_optional(self, page_1, page_2): + dashboard = vm.Dashboard(pages=[page_1, page_2], theme="vizro_light", title="Vizro") assert hasattr(dashboard, "id") - assert dashboard.pages == [page1, page2] + assert dashboard.pages == [page_1, page_2] assert dashboard.theme == "vizro_light" assert dashboard.title == "Vizro" assert isinstance(dashboard.navigation, vm.Navigation) assert dashboard.navigation.pages == ["Page 1", "Page 2"] - def test_navigation_pages_automatically_populated(self, page1, page2): - dashboard = vm.Dashboard(pages=[page1, page2]) + def test_navigation_pages_automatically_populated(self, page_1, page_2): + dashboard = vm.Dashboard(pages=[page_1, page_2]) assert dashboard.navigation.pages == ["Page 1", "Page 2"] - def test_navigation_with_pages(self, page1, page2): - dashboard = vm.Dashboard(pages=[page1, page2], navigation=vm.Navigation(pages=["Page 1"])) + def test_navigation_with_pages(self, page_1, page_2): + dashboard = vm.Dashboard(pages=[page_1, page_2], navigation=vm.Navigation(pages=["Page 1"])) assert dashboard.navigation.pages == ["Page 1"] def test_mandatory_pages_missing(self): @@ -137,25 +137,23 @@ def test_field_invalid_pages_input_type(self): with pytest.raises(ValidationError, match="4 validation errors for Dashboard"): vm.Dashboard(pages=[vm.Button()]) - def test_field_invalid_theme_input_type(self, page1): + def test_field_invalid_theme_input_type(self, page_1): with pytest.raises(ValidationError, match="unexpected value; permitted: 'vizro_dark', 'vizro_light'"): - vm.Dashboard(pages=[page1], theme="not_existing") + vm.Dashboard(pages=[page_1], theme="not_existing") class TestDashboardPreBuild: """Tests dashboard pre_build method.""" - @pytest.mark.usefixtures("vizro_app") - def test_dashboard_page_registry(self, dashboard, mock_page_registry): - dashboard.pre_build() + def test_dashboard_page_registry(self, prebuilt_two_page_dashboard, mock_page_registry): result = dash.page_registry expected = mock_page_registry # Str conversion required as comparison of OrderedDict values result in False otherwise assert str(result.items()) == str(expected.items()) - def test_create_layout_page_404(self, dashboard, mocker): + def test_create_layout_page_404(self, prebuilt_two_page_dashboard, mocker): mocker.patch("vizro.models._dashboard.get_relative_path") - result = dashboard._make_page_404_layout() + result = prebuilt_two_page_dashboard._make_page_404_layout() result_image = result.children[0] result_div = result.children[1] @@ -164,12 +162,10 @@ def test_create_layout_page_404(self, dashboard, mocker): assert isinstance(result_div, html.Div) -@pytest.mark.usefixtures("vizro_app") class TestDashboardBuild: """Tests dashboard build method.""" - def test_dashboard_build(self, dashboard_container, dashboard): - dashboard.pre_build() - result = json.loads(json.dumps(dashboard.build(), cls=plotly.utils.PlotlyJSONEncoder)) + def test_dashboard_build(self, dashboard_container, prebuilt_two_page_dashboard): + result = json.loads(json.dumps(prebuilt_two_page_dashboard.build(), cls=plotly.utils.PlotlyJSONEncoder)) expected = json.loads(json.dumps(dashboard_container, cls=plotly.utils.PlotlyJSONEncoder)) assert result == expected diff --git a/vizro-core/tests/unit/vizro/models/test_types.py b/vizro-core/tests/unit/vizro/models/test_types.py index 0d7042ec7..910c30b7b 100644 --- a/vizro-core/tests/unit/vizro/models/test_types.py +++ b/vizro-core/tests/unit/vizro/models/test_types.py @@ -1,5 +1,4 @@ import importlib -from pathlib import Path import plotly.express as plotly_express import plotly.graph_objects as go