code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def extract_bs_variables_from_css(variables: list[str], css_content: str) -> tuple[dict[str, str], dict[str, str]]:
"""Extract the last two occurrences for each variable in the CSS file."""
extracted_dark = {}
extracted_light = {}
for variable in variables:
dark_value, light_value = _extract_la... | Extract the last two occurrences for each variable in the CSS file. | extract_bs_variables_from_css | python | mckinsey/vizro | vizro-core/src/vizro/_themes/generate_plotly_templates.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/src/vizro/_themes/generate_plotly_templates.py | Apache-2.0 |
def generate_json_template(extracted_values: dict[str, str]) -> go.layout.Template:
"""Generates the Plotly JSON chart template."""
FONT_COLOR_PRIMARY = extracted_values["BS-PRIMARY"]
BG_COLOR = extracted_values["BS-BODY-BG"]
FONT_COLOR_SECONDARY = extracted_values["BS-SECONDARY"]
GRID_COLOR = extra... | Generates the Plotly JSON chart template. | generate_json_template | python | mckinsey/vizro | vizro-core/src/vizro/_themes/generate_plotly_templates.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/src/vizro/_themes/generate_plotly_templates.py | Apache-2.0 |
def create_template_common() -> go.layout.Template:
"""Creates template with common values for dark and light theme.
Returns: A plotly template object, see https://plotly.com/python/reference/layout/.
"""
COLORS = get_colors()
template_common = go.layout.Template()
template_common.layout = go.L... | Creates template with common values for dark and light theme.
Returns: A plotly template object, see https://plotly.com/python/reference/layout/.
| create_template_common | python | mckinsey/vizro | vizro-core/src/vizro/_themes/_common_template.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/src/vizro/_themes/_common_template.py | Apache-2.0 |
def dash_br_driver(dash_br, request):
"""Built-in driver from the dash library."""
port = request.param.get("port", cnst.DEFAULT_PORT) if hasattr(request, "param") else cnst.DEFAULT_PORT
path = request.param.get("path", "") if hasattr(request, "param") else ""
dash_br.driver.set_window_size(1920, 1080)
... | Built-in driver from the dash library. | dash_br_driver | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/conftest.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/conftest.py | Apache-2.0 |
def teardown_method(dash_br):
"""Fixture checks log errors and quits the driver after each test."""
yield
# checking for browser console errors
if os.getenv("BROWSER") in ["chrome", "chrome_mobile"]:
try:
error_logs = [log for log in dash_br.get_logs() if log["level"] == "SEVERE" or ... | Fixture checks log errors and quits the driver after each test. | teardown_method | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/conftest.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/conftest.py | Apache-2.0 |
def bar_with_highlight(data_frame, x, highlight_bar=None):
"""Custom chart to test using DatePicker with Parameter."""
fig = px.bar(data_frame=data_frame, x=x)
fig["data"][0]["marker"]["color"] = ["orange" if c == highlight_bar else "blue" for c in fig["data"][0]["x"]]
return fig | Custom chart to test using DatePicker with Parameter. | bar_with_highlight | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/custom_components/custom_charts/bar_custom.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/custom_components/custom_charts/bar_custom.py | Apache-2.0 |
def test_export_filtered_data(dash_br):
"""Test exporting filtered data. It is prefiltered in dashboard config."""
page_select(
dash_br,
page_path=cnst.FILTERS_PAGE_PATH,
page_name=cnst.FILTERS_PAGE,
)
# download files and compare it with base ones
dash_br.multiple_click(but... | Test exporting filtered data. It is prefiltered in dashboard config. | test_export_filtered_data | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_actions.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_actions.py | Apache-2.0 |
def test_scatter_click_data_custom_action(dash_br):
"""Test custom action for changing data in card by interacting with graph."""
page_select(
dash_br,
page_name=cnst.FILTER_INTERACTIONS_PAGE,
)
# click on the dot in the scatter graph and check card text values
dash_br.click_at_coor... | Test custom action for changing data in card by interacting with graph. | test_scatter_click_data_custom_action | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_actions.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_actions.py | Apache-2.0 |
def test_modebar(dash_br):
"""Check that modebar element exist for the chart."""
dash_br.multiple_click(f"a[href='{cnst.FILTERS_PAGE_PATH}']", 1)
dash_br.wait_for_element(f"#{cnst.SCATTER_GRAPH_ID} .modebar-container div[id^='modebar']") | Check that modebar element exist for the chart. | test_modebar | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_charts.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_charts.py | Apache-2.0 |
def test_modebar_false(dash_br):
"""Check that modebar element disabled for the chart."""
dash_br.multiple_click(f"a[href='{cnst.FILTERS_PAGE_PATH}']", 1)
graph_load_waiter(dash_br, cnst.BOX_GRAPH_ID)
dash_br.wait_for_no_elements(f'div[id="{cnst.BOX_GRAPH_ID}"] .modebar-container div[id^="modebar"]') | Check that modebar element disabled for the chart. | test_modebar_false | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_charts.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_charts.py | Apache-2.0 |
def test_custom_dropdown(dash_br):
"""Testing setting up and filter of the custom dropdown."""
page_select(
dash_br,
page_name=cnst.CUSTOM_COMPONENTS_PAGE,
)
# choose 'versicolor' value
select_dropdown_value(dash_br, value=2, dropdown_id=cnst.CUSTOM_DROPDOWN_ID)
check_graph_is_lo... | Testing setting up and filter of the custom dropdown. | test_custom_dropdown | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_custom_components.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_custom_components.py | Apache-2.0 |
def test_custom_range_slider(dash_br):
"""Testing setting up and filter of the custom range slider."""
page_select(
dash_br,
page_name=cnst.CUSTOM_COMPONENTS_PAGE,
)
dash_br.multiple_click(slider_value_path(elem_id=cnst.CUSTOM_RANGE_SLIDER_ID, value=4), 1)
check_graph_is_loading(dash... | Testing setting up and filter of the custom range slider. | test_custom_range_slider | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_custom_components.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_custom_components.py | Apache-2.0 |
def test_single_date(dash_br):
"""Tests that single datepicker as filter works correctly."""
accordion_select(dash_br, accordion_name=cnst.DATEPICKER_ACCORDION)
page_select(
dash_br,
page_name=cnst.DATEPICKER_PAGE,
)
# open datepicker calendar and choose date 17 May 2016
dash_br... | Tests that single datepicker as filter works correctly. | test_single_date | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_datepicker.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_datepicker.py | Apache-2.0 |
def test_single_date_param(dash_br):
"""Tests that single datepicker as parameter works correctly."""
accordion_select(dash_br, accordion_name=cnst.DATEPICKER_ACCORDION)
page_select(
dash_br,
page_name=cnst.DATEPICKER_PARAMS_PAGE,
)
# check that specific bar has blue color
dash_b... | Tests that single datepicker as parameter works correctly. | test_single_date_param | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_datepicker.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_datepicker.py | Apache-2.0 |
def test_data_dynamic_parametrization(dash_br, cache, slider_id):
"""This test checks parametrized data loading and how it is working with and without cache."""
first_screen = f"{cache}_screen_first_test_data_dynamic_parametrization.png"
second_screen = f"{cache}_screen_second_test_data_dynamic_parametrizat... | This test checks parametrized data loading and how it is working with and without cache. | test_data_dynamic_parametrization | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_dynamic_data.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_dynamic_data.py | Apache-2.0 |
def test_numerical_filters(dash_br):
"""Initial selected value for slider is 6. Initial selected values for range_slider are 6 and 7."""
accordion_select(dash_br, accordion_name=cnst.DYNAMIC_DATA_ACCORDION)
page_select(
dash_br,
page_name=cnst.DYNAMIC_FILTERS_NUMERICAL_PAGE,
)
# Set... | Initial selected value for slider is 6. Initial selected values for range_slider are 6 and 7. | test_numerical_filters | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_dynamic_data.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_dynamic_data.py | Apache-2.0 |
def test_dynamic_data_parameter_refresh_dynamic_filters(dash_br):
"""Test automatic refreshing of the dynamic filters and their targets when the data_frame parameter is changed.
Page configuration includes dynamic data scatter chart which controls by slider parameter and static data scatter
which has 'virg... | Test automatic refreshing of the dynamic filters and their targets when the data_frame parameter is changed.
Page configuration includes dynamic data scatter chart which controls by slider parameter and static data scatter
which has 'virginica' data only.
| test_dynamic_data_parameter_refresh_dynamic_filters | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_dynamic_data.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_dynamic_data.py | Apache-2.0 |
def test_dropdown_homepage(dash_br):
"""Test dropdown filter for the homepage."""
graph_load_waiter(dash_br, graph_id=cnst.AREA_GRAPH_ID)
# select 'setosa'
select_dropdown_value(dash_br, value=2, dropdown_id=cnst.DROPDOWN_FILTER_HOMEPAGEPAGE)
check_graph_is_loading(dash_br, cnst.AREA_GRAPH_ID) | Test dropdown filter for the homepage. | test_dropdown_homepage | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_filters.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_filters.py | Apache-2.0 |
def test_filter_and_parameter(dash_br):
"""Testing filter and parameter on the same page."""
page_select(
dash_br,
page_name=cnst.FILTER_AND_PARAM_PAGE,
)
# check that title of the graph is 'blue'
dash_br.wait_for_text_to_equal(".gtitle", "blue")
# select 'red' value in the rad... | Testing filter and parameter on the same page. | test_filter_and_parameter | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_filter_and_param_config.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_filter_and_param_config.py | Apache-2.0 |
def test_interactions(dash_br):
"""Test filter interactions between two graphs."""
page_select(
dash_br,
page_name=cnst.FILTER_INTERACTIONS_PAGE,
)
# click on the 'setosa' data in scatter graph and check result for box graph
dash_br.click_at_coord_fractions(f"#{cnst.SCATTER_INTERACT... | Test filter interactions between two graphs. | test_interactions | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_interactions.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_interactions.py | Apache-2.0 |
def test_pages(dash_br):
"""Test of going from homepage to filters page and back using card link."""
# open homepage and check title text
graph_load_waiter(dash_br, graph_id=cnst.AREA_GRAPH_ID)
dash_br.wait_for_text_to_equal(page_title_path(), cnst.HOME_PAGE)
# open filters page using card link and... | Test of going from homepage to filters page and back using card link. | test_pages | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_pages.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_pages.py | Apache-2.0 |
def test_active_accordion(dash_br):
"""Test opening page from card link and checking appropriate accordion is opened."""
graph_load_waiter(dash_br, graph_id=cnst.AREA_GRAPH_ID)
dash_br.multiple_click(nav_card_link_path(href=f"/{cnst.DATEPICKER_PAGE}"), 1)
graph_load_waiter(dash_br, graph_id=cnst.BAR_POP... | Test opening page from card link and checking appropriate accordion is opened. | test_active_accordion | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_pages.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_pages.py | Apache-2.0 |
def test_404_page(dash_br):
"""Test opening page that doesn't exist."""
graph_load_waiter(dash_br, graph_id=cnst.AREA_GRAPH_ID)
dash_br.multiple_click(nav_card_link_path(href=cnst.PAGE_404_PATH), 1)
dash_br.wait_for_text_to_equal("a[class='mt-4 btn btn-primary']", "Take me home")
dash_br.multiple_cl... | Test opening page that doesn't exist. | test_404_page | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_pages.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_pages.py | Apache-2.0 |
def test_sliders_state(dash_br):
"""Verify that sliders values stays the same after page reload."""
page_select(
dash_br,
page_path=cnst.PARAMETERS_PAGE_PATH,
page_name=cnst.PARAMETERS_PAGE,
)
# change slider value to '0.4'
dash_br.multiple_click(slider_value_path(elem_id=cn... | Verify that sliders values stays the same after page reload. | test_sliders_state | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_parameters.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_parameters.py | Apache-2.0 |
def test_none_parameter(dash_br):
"""Test if one of the parameter values is NONE."""
page_select(
dash_br,
page_path=cnst.PARAMETERS_PAGE_PATH,
page_name=cnst.PARAMETERS_PAGE,
)
# check that specific bar has blue color
dash_br.wait_for_element(
f"div[id='{cnst.BAR_GR... | Test if one of the parameter values is NONE. | test_none_parameter | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_parameters.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_parameters.py | Apache-2.0 |
def test_parameters_title(chrome_driver, dash_br):
"""Tests that graph title is changing by parameter independently for every user."""
# select parameters page for the first user
page_select_selenium(
chrome_driver,
page_path=cnst.PARAMETERS_PAGE_PATH,
page_name=cnst.PARAMETERS_PAGE,... | Tests that graph title is changing by parameter independently for every user. | test_parameters_title | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_statelessness.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_statelessness.py | Apache-2.0 |
def test_theme_color(chrome_driver, dash_br):
"""Tests that theme color is changing independently for every user."""
# select parameters page for the first user
page_select_selenium(
chrome_driver,
page_path=cnst.PARAMETERS_PAGE_PATH,
page_name=cnst.PARAMETERS_PAGE,
)
# sele... | Tests that theme color is changing independently for every user. | test_theme_color | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_statelessness.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_statelessness.py | Apache-2.0 |
def test_export_action(chrome_driver, dash_br):
"""Tests that export action is giving different results according to what every user filters."""
# select filters page for the first user
page_select_selenium(
chrome_driver,
page_path=cnst.FILTERS_PAGE_PATH,
page_name=cnst.FILTERS_PAGE... | Tests that export action is giving different results according to what every user filters. | test_export_action | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_statelessness.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_statelessness.py | Apache-2.0 |
def test_interactions(dash_br):
"""Test filter interaction between table and line graph."""
accordion_select(dash_br, accordion_name=cnst.AG_GRID_ACCORDION)
page_select(
dash_br,
page_name=cnst.TABLE_INTERACTIONS_PAGE,
)
# click on Bosnia and Herzegovina country
dash_br.multiple_... | Test filter interaction between table and line graph. | test_interactions | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_table.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_table.py | Apache-2.0 |
def test_interactions(dash_br):
"""Test filter interaction between ag_grid and line graph."""
accordion_select(dash_br, accordion_name=cnst.AG_GRID_ACCORDION)
page_select(
dash_br,
page_name=cnst.TABLE_AG_GRID_INTERACTIONS_PAGE,
)
# check if column 'country' is available
dash_br... | Test filter interaction between ag_grid and line graph. | test_interactions | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_table_ag_grid.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_table_ag_grid.py | Apache-2.0 |
def test_themes(dash_br_driver, dashboard_id):
"""Test switching the themes and checking the graph and theme color."""
page_select(dash_br_driver, page_path=cnst.FILTERS_PAGE_PATH, page_name=cnst.FILTERS_PAGE)
if dashboard_id == cnst.DASHBOARD_DEFAULT:
# dashboard loaded with light theme
ch... | Test switching the themes and checking the graph and theme color. | test_themes | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_themes.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_themes.py | Apache-2.0 |
def test_themes_page_change(dash_br_driver, dashboard_id):
"""Test switching themes after reloading the page with two tabs."""
page_select(
dash_br_driver,
page_path=cnst.PARAMETERS_PAGE_PATH,
page_name=cnst.PARAMETERS_PAGE,
)
def _logic(style_background, graph_color, theme_colo... | Test switching themes after reloading the page with two tabs. | test_themes_page_change | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_dom_elements/test_themes.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_dom_elements/test_themes.py | Apache-2.0 |
def image_assertion(func):
"""Wait until all callbacks are finished and compare screenshots."""
def wrapper(dash_br, request):
result = func(dash_br)
callbacks_finish_waiter(dash_br)
time.sleep(1) # to finish page loading
result_image_path, expected_image_path = make_screenshot... | Wait until all callbacks are finished and compare screenshots. | image_assertion | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_screenshots/test_screenshots.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_screenshots/test_screenshots.py | Apache-2.0 |
def test_collapsible_subcontainers_flex(dash_br):
"""Test that after closing subcontainer the parent container is still open."""
accordion_select(dash_br, accordion_name=cnst.LAYOUT_ACCORDION)
page_select(dash_br, page_name=cnst.COLLAPSIBLE_CONTAINERS_FLEX)
# close subcontainer
dash_br.multiple_cli... | Test that after closing subcontainer the parent container is still open. | test_collapsible_subcontainers_flex | python | mckinsey/vizro | vizro-core/tests/e2e/vizro/test_screenshots/test_screenshots.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/e2e/vizro/test_screenshots/test_screenshots.py | Apache-2.0 |
def _strip_keys(object, keys):
"""Strips from a JSON `object` all entries where the key is in keys, regardless of how deeply it's nested."""
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):
... | Strips from a JSON `object` all entries where the key is in keys, regardless of how deeply it's nested. | _strip_keys | python | mckinsey/vizro | vizro-core/tests/tests_utils/asserts.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/asserts.py | Apache-2.0 |
def assert_component_equal(left, right, *, keys_to_strip=None):
"""Checks that the `left` and `right` Dash components are equal, ignoring `keys_to_strip`.
Args:
left: Dash component to compare.
right: Dash component to compare.
keys_to_strip: Keys to strip from the component dictionary ... | Checks that the `left` and `right` Dash components are equal, ignoring `keys_to_strip`.
Args:
left: Dash component to compare.
right: Dash component to compare.
keys_to_strip: Keys to strip from the component dictionary before comparison.
If keys_to_strip is set to STRIP_ALL the... | assert_component_equal | python | mckinsey/vizro | vizro-core/tests/tests_utils/asserts.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/asserts.py | Apache-2.0 |
def make_screenshot_and_paths(driver, request_node_name):
"""Creates image paths and makes screenshot during the test run."""
result_image_path = f"{request_node_name}_branch.png"
expected_image_path = (
f"tests/e2e/screenshots/{os.getenv('BROWSER', 'chrome')}/{request_node_name.replace('test', 'mai... | Creates image paths and makes screenshot during the test run. | make_screenshot_and_paths | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/asserts.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/asserts.py | Apache-2.0 |
def assert_image_equal(result_image_path, expected_image_path):
"""Comparison logic and diff files creation."""
expected_image_name = Path(expected_image_path).name
try:
assert_pixelmatch(result_image_path, expected_image_path)
Path(result_image_path).unlink()
except subprocess.CalledPro... | Comparison logic and diff files creation. | assert_image_equal | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/asserts.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/asserts.py | Apache-2.0 |
def browser_console_warnings_checker(log_level, log_levels):
"""Whitelist for browser console errors and its assert."""
assert_that(
log_level["message"],
any_of(
contains_string(cnst.INVALID_PROP_ERROR),
contains_string(cnst.REACT_NOT_RECOGNIZE_ERROR),
contai... | Whitelist for browser console errors and its assert. | browser_console_warnings_checker | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/vizro/checkers.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/vizro/checkers.py | Apache-2.0 |
def check_graph_is_loading_selenium(driver, graph_id, timeout=cnst.SELENIUM_WAITERS_TIMEOUT):
"""Waiting for graph to start reloading for pure selenium."""
WebDriverWait(driver, timeout).until(
expected_conditions.presence_of_element_located(
(By.CSS_SELECTOR, f"div[id='{graph_id}'][data-das... | Waiting for graph to start reloading for pure selenium. | check_graph_is_loading_selenium | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/vizro/checkers.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/vizro/checkers.py | Apache-2.0 |
def check_selected_categorical_component(driver, component_id, options_value_status):
"""Checks what selected and what is not for checklist and radio items.
Args:
driver: dash_br fixture
component_id: id of checklist or radio items
options_value_status: list of dicts with the next synta... | Checks what selected and what is not for checklist and radio items.
Args:
driver: dash_br fixture
component_id: id of checklist or radio items
options_value_status: list of dicts with the next syntax
[{
"value": int, number of the value inside dom structure,
... | check_selected_categorical_component | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/vizro/checkers.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/vizro/checkers.py | Apache-2.0 |
def accordion_select(driver, accordion_name):
"""Selecting accordion and checking if it is active."""
accordion_name = accordion_name.upper()
click_element_by_xpath_selenium(driver, f"//button[text()='{accordion_name}']")
check_accordion_active(driver, accordion_name)
# to let accordion open
tim... | Selecting accordion and checking if it is active. | accordion_select | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/vizro/navigation.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/vizro/navigation.py | Apache-2.0 |
def page_select(driver, page_name, graph_check=True, page_path=None):
"""Selecting page and checking if it has proper title."""
page_path = page_path if page_path else f"/{page_name}"
driver.multiple_click(f"a[href='{page_path}']", 1)
driver.wait_for_contains_text(page_title_path(), page_name)
if g... | Selecting page and checking if it has proper title. | page_select | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/vizro/navigation.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/vizro/navigation.py | Apache-2.0 |
def page_select_selenium(driver, page_path, page_name, timeout=cnst.SELENIUM_WAITERS_TIMEOUT, graph_check=True):
"""Selecting page and checking if it has proper title for pure selenium."""
WebDriverWait(driver, timeout).until(
expected_conditions.element_to_be_clickable((By.CSS_SELECTOR, f"a[href='{page... | Selecting page and checking if it has proper title for pure selenium. | page_select_selenium | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/vizro/navigation.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/vizro/navigation.py | Apache-2.0 |
def select_dropdown_value(driver, value, dropdown_id, multi=True):
"""Steps to select value in dropdown."""
dropdown_path = f"div[id='{dropdown_id}']"
if multi:
driver.multiple_click(f"{dropdown_path} .Select-clear", 1)
driver.multiple_click(f"{dropdown_path} .Select-arrow", 1)
driver.multip... | Steps to select value in dropdown. | select_dropdown_value | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/vizro/navigation.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/vizro/navigation.py | Apache-2.0 |
def graph_load_waiter_selenium(driver, graph_id, timeout=cnst.SELENIUM_WAITERS_TIMEOUT):
"""Waiting for graph's x-axis to appear for pure selenium."""
WebDriverWait(driver, timeout).until(
expected_conditions.presence_of_element_located(
(By.CSS_SELECTOR, f"div[id='{graph_id}'] path[class='x... | Waiting for graph's x-axis to appear for pure selenium. | graph_load_waiter_selenium | python | mckinsey/vizro | vizro-core/tests/tests_utils/e2e/vizro/waiters.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/tests_utils/e2e/vizro/waiters.py | Apache-2.0 |
def managers_one_page_two_graphs_with_dynamic_data(box_chart_dynamic_data_frame, scatter_chart_dynamic_data_frame):
"""Instantiates a simple model_manager and data_manager with a page, two graph models and the button component."""
vm.Page(
id="test_page",
title="My first dashboard",
comp... | Instantiates a simple model_manager and data_manager with a page, two graph models and the button component. | managers_one_page_two_graphs_with_dynamic_data | python | mckinsey/vizro | vizro-core/tests/unit/vizro/conftest.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/conftest.py | Apache-2.0 |
def page_actions_builtin_controls(standard_px_chart):
"""Instantiates managers with one page that contains filter, parameter, and filter_interaction actions."""
vm.Page(
title="title",
components=[
vm.Graph(
id="graph_1",
figure=standard_px_chart,
... | Instantiates managers with one page that contains filter, parameter, and filter_interaction actions. | page_actions_builtin_controls | python | mckinsey/vizro | vizro-core/tests/unit/vizro/conftest.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/conftest.py | Apache-2.0 |
def manager_for_testing_actions_output_input_prop(ag_grid_with_id):
"""Instantiates the model_manager using a Dropdown (has default input and output properties)."""
# We have to use one of the selectors as the known-model as currently only the selectors have both
# input and output properties defined. There... | Instantiates the model_manager using a Dropdown (has default input and output properties). | manager_for_testing_actions_output_input_prop | python | mckinsey/vizro | vizro-core/tests/unit/vizro/conftest.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/conftest.py | Apache-2.0 |
def managers_one_page_two_graphs_one_table_one_aggrid_one_button(
box_chart, scatter_chart, dash_data_table_with_id, ag_grid_with_id
):
"""Instantiates a simple model_manager and data_manager with: page, graphs, table, aggrid and button component."""
vm.Page(
id="test_page",
title="My first ... | Instantiates a simple model_manager and data_manager with: page, graphs, table, aggrid and button component. | managers_one_page_two_graphs_one_table_one_aggrid_one_button | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/conftest.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/conftest.py | Apache-2.0 |
def managers_one_page_one_graph_with_dict_param_input(scatter_matrix_chart):
"""Instantiates a model_manager and data_manager with a page and a graph that requires a list input."""
vm.Page(
id="test_page",
title="My first dashboard",
components=[
vm.Graph(id="scatter_matrix_c... | Instantiates a model_manager and data_manager with a page and a graph that requires a list input. | managers_one_page_one_graph_with_dict_param_input | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/conftest.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/conftest.py | Apache-2.0 |
def ctx_export_data(request):
"""Mock dash.ctx that represents filters and filter interactions applied."""
targets, pop_filter, continent_filter_interaction, country_table_filter_interaction = request.param
args_grouping_filter_interaction = []
if continent_filter_interaction:
args_grouping_filt... | Mock dash.ctx that represents filters and filter interactions applied. | ctx_export_data | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_export_data.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_export_data.py | Apache-2.0 |
def ctx_export_data_filter_and_parameter(request):
"""Mock dash.ctx that represents filters and parameter applied."""
targets, pop_filter, first_n_parameter = request.param
mock_ctx = {
"args_grouping": {
"external": {
"_controls": {
"filters": (
... | Mock dash.ctx that represents filters and parameter applied. | ctx_export_data_filter_and_parameter | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_export_data.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_export_data.py | Apache-2.0 |
def config_for_testing_all_components_with_actions(request, standard_px_chart, ag_grid_with_id):
"""Instantiates managers with one page that contains four controls, two graphs and filter interaction."""
# If the fixture is parametrised set the targets. Otherwise, set export_data without targets.
export_data... | Instantiates managers with one page that contains four controls, two graphs and filter interaction. | config_for_testing_all_components_with_actions | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_export_data.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_export_data.py | Apache-2.0 |
def ctx_filter_continent(request):
"""Mock dash.ctx that represents continent Filter value selection."""
continent = request.param
mock_ctx = {
"args_grouping": {
"external": {
"_controls": {
"filter_interaction": [],
"filters": [
... | Mock dash.ctx that represents continent Filter value selection. | ctx_filter_continent | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_filter_action.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_filter_action.py | Apache-2.0 |
def ctx_filter_continent_and_pop(request):
"""Mock dash.ctx that represents continent and pop Filter value selection."""
continent, pop = request.param
mock_ctx = {
"args_grouping": {
"external": {
"_controls": {
"filter_interaction": [],
... | Mock dash.ctx that represents continent and pop Filter value selection. | ctx_filter_continent_and_pop | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_filter_action.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_filter_action.py | Apache-2.0 |
def ctx_filter_interaction(request):
"""Mock dash.ctx that represents a click on a continent data-point and table selected cell."""
continent_filter_interaction, country_table_filter_interaction, country_aggrid_filter_interaction = request.param
args_grouping_filter_interaction = []
if continent_filter... | Mock dash.ctx that represents a click on a continent data-point and table selected cell. | ctx_filter_interaction | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_filter_interaction.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_filter_interaction.py | Apache-2.0 |
def ctx_on_page_load(request):
"""Mock dash.ctx that represents on page load."""
continent_filter, pop, y, x = request.param
mock_ctx = {
"args_grouping": {
"external": {
"_controls": {
"filter_interaction": [],
"filters": [
... | Mock dash.ctx that represents on page load. | ctx_on_page_load | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_on_page_load.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_on_page_load.py | Apache-2.0 |
def ctx_parameter_y(request):
"""Mock dash.ctx that represents y-axis Parameter value selection."""
y = request.param
mock_ctx = {
"args_grouping": {
"external": {
"_controls": {
"filter_interaction": [],
"filters": [],
... | Mock dash.ctx that represents y-axis Parameter value selection. | ctx_parameter_y | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_parameter_action.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_parameter_action.py | Apache-2.0 |
def ctx_parameter_dimensions(request):
"""Mock dash.ctx that represents `dimensions` Parameter value selection."""
y = request.param
mock_ctx = {
"args_grouping": {
"external": {
"_controls": {
"filter_interaction": [],
"filters": [... | Mock dash.ctx that represents `dimensions` Parameter value selection. | ctx_parameter_dimensions | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_parameter_action.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_parameter_action.py | Apache-2.0 |
def ctx_parameter_hover_data(request):
"""Mock dash.ctx that represents hover_data Parameter value selection."""
hover_data = request.param
mock_ctx = {
"args_grouping": {
"external": {
"_controls": {
"filter_interaction": [],
"filt... | Mock dash.ctx that represents hover_data Parameter value selection. | ctx_parameter_hover_data | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_parameter_action.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_parameter_action.py | Apache-2.0 |
def ctx_parameter_data_frame_argument(request):
"""Mock dash.ctx that represents parameter applied."""
targets, first_n_last_n_args = request.param
dynamic_filters = []
parameters = [
CallbackTriggerDict(
id="first_n_parameter",
property="value",
value=first_... | Mock dash.ctx that represents parameter applied. | ctx_parameter_data_frame_argument | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/test_parameter_action.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/test_parameter_action.py | Apache-2.0 |
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=[
vm.Page(
id="test_page",
title="First page",
c... | Instantiates managers with one page that contains two controls and two components. | managers_one_page_two_components_two_controls | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/_action_loop/test_get_action_loop_components.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/_action_loop/test_get_action_loop_components.py | Apache-2.0 |
def managers_one_page_no_actions(vizro_app):
"""Instantiates managers with one "empty" page."""
vm.Dashboard(
pages=[
vm.Page(
id="test_page_no_actions",
title="Second page",
components=[
vm.Card(text=""),
],... | Instantiates managers with one "empty" page. | managers_one_page_no_actions | python | mckinsey/vizro | vizro-core/tests/unit/vizro/actions/_action_loop/test_get_action_loop_components.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/actions/_action_loop/test_get_action_loop_components.py | Apache-2.0 |
def test_model_type_none_root_model_none(self):
"""model_type is None | page is None -> return all elements."""
result = [model.id for model in model_manager._get_models()]
expected = {
"page_1_id",
"page_1_button_id",
"page_1_graph_id",
"page_2_i... | model_type is None | page is None -> return all elements. | test_model_type_none_root_model_none | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_type_root_model_none(self):
"""model_type is vm.Button | root_model is None -> return all vm.Button from the dashboard."""
result = [model.id for model in model_manager._get_models(model_type=vm.Button)]
expected = {"page_1_button_id", "page_2_button_id"}
excluded = {"pag... | model_type is vm.Button | root_model is None -> return all vm.Button from the dashboard. | test_model_type_root_model_none | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_type_none_root_model_not_none(self, page_1):
"""model_type is None | root_model is page_1 -> return all elements from the page_1."""
result = [model.id for model in model_manager._get_models(root_model=page_1)]
expected = {"page_1_id", "page_1_button_id", "page_1_graph_id"}
... | model_type is None | root_model is page_1 -> return all elements from the page_1. | test_model_type_none_root_model_not_none | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_type_not_none_page_not_none(self, page_1):
"""model_type is vm.Button | page is page_1 -> return all vm.Button from the page_1."""
result = [model.id for model in model_manager._get_models(model_type=vm.Button, root_model=page_1)]
expected = {"page_1_button_id"}
excluded ... | model_type is vm.Button | page is page_1 -> return all vm.Button from the page_1. | test_model_type_not_none_page_not_none | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_type_no_match_root_model_none(self):
"""model_type matches no type | root_model is None -> return empty list."""
# There is no AgGrid in the dashboard
result = [model.id for model in model_manager._get_models(model_type=vm.AgGrid)]
assert result == [] | model_type matches no type | root_model is None -> return empty list. | test_model_type_no_match_root_model_none | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_type_no_match_root_model_not_none(self, page_1):
"""model_type matches no type | root_model is page_1 -> return empty list."""
# There is no AgGrid in the page_1
result = [model.id for model in model_manager._get_models(model_type=vm.AgGrid, root_model=page_1)]
assert res... | model_type matches no type | root_model is page_1 -> return empty list. | test_model_type_no_match_root_model_not_none | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_type_tuple_of_models(self):
"""model_type is tuple of models -> return all elements of the specified types from the dashboard."""
result = [model.id for model in model_manager._get_models(model_type=(vm.Button, vm.Graph))]
expected = {"page_1_button_id", "page_1_graph_id", "page_... | model_type is tuple of models -> return all elements of the specified types from the dashboard. | test_model_type_tuple_of_models | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_type_figure_models(self):
"""model_type is FIGURE_MODELS | root_model is None -> return all figure elements from the dashboard."""
result = [model.id for model in model_manager._get_models(model_type=FIGURE_MODELS)]
expected = {"page_1_graph_id", "page_2_figure_id"}
exclu... | model_type is FIGURE_MODELS | root_model is None -> return all figure elements from the dashboard. | test_model_type_figure_models | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_subclass_model_type(self, page_1, standard_px_chart):
"""model_type is subclass of vm.Graph -> return all elements of the specified type and its subclasses."""
class CustomGraph(vm.Graph):
pass
page_1.components.append(CustomGraph(id="page_1_custom_graph_id", figure=standa... | model_type is subclass of vm.Graph -> return all elements of the specified type and its subclasses. | test_subclass_model_type | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_nested_models(self, page_1, make_nested_control):
"""Model is nested under another model and known property in different ways -> return the model."""
class ControlGroup(vm.VizroBaseModel):
controls: Any
page_1.controls.append(
ControlGroup(controls=make_nested_... | Model is nested under another model and known property in different ways -> return the model. | test_nested_models | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_under_unknown_field(self, page_1):
"""Model is nested under another model but under an unknown field -> don't return the model."""
class ControlGroup(vm.VizroBaseModel):
unknown_field: Any
page_1.controls.append(ControlGroup(unknown_field=vm.Filter(id="page_1_control... | Model is nested under another model but under an unknown field -> don't return the model. | test_model_under_unknown_field | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_root_model_container(self, container_1):
"""model_type is None | root_model is container_1 -> return all elements from the container_1."""
result = [model.id for model in model_manager._get_models(root_model=container_1)]
expected = {"container_1_id", "container_1_button_id", "containe... | model_type is None | root_model is container_1 -> return all elements from the container_1. | test_root_model_container | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_in_page(self, page_1):
"""Model is in page -> return page."""
result = model_manager._get_model_page(page_1.components[0])
assert result == page_1 | Model is in page -> return page. | test_model_in_page | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_not_in_page(self, page_1):
"""Model is not in page -> return None."""
# Instantiate standalone model
button = vm.Button(id="standalone_button_id")
result = model_manager._get_model_page(button)
assert result is None | Model is not in page -> return None. | test_model_not_in_page | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_model_is_page(self, page_1):
"""Model is Page -> return that page."""
result = model_manager._get_model_page(page_1)
assert result == page_1 | Model is Page -> return that page. | test_model_is_page | python | mckinsey/vizro | vizro-core/tests/unit/vizro/managers/test_model_manager.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/managers/test_model_manager.py | Apache-2.0 |
def test_add_same_model(self, Parent):
"""Test whether adding same model re-defined avoids pydantic discriminator error."""
class MultipleChild(vm.VizroBaseModel):
type: Literal["derived"] = "derived"
Parent.add_type("child", MultipleChild)
class MultipleChild(vm.VizroBase... | Test whether adding same model re-defined avoids pydantic discriminator error. | test_add_same_model | python | mckinsey/vizro | vizro-core/tests/unit/vizro/models/test_base.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/models/test_base.py | Apache-2.0 |
def test_add_duplicate_type(self, Parent):
"""Test whether adding model of same type avoids pydantic discriminator error."""
class MultipleChild(ChildX):
pass
Parent.add_type("child", MultipleChild) | Test whether adding model of same type avoids pydantic discriminator error. | test_add_duplicate_type | python | mckinsey/vizro | vizro-core/tests/unit/vizro/models/test_base.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/models/test_base.py | Apache-2.0 |
def test_button_build_with_extra(self):
"""Test that extra arguments correctly override defaults."""
result = vm.Button(
id="button", text="Click me!", extra={"color": "success", "outline": True, "href": "www.google.com"}
).build()
assert_component_equal(
result,
... | Test that extra arguments correctly override defaults. | test_button_build_with_extra | python | mckinsey/vizro | vizro-core/tests/unit/vizro/models/_components/test_button.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/models/_components/test_button.py | Apache-2.0 |
def test_button_build_with_description(self):
"""Test that description argument correctly builds icon and tooltip."""
result = vm.Button(
id="button",
text="Click me",
description=vm.Tooltip(text="Test description", icon="info", id="info"),
).build()
... | Test that description argument correctly builds icon and tooltip. | test_button_build_with_description | python | mckinsey/vizro | vizro-core/tests/unit/vizro/models/_components/test_button.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/models/_components/test_button.py | Apache-2.0 |
def test_checklist_build_with_description(self):
"""Test that description arguments correctly builds icon and tooltip."""
checklist = Checklist(
options=["A", "B", "C"],
value=["A"],
title="Title",
description=Tooltip(text="Test description", icon="info", ... | Test that description arguments correctly builds icon and tooltip. | test_checklist_build_with_description | python | mckinsey/vizro | vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py | Apache-2.0 |
def managers_one_page_two_graphs(gapminder):
"""Instantiates a simple model_manager and data_manager with a page, and two graph models and gapminder data."""
vm.Page(
id="test_page",
title="My first dashboard",
components=[
vm.Graph(id="scatter_chart", figure=px.scatter(gapmi... | Instantiates a simple model_manager and data_manager with a page, and two graph models and gapminder data. | managers_one_page_two_graphs | python | mckinsey/vizro | vizro-core/tests/unit/vizro/models/_controls/conftest.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/models/_controls/conftest.py | Apache-2.0 |
def managers_column_different_type():
"""Instantiates the managers with a page and two graphs sharing the same column but of different data types."""
df_numerical = pd.DataFrame({"shared_column": [1]})
df_temporal = pd.DataFrame({"shared_column": [datetime(2024, 1, 1)]})
df_categorical = pd.DataFrame({"... | Instantiates the managers with a page and two graphs sharing the same column but of different data types. | managers_column_different_type | python | mckinsey/vizro | vizro-core/tests/unit/vizro/models/_controls/test_filter.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/models/_controls/test_filter.py | Apache-2.0 |
def managers_column_only_exists_in_some():
"""Dataframes with column_numerical and column_categorical, which can be different lengths."""
vm.Page(
id="test_page",
title="Page Title",
components=[
vm.Graph(id="column_numerical_exists_1", figure=px.scatter(pd.DataFrame({"column... | Dataframes with column_numerical and column_categorical, which can be different lengths. | managers_column_only_exists_in_some | python | mckinsey/vizro | vizro-core/tests/unit/vizro/models/_controls/test_filter.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tests/unit/vizro/models/_controls/test_filter.py | Apache-2.0 |
def fetch_extracted_url(source_url: str, pattern: str, headers: dict[str, str]) -> bytes:
"""Look at the file at source_url, search for pattern and then download `url_to_download`."""
response = requests.get(source_url, timeout=TIMEOUT, headers=headers)
response.raise_for_status()
match = re.search(pat... | Look at the file at source_url, search for pattern and then download `url_to_download`. | fetch_extracted_url | python | mckinsey/vizro | vizro-core/tools/download_static_files.py | https://github.com/mckinsey/vizro/blob/master/vizro-core/tools/download_static_files.py | Apache-2.0 |
def get_sample_data_info(data_name: Literal["iris", "tips", "stocks", "gapminder"]) -> DFMetaData:
"""If user provides no data, use this tool to get sample data information.
Use the following data for the below purposes:
- iris: mostly numerical with one categorical column, good for scatter, histogram,... | If user provides no data, use this tool to get sample data information.
Use the following data for the below purposes:
- iris: mostly numerical with one categorical column, good for scatter, histogram, boxplot, etc.
- tips: contains mix of numerical and categorical columns, good for bar, pie, etc.
... | get_sample_data_info | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def validate_model_config(
dashboard_config: dict[str, Any],
data_infos: list[DFMetaData], # Should be Optional[..]=None, but Cursor complains..
auto_open: bool = True,
) -> ValidationResults:
"""Validate Vizro model configuration. Run ALWAYS when you have a complete dashboard configuration.
If su... | Validate Vizro model configuration. Run ALWAYS when you have a complete dashboard configuration.
If successful, the tool will return the python code and, if it is a remote file, the py.cafe link to the chart.
The PyCafe link will be automatically opened in your default browser if auto_open is True.
Args:
... | validate_model_config | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def get_model_json_schema(model_name: str) -> dict[str, Any]:
"""Get the JSON schema for the specified Vizro model.
Args:
model_name: Name of the Vizro model to get schema for (e.g., 'Card', 'Dashboard', 'Page')
Returns:
JSON schema of the requested Vizro model
"""
# Dictionary map... | Get the JSON schema for the specified Vizro model.
Args:
model_name: Name of the Vizro model to get schema for (e.g., 'Card', 'Dashboard', 'Page')
Returns:
JSON schema of the requested Vizro model
| get_model_json_schema | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def get_vizro_chart_or_dashboard_plan(user_plan: Literal["chart", "dashboard"]) -> str:
"""Get instructions for creating a Vizro chart or dashboard. Call FIRST when asked to create Vizro things."""
if user_plan == "chart":
return """
IMPORTANT:
- KEEP IT SIMPLE: rather than iterating yourself, ask t... | Get instructions for creating a Vizro chart or dashboard. Call FIRST when asked to create Vizro things. | get_vizro_chart_or_dashboard_plan | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def load_and_analyze_data(path_or_url: str) -> DataAnalysisResults:
"""Load data from various file formats into a pandas DataFrame and analyze its structure.
Supported formats:
- CSV (.csv)
- JSON (.json)
- HTML (.html, .htm)
- Excel (.xls, .xlsx)
- OpenDocument Spreadsheet (.ods)
- Par... | Load data from various file formats into a pandas DataFrame and analyze its structure.
Supported formats:
- CSV (.csv)
- JSON (.json)
- HTML (.html, .htm)
- Excel (.xls, .xlsx)
- OpenDocument Spreadsheet (.ods)
- Parquet (.parquet)
Args:
path_or_url: Local file path or URL to a... | load_and_analyze_data | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def create_starter_dashboard():
"""Prompt template for getting started with Vizro."""
content = f"""
Create a super simple Vizro dashboard with one page and one chart and one filter:
- No need to call any tools except for validate_model_config
- Call this tool with the precise config as shown below
- The PyCafe... | Prompt template for getting started with Vizro. | create_starter_dashboard | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def create_eda_dashboard(
file_path_or_url: str,
) -> str:
"""Prompt template for creating an EDA dashboard based on one dataset."""
content = f"""
Create an EDA dashboard based on the following dataset:{file_path_or_url}. Proceed as follows:
1. Analyze the data using the load_and_analyze_data tool first, p... | Prompt template for creating an EDA dashboard based on one dataset. | create_eda_dashboard | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def validate_chart_code(
chart_config: ChartPlan,
data_info: DFMetaData,
auto_open: bool = True,
) -> ValidationResults:
"""Validate the chart code created by the user and optionally open the PyCafe link in a browser.
Args:
chart_config: A ChartPlan object with the chart configuration
... | Validate the chart code created by the user and optionally open the PyCafe link in a browser.
Args:
chart_config: A ChartPlan object with the chart configuration
data_info: Metadata for the dataset to be used in the chart
auto_open: Whether to automatically open the PyCafe link in a browser... | validate_chart_code | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def create_vizro_chart(
chart_type: str,
file_path_or_url: Optional[str] = None,
) -> str:
"""Prompt template for creating a Vizro chart."""
content = f"""
- Create a chart using the following chart type: {chart_type}.
- You MUST name the function containing the fig `custom_chart`
- Make sure to anal... | Prompt template for creating a Vizro chart. | create_vizro_chart | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/server.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/server.py | Apache-2.0 |
def main():
"""Run the Vizro MCP server - makes charts and dashboards available to AI assistants."""
# Configure logging to show warnings by default
logging.basicConfig(level=logging.WARNING, stream=sys.stderr)
# Run the MCP server
mcp.run() | Run the Vizro MCP server - makes charts and dashboards available to AI assistants. | main | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/__init__.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/__init__.py | Apache-2.0 |
def get_dashboard_template(self, data_info: DFMetaData) -> str:
"""Create a simple dashboard template for displaying the chart.
Args:
data_info: The metadata of the dataset to use.
Returns:
Complete Python code for a Vizro dashboard displaying the chart.
"""
... | Create a simple dashboard template for displaying the chart.
Args:
data_info: The metadata of the dataset to use.
Returns:
Complete Python code for a Vizro dashboard displaying the chart.
| get_dashboard_template | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/_schemas/schemas.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/_schemas/schemas.py | Apache-2.0 |
def get_overview_vizro_models() -> dict[str, list[dict[str, str]]]:
"""Get all available models in the vizro.models namespace.
Returns:
Dictionary with categories of models and their descriptions
"""
result: dict[str, list[dict[str, str]]] = {}
for category, models_list in MODEL_GROUPS.item... | Get all available models in the vizro.models namespace.
Returns:
Dictionary with categories of models and their descriptions
| get_overview_vizro_models | python | mckinsey/vizro | vizro-mcp/src/vizro_mcp/_schemas/schemas.py | https://github.com/mckinsey/vizro/blob/master/vizro-mcp/src/vizro_mcp/_schemas/schemas.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.