Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL committed Oct 25, 2023
1 parent 7632ea7 commit 369d63f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

logger = logging.getLogger(__name__)


def _process_callable_data_frame(captured_callable, values):
data_frame = captured_callable["data_frame"]

Expand Down
1 change: 1 addition & 0 deletions vizro-core/src/vizro/models/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def wrapped(*args, **kwargs):

return wrapped
elif self._mode == "table":

@functools.wraps(func)
def wrapped(*args, **kwargs):
if "data_frame" not in inspect.signature(func).parameters:
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/tables/dash_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from vizro.models.types import capture


def _set_defaults_nested(supplied: Mapping[str,Any], defaults: Mapping[str,Any]) -> dict[str,Any]:
def _set_defaults_nested(supplied: Mapping[str, Any], defaults: Mapping[str, Any]) -> dict[str, Any]:
supplied = defaultdict(dict, supplied)
for default_key, default_value in defaults.items():
if isinstance(default_value, Mapping):
Expand Down
1 change: 1 addition & 0 deletions vizro-core/tests/unit/vizro/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def standard_px_chart(gapminder):
size_max=60,
)


@pytest.fixture
def standard_dash_table(gapminder):
return dash_data_table(data_frame=gapminder)
Expand Down
13 changes: 6 additions & 7 deletions vizro-core/tests/unit/vizro/models/_components/test_table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Unit tests for vizro.models.Table."""
import json

import pandas as pd
import plotly
import pytest
from dash import dash_table, html
Expand All @@ -27,12 +26,12 @@ def dash_table_with_str_dataframe():
@pytest.fixture
def expected_table():
return html.Div(
[
None,
html.Div(dash_table.DataTable(), id="text_table"),
],
className="table-container",
)
[
None,
html.Div(dash_table.DataTable(), id="text_table"),
],
className="table-container",
)


class TestDunderMethodsTable:
Expand Down
9 changes: 7 additions & 2 deletions vizro-core/tests/unit/vizro/models/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ def test_set_layout_invalid(self):
with pytest.raises(ValidationError, match="Number of page and grid components need to be the same."):
vm.Page(title="Page 4", components=[vm.Button()], layout=vm.Layout(grid=[[0, 1]]))

def test_valid_component_types(self, standard_px_chart,standard_dash_table):
def test_valid_component_types(self, standard_px_chart, standard_dash_table):
vm.Page(
title="Page Title",
components=[vm.Graph(figure=standard_px_chart), vm.Card(text="""# Header 1"""), vm.Button(),vm.Table(figure=standard_dash_table)],
components=[
vm.Graph(figure=standard_px_chart),
vm.Card(text="""# Header 1"""),
vm.Button(),
vm.Table(figure=standard_dash_table),
],
)

@pytest.mark.parametrize(
Expand Down
26 changes: 16 additions & 10 deletions vizro-core/tests/unit/vizro/tables/test_dash_table.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from vizro.tables.dash_table import _set_defaults_nested
import pytest

from vizro.tables.dash_table import _set_defaults_nested


@pytest.fixture
def default_dictionary():
return {"a": {"b": {"c": 1, "d": 2}},"e": 3}
return {"a": {"b": {"c": 1, "d": 2}}, "e": 3}


@pytest.mark.parametrize("input, expected_output", [
({},{"a": {"b": {"c": 1, "d": 2}},"e": 3}), # nothing supplied
({'e': 10},{"a": {"b": {"c": 1, "d": 2}},"e": 10}), # flat main key
({"a": {"b": {"c": 11, "d": 12}}},{"a": {"b": {"c": 11, "d": 12}},"e": 3}), # updated multiple nested keys
({"a": {"b": {"c": 1, "d": {"f":42}}}},{"a": {"b": {"c": 1, "d": {"f":42}}},"e": 3}), # add new dict
({"a": {"b": {"c": 5}}},{'a': {'b': {'c': 5, 'd': 2}},"e": 3}) #arbitrary nesting
])
@pytest.mark.parametrize(
"input, expected_output",
[
({}, {"a": {"b": {"c": 1, "d": 2}}, "e": 3}), # nothing supplied
({"e": 10}, {"a": {"b": {"c": 1, "d": 2}}, "e": 10}), # flat main key
({"a": {"b": {"c": 11, "d": 12}}}, {"a": {"b": {"c": 11, "d": 12}}, "e": 3}), # updated multiple nested keys
({"a": {"b": {"c": 1, "d": {"f": 42}}}}, {"a": {"b": {"c": 1, "d": {"f": 42}}}, "e": 3}), # add new dict
({"a": {"b": {"c": 5}}}, {"a": {"b": {"c": 5, "d": 2}}, "e": 3}), # arbitrary nesting
],
)
def test_set_defaults_nested(default_dictionary, input, expected_output):
assert _set_defaults_nested(input, default_dictionary) == expected_output
assert _set_defaults_nested(input, default_dictionary) == expected_output

0 comments on commit 369d63f

Please sign in to comment.