-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cada8a
commit 611e639
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
vizro-core/tests/unit/vizro/_themes/test_create_chart_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pytest | ||
from pathlib import Path | ||
from unittest.mock import mock_open, patch | ||
|
||
from vizro._themes.create_chart_templates import _extract_last_two_occurrences, extract_bs_variables_from_css_file | ||
|
||
@pytest.fixture | ||
def css_content(): | ||
css_content = """ | ||
:root, [data-bs-theme=light] { | ||
--bs-primary: #007bff; | ||
--bs-tertiary-color: #adb5bd; | ||
} | ||
:root, [data-bs-theme=dark] { | ||
--bs-primary: #375a7f; | ||
--bs-secondary: #6c757d; | ||
} | ||
[data-bs-theme=light] { | ||
--bs-primary: #976fd1; | ||
--bs-secondary: #444fff; | ||
} | ||
""" | ||
|
||
return css_content | ||
|
||
@pytest.mark.parametrize( | ||
"variable, expected", | ||
[ | ||
("--bs-primary", ("#375a7f", "#976fd1")), | ||
("--bs-secondary", ("#6c757d", "#444fff")), | ||
("--bs-tertiary", (None, None)), | ||
], | ||
) | ||
def test_extract_last_two_occurrences(variable, css_content, expected): | ||
result_dark, result_light = _extract_last_two_occurrences(variable, css_content) | ||
assert (result_dark, result_light) == expected | ||
|
||
|
||
|
||
def test_extract_bs_variables_from_css_file(css_content): | ||
variables = ["--bs-primary", "--bs-secondary", "--bs-tertiary"] | ||
expected_dark = { | ||
"BS-PRIMARY": "#375a7f", | ||
"BS-SECONDARY": "#6c757d", | ||
"BS-TERTIARY": None, | ||
} | ||
expected_light = { | ||
"BS-PRIMARY": "#976fd1", | ||
"BS-SECONDARY": "#444fff", | ||
"BS-TERTIARY": None, | ||
} | ||
|
||
mock_path = Path("/fake/path/to/css/vizro-bootstrap.css") | ||
with patch("builtins.open", mock_open(read_data=css_content)): | ||
result_dark, result_light = extract_bs_variables_from_css_file(variables, mock_path) | ||
|
||
assert result_dark == expected_dark | ||
assert result_light == expected_light |