Skip to content

Commit

Permalink
Rearrange test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
antonymilne committed Nov 28, 2023
1 parent 6efabd2 commit 5f5ceba
Show file tree
Hide file tree
Showing 24 changed files with 83 additions and 102 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/docs/pages/tutorials/explore_components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions vizro-core/docs/pages/user_guides/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).


Expand Down
24 changes: 12 additions & 12 deletions vizro-core/docs/pages/user_guides/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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=[
Expand All @@ -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()
```
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -258,17 +258,17 @@ 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
```
=== "Result"
[![CustomIcons]][CustomIcons]

[CustomIcons]: ../../assets/user_guides/navigation/custom_icons.png
[CustomIcons]: ../../assets/user_guides/navigation/custom_icons.png
5 changes: 2 additions & 3 deletions vizro-core/examples/from_yaml/dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -36,4 +36,3 @@ navigation:
icon: pie_chart
pages:
- My third page

2 changes: 1 addition & 1 deletion vizro-core/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 0 additions & 1 deletion vizro-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions vizro-core/src/vizro/models/_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_navigation/nav_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions vizro-core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
3 changes: 1 addition & 2 deletions vizro-core/tests/integration/test_navigation.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion vizro-core/tests/tests_utils/asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down Expand Up @@ -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=[
Expand All @@ -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))
Expand All @@ -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, "
Expand Down
25 changes: 19 additions & 6 deletions vizro-core/tests/unit/vizro/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
5 changes: 0 additions & 5 deletions vizro-core/tests/unit/vizro/models/_navigation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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."""

Expand Down Expand Up @@ -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."""

Expand Down
Loading

0 comments on commit 5f5ceba

Please sign in to comment.