Skip to content

Commit

Permalink
Apply ctx abbreviation consistently (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen authored Jan 10, 2024
1 parent 758ba04 commit d64350c
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 101 deletions.
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))
-->
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/actions/_actions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class CallbackTriggerDict(TypedDict):
"""Represent dash.callback_context.args_grouping item. Shortened as 'ctd' in the code.
"""Represent dash.ctx.args_grouping item. Shortened as 'ctd' in the code.
Args:
id: The component ID. If it`s a pattern matching ID, it will be a dict.
Expand Down
46 changes: 21 additions & 25 deletions vizro-core/tests/unit/vizro/actions/test_export_data_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def managers_one_page_without_graphs_one_button():


@pytest.fixture
def callback_context_export_data(request):
"""Mock dash.callback_context that represents filters and filter interactions applied."""
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:
Expand Down Expand Up @@ -97,7 +97,7 @@ def callback_context_export_data(request):
),
}
)
mock_callback_context = {
mock_ctx = {
"args_grouping": {
"external": {
"filters": [
Expand All @@ -123,14 +123,14 @@ def callback_context_export_data(request):
],
}

context_value.set(AttributeDict(**mock_callback_context))
context_value.set(AttributeDict(**mock_ctx))
return context_value


class TestExportData:
@pytest.mark.usefixtures("managers_one_page_without_graphs_one_button")
@pytest.mark.parametrize("callback_context_export_data", [([[], None, None, None])], indirect=True)
def test_no_graphs_no_targets(self, callback_context_export_data):
@pytest.mark.parametrize("ctx_export_data", [([[], None, None, None])], indirect=True)
def test_no_graphs_no_targets(self, ctx_export_data):
# Add action to relevant component
model_manager["button"].actions = [vm.Action(id="test_action", function=export_data())]

Expand All @@ -141,10 +141,8 @@ def test_no_graphs_no_targets(self, callback_context_export_data):
assert result == expected

@pytest.mark.usefixtures("managers_one_page_two_graphs_one_button")
@pytest.mark.parametrize(
"callback_context_export_data", [([["scatter_chart", "box_chart"], None, None, None])], indirect=True
)
def test_graphs_no_targets(self, callback_context_export_data, gapminder_2007):
@pytest.mark.parametrize("ctx_export_data", [([["scatter_chart", "box_chart"], None, None, None])], indirect=True)
def test_graphs_no_targets(self, ctx_export_data, gapminder_2007):
# Add action to relevant component
model_manager["button"].actions = [vm.Action(id="test_action", function=export_data())]

Expand All @@ -169,14 +167,14 @@ def test_graphs_no_targets(self, callback_context_export_data, gapminder_2007):

@pytest.mark.usefixtures("managers_one_page_two_graphs_one_button")
@pytest.mark.parametrize(
"callback_context_export_data, targets",
"ctx_export_data, targets",
[
([["scatter_chart", "box_chart"], None, None, None], None),
([["scatter_chart", "box_chart"], None, None, None], []),
],
indirect=["callback_context_export_data"],
indirect=["ctx_export_data"],
)
def test_graphs_false_targets(self, callback_context_export_data, targets, gapminder_2007):
def test_graphs_false_targets(self, ctx_export_data, targets, gapminder_2007):
# Add action to relevant component
model_manager["button"].actions = [vm.Action(id="test_action", function=export_data(targets=targets))]

Expand All @@ -200,8 +198,8 @@ def test_graphs_false_targets(self, callback_context_export_data, targets, gapmi
assert result == expected

@pytest.mark.usefixtures("managers_one_page_two_graphs_one_button")
@pytest.mark.parametrize("callback_context_export_data", [(["scatter_chart"], None, None, None)], indirect=True)
def test_one_target(self, callback_context_export_data, gapminder_2007):
@pytest.mark.parametrize("ctx_export_data", [(["scatter_chart"], None, None, None)], indirect=True)
def test_one_target(self, ctx_export_data, gapminder_2007):
# Add action to relevant component
model_manager["button"].actions = [vm.Action(id="test_action", function=export_data(targets=["scatter_chart"]))]

Expand All @@ -219,10 +217,8 @@ def test_one_target(self, callback_context_export_data, gapminder_2007):
assert result == expected

@pytest.mark.usefixtures("managers_one_page_two_graphs_one_button")
@pytest.mark.parametrize(
"callback_context_export_data", [(["scatter_chart", "box_chart"], None, None, None)], indirect=True
)
def test_multiple_targets(self, callback_context_export_data, gapminder_2007):
@pytest.mark.parametrize("ctx_export_data", [(["scatter_chart", "box_chart"], None, None, None)], indirect=True)
def test_multiple_targets(self, ctx_export_data, gapminder_2007):
# Add action to relevant component
model_manager["button"].actions = [
vm.Action(id="test_action", function=export_data(targets=["scatter_chart", "box_chart"]))
Expand All @@ -248,10 +244,10 @@ def test_multiple_targets(self, callback_context_export_data, gapminder_2007):
assert result == expected

@pytest.mark.usefixtures("managers_one_page_two_graphs_one_button")
@pytest.mark.parametrize("callback_context_export_data", [(["invalid_target_id"], None, None, None)], indirect=True)
@pytest.mark.parametrize("ctx_export_data", [(["invalid_target_id"], None, None, None)], indirect=True)
def test_invalid_target(
self,
callback_context_export_data,
ctx_export_data,
):
# Add action to relevant component
model_manager["button"].actions = [
Expand All @@ -264,7 +260,7 @@ def test_invalid_target(

@pytest.mark.usefixtures("managers_one_page_two_graphs_one_button")
@pytest.mark.parametrize(
"callback_context_export_data, target_scatter_filter_and_filter_interaction, target_box_filtered_pop",
"ctx_export_data, target_scatter_filter_and_filter_interaction, target_box_filtered_pop",
[
(
[["scatter_chart", "box_chart"], [10**6, 10**7], None, None],
Expand All @@ -282,7 +278,7 @@ def test_invalid_target(
)
def test_multiple_targets_with_filter_and_filter_interaction(
self,
callback_context_export_data,
ctx_export_data,
target_scatter_filter_and_filter_interaction,
target_box_filtered_pop,
):
Expand Down Expand Up @@ -323,7 +319,7 @@ def test_multiple_targets_with_filter_and_filter_interaction(

@pytest.mark.usefixtures("managers_one_page_two_graphs_one_table_one_button")
@pytest.mark.parametrize(
"callback_context_export_data, target_scatter_filter_and_filter_interaction, target_box_filtered_pop",
"ctx_export_data, target_scatter_filter_and_filter_interaction, target_box_filtered_pop",
[
(
[["scatter_chart", "box_chart"], [10**6, 10**7], None, "Algeria"],
Expand All @@ -341,7 +337,7 @@ def test_multiple_targets_with_filter_and_filter_interaction(
)
def test_multiple_targets_with_filter_and_filter_interaction_and_table(
self,
callback_context_export_data,
ctx_export_data,
target_scatter_filter_and_filter_interaction,
target_box_filtered_pop,
):
Expand Down
40 changes: 20 additions & 20 deletions vizro-core/tests/unit/vizro/actions/test_filter_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def target_box_filtered_continent_and_pop(request, gapminder_2007, box_params):


@pytest.fixture
def callback_context_filter_continent(request):
"""Mock dash.callback_context that represents continent Filter value selection."""
def ctx_filter_continent(request):
"""Mock dash.ctx that represents continent Filter value selection."""
continent = request.param
mock_callback_context = {
mock_ctx = {
"args_grouping": {
"external": {
"filter_interaction": [],
Expand All @@ -57,15 +57,15 @@ def callback_context_filter_continent(request):
}
}
}
context_value.set(AttributeDict(**mock_callback_context))
context_value.set(AttributeDict(**mock_ctx))
return context_value


@pytest.fixture
def callback_context_filter_continent_and_pop(request):
"""Mock dash.callback_context that represents continent and pop Filter value selection."""
def ctx_filter_continent_and_pop(request):
"""Mock dash.ctx that represents continent and pop Filter value selection."""
continent, pop = request.param
mock_callback_context = {
mock_ctx = {
"args_grouping": {
"external": {
"filter_interaction": [],
Expand Down Expand Up @@ -96,20 +96,20 @@ def callback_context_filter_continent_and_pop(request):
}
}
}
context_value.set(AttributeDict(**mock_callback_context))
context_value.set(AttributeDict(**mock_ctx))
return context_value


@pytest.mark.usefixtures("managers_one_page_two_graphs_one_button")
class TestFilter:
@pytest.mark.parametrize(
"callback_context_filter_continent,target_scatter_filtered_continent,target_box_filtered_continent",
"ctx_filter_continent,target_scatter_filtered_continent,target_box_filtered_continent",
[(["Africa"], ["Africa"], ["Africa"]), (["Africa", "Europe"], ["Africa", "Europe"], ["Africa", "Europe"])],
indirect=True,
)
def test_one_filter_no_targets(
self,
callback_context_filter_continent,
ctx_filter_continent,
target_scatter_filtered_continent,
target_box_filtered_continent,
):
Expand All @@ -130,13 +130,13 @@ def test_one_filter_no_targets(
assert result == expected

@pytest.mark.parametrize(
"callback_context_filter_continent,target_scatter_filtered_continent",
"ctx_filter_continent,target_scatter_filtered_continent",
[(["Africa"], ["Africa"]), (["Africa", "Europe"], ["Africa", "Europe"])],
indirect=True,
)
def test_one_filter_one_target(
self,
callback_context_filter_continent,
ctx_filter_continent,
target_scatter_filtered_continent,
):
# Creating and adding a Filter object to the existing Page
Expand All @@ -157,13 +157,13 @@ def test_one_filter_one_target(
assert result == expected

@pytest.mark.parametrize(
"callback_context_filter_continent,target_scatter_filtered_continent,target_box_filtered_continent",
"ctx_filter_continent,target_scatter_filtered_continent,target_box_filtered_continent",
[(["Africa"], ["Africa"], ["Africa"]), (["Africa", "Europe"], ["Africa", "Europe"], ["Africa", "Europe"])],
indirect=True,
)
def test_one_filter_multiple_targets(
self,
callback_context_filter_continent,
ctx_filter_continent,
target_scatter_filtered_continent,
target_box_filtered_continent,
):
Expand All @@ -189,7 +189,7 @@ def test_one_filter_multiple_targets(
assert result == expected

@pytest.mark.parametrize(
"callback_context_filter_continent_and_pop,target_scatter_filtered_continent_and_pop,target_box_filtered_continent_and_pop",
"ctx_filter_continent_and_pop,target_scatter_filtered_continent_and_pop,target_box_filtered_continent_and_pop",
[
([["Africa"], [10**6, 10**7]], [["Africa"], [10**6, 10**7]], [["Africa"], [10**6, 10**7]]),
(
Expand All @@ -202,7 +202,7 @@ def test_one_filter_multiple_targets(
)
def test_multiple_filters_no_targets(
self,
callback_context_filter_continent_and_pop,
ctx_filter_continent_and_pop,
target_scatter_filtered_continent_and_pop,
target_box_filtered_continent_and_pop,
):
Expand All @@ -227,7 +227,7 @@ def test_multiple_filters_no_targets(
assert result == expected

@pytest.mark.parametrize(
"callback_context_filter_continent_and_pop,target_scatter_filtered_continent_and_pop",
"ctx_filter_continent_and_pop,target_scatter_filtered_continent_and_pop",
[
([["Africa"], [10**6, 10**7]], [["Africa"], [10**6, 10**7]]),
([["Africa", "Europe"], [10**6, 10**7]], [["Africa", "Europe"], [10**6, 10**7]]),
Expand All @@ -236,7 +236,7 @@ def test_multiple_filters_no_targets(
)
def test_multiple_filters_one_target(
self,
callback_context_filter_continent_and_pop,
ctx_filter_continent_and_pop,
target_scatter_filtered_continent_and_pop,
):
# Creating and adding a Filter objects to the existing Page
Expand All @@ -262,7 +262,7 @@ def test_multiple_filters_one_target(
assert result == expected

@pytest.mark.parametrize(
"callback_context_filter_continent_and_pop,target_scatter_filtered_continent_and_pop,target_box_filtered_continent_and_pop",
"ctx_filter_continent_and_pop,target_scatter_filtered_continent_and_pop,target_box_filtered_continent_and_pop",
[
([["Africa"], [10**6, 10**7]], [["Africa"], [10**6, 10**7]], [["Africa"], [10**6, 10**7]]),
(
Expand All @@ -275,7 +275,7 @@ def test_multiple_filters_one_target(
)
def test_multiple_filters_multiple_targets(
self,
callback_context_filter_continent_and_pop,
ctx_filter_continent_and_pop,
target_scatter_filtered_continent_and_pop,
target_box_filtered_continent_and_pop,
):
Expand Down
Loading

0 comments on commit d64350c

Please sign in to comment.