From 9110267582b55631ef9b68592e39bb339c85aa11 Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Wed, 8 Nov 2023 23:08:29 +0000 Subject: [PATCH] Revert changes to examples so that integration tests still pass --- ...230816_antony.milne_fix_assets_pathname.md | 48 +++++++++++++++++++ vizro-core/examples/default/app.py | 3 -- vizro-core/examples/from_dict/app.py | 1 - vizro-core/examples/from_json/app.py | 1 - vizro-core/examples/from_yaml/app.py | 1 - vizro-core/src/vizro/_vizro.py | 8 ++-- vizro-core/src/vizro/models/_dashboard.py | 2 +- vizro-core/tests/integration/test_examples.py | 1 - .../tests/unit/vizro/models/test_dashboard.py | 3 +- 9 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 vizro-core/changelog.d/20231108_230816_antony.milne_fix_assets_pathname.md diff --git a/vizro-core/changelog.d/20231108_230816_antony.milne_fix_assets_pathname.md b/vizro-core/changelog.d/20231108_230816_antony.milne_fix_assets_pathname.md new file mode 100644 index 000000000..f1f65e73c --- /dev/null +++ b/vizro-core/changelog.d/20231108_230816_antony.milne_fix_assets_pathname.md @@ -0,0 +1,48 @@ + + + + + + + + + diff --git a/vizro-core/examples/default/app.py b/vizro-core/examples/default/app.py index 65764fcd8..3bcce552b 100644 --- a/vizro-core/examples/default/app.py +++ b/vizro-core/examples/default/app.py @@ -1,8 +1,5 @@ """Example to show dashboard configuration.""" -import os -import dash -import flask import pandas as pd import vizro.models as vm diff --git a/vizro-core/examples/from_dict/app.py b/vizro-core/examples/from_dict/app.py index 6e41bbe53..f36641ef6 100644 --- a/vizro-core/examples/from_dict/app.py +++ b/vizro-core/examples/from_dict/app.py @@ -1,5 +1,4 @@ """Example to show dashboard configuration specified as a dictionary.""" -import os import pandas as pd diff --git a/vizro-core/examples/from_json/app.py b/vizro-core/examples/from_json/app.py index 282034888..900914bf3 100644 --- a/vizro-core/examples/from_json/app.py +++ b/vizro-core/examples/from_json/app.py @@ -1,6 +1,5 @@ """Example to show dashboard configuration specified as a JSON file.""" import json -import os from pathlib import Path import pandas as pd diff --git a/vizro-core/examples/from_yaml/app.py b/vizro-core/examples/from_yaml/app.py index eb74a043f..4ab29d514 100644 --- a/vizro-core/examples/from_yaml/app.py +++ b/vizro-core/examples/from_yaml/app.py @@ -1,5 +1,4 @@ """Example to show dashboard configuration specified as a YAML file.""" -import os from pathlib import Path import pandas as pd diff --git a/vizro-core/src/vizro/_vizro.py b/vizro-core/src/vizro/_vizro.py index 7f2fb6b15..907197449 100644 --- a/vizro-core/src/vizro/_vizro.py +++ b/vizro-core/src/vizro/_vizro.py @@ -1,7 +1,6 @@ import logging -import os -from pathlib import Path, PosixPath -from typing import Dict, List, Tuple +from pathlib import Path +from typing import List import dash import flask @@ -101,7 +100,8 @@ def _reset(): @staticmethod def _get_external_assets(new_path: str, folder: Path, extension: str) -> List[str]: """Returns a list of paths to assets with given extension in folder, prefixed with new_path. + e.g. with new_path="/vizro", extension="css", folder="/path/to/vizro/vizro-core/src/vizro/static", - we will get ["/vizro/css/accordion.css", "/vizro/css/button.css", ...] + we will get ["/vizro/css/accordion.css", "/vizro/css/button.css", ...]. """ return sorted((new_path / path.relative_to(folder)).as_posix() for path in folder.rglob(f"*.{extension}")) diff --git a/vizro-core/src/vizro/models/_dashboard.py b/vizro-core/src/vizro/models/_dashboard.py index c9a2025c6..11d482706 100644 --- a/vizro-core/src/vizro/models/_dashboard.py +++ b/vizro-core/src/vizro/models/_dashboard.py @@ -8,7 +8,7 @@ import dash_bootstrap_components as dbc import dash_daq as daq import plotly.io as pio -from dash import ClientsideFunction, Input, Output, clientside_callback, html, get_relative_path +from dash import ClientsideFunction, Input, Output, clientside_callback, get_relative_path, html from pydantic import Field, validator import vizro diff --git a/vizro-core/tests/integration/test_examples.py b/vizro-core/tests/integration/test_examples.py index f543e0928..85885b373 100644 --- a/vizro-core/tests/integration/test_examples.py +++ b/vizro-core/tests/integration/test_examples.py @@ -23,7 +23,6 @@ def setup_integration_test_environment(monkeypatch_session): # We only need to install chromedriver outside CI. if not os.getenv("CI"): chromedriver_autoinstaller_fix.install() - print("Done setting up integration test environment.") @pytest.fixture diff --git a/vizro-core/tests/unit/vizro/models/test_dashboard.py b/vizro-core/tests/unit/vizro/models/test_dashboard.py index 49ea53cdf..43353b85d 100644 --- a/vizro-core/tests/unit/vizro/models/test_dashboard.py +++ b/vizro-core/tests/unit/vizro/models/test_dashboard.py @@ -142,7 +142,8 @@ def test_dashboard_page_registry(self, dashboard, 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): + def test_create_layout_page_404(self, dashboard, mocker): + mocker.patch("vizro.models._dashboard.get_relative_path") result = dashboard._make_page_404_layout() result_image = result.children[0] result_div = result.children[1]