-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into docs/improve_custom_chart_docs
- Loading branch information
Showing
11 changed files
with
182 additions
and
79 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
vizro-core/changelog.d/20231219_171218_antony.milne_assert_components_equal.md
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,48 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Highlights ✨ | ||
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) | ||
--> | ||
<!-- | ||
### Removed | ||
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) | ||
--> | ||
<!-- | ||
### Added | ||
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) | ||
--> | ||
<!-- | ||
### Changed | ||
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) | ||
--> | ||
<!-- | ||
### Deprecated | ||
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) | ||
--> | ||
<!-- | ||
### Fixed | ||
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) | ||
--> | ||
<!-- | ||
### Security | ||
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) | ||
--> |
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
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
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
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,48 @@ | ||
"""Demo to show how to use asserts. These are not real tests that are run as part of testing, just a teaching aid.""" | ||
from typing import List | ||
|
||
from asserts import STRIP_ALL, assert_component_equal | ||
from dash import html | ||
|
||
from vizro.models import VizroBaseModel | ||
|
||
|
||
class X(VizroBaseModel): | ||
# Low-level contents model. | ||
text: str | ||
|
||
def build(self): | ||
return html.Div( | ||
[html.H1("Heading"), html.P(self.text, id=self.id), html.Hr(), html.H2("Something")], className="inner" | ||
) | ||
|
||
|
||
class Y(VizroBaseModel): | ||
# Higher-level container model. | ||
children: List[X] | ||
|
||
def build(self): | ||
return html.Div([child.build() for child in self.children], id=self.id, className="container") | ||
|
||
|
||
def test_X_build(): | ||
# Test for low-level contents: compare the whole component tree. | ||
# Sometimes setting keys_to_strip={"className"} is useful here. | ||
result = X(id="x", text="Hello world").build() | ||
expected = html.Div( | ||
[html.H1("Heading"), html.P("Hello world", id="x"), html.Hr(), html.H2("Something")], className="inner" | ||
) | ||
assert_component_equal(result, expected) | ||
|
||
|
||
def test_Y_build(): | ||
# Test for higher-level container. | ||
many_x = [X(text="Hello world") for _ in range(4)] | ||
result = Y(id="y", children=many_x).build() | ||
# We don't want to compare the whole component tree here. Instead compare the bit that's specifically in Y and | ||
# ignore the children: | ||
assert_component_equal(result, html.Div(id="y", className="container"), keys_to_strip={"children"}) | ||
# And also compare the "interface" between X and Y. Use STRIP_ALL to not look at any properties of the html.Div. | ||
# This is basically the same as doing: | ||
# assert all(isinstance(child, html.Div) for child in result.children) and len(result.children) == 4 | ||
assert_component_equal(result.children, [html.Div()] * 4, keys_to_strip=STRIP_ALL) |
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
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
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
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
Oops, something went wrong.