codeant-ai-for-open-source[bot] commented on code in PR #41133: URL: https://github.com/apache/superset/pull/41133#discussion_r3589605244
########## tests/unit_tests/dashboards/test_excel_export_layout.py: ########## @@ -0,0 +1,105 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from typing import Any +from unittest.mock import MagicMock + +from superset.dashboards.excel_export.layout import get_charts_in_layout_order + + +def _chart_node(node_id: str, chart_id: int) -> dict[str, Any]: + return {"id": node_id, "type": "CHART", "meta": {"chartId": chart_id}} + + +def _dashboard(position: dict[str, Any], chart_ids: list[int]) -> MagicMock: + dashboard = MagicMock() + dashboard.position = position + dashboard.slices = [MagicMock(id=cid) for cid in chart_ids] + return dashboard + + +def _ids(slices: list[Any]) -> list[int]: + return [slc.id for slc in slices] + + +def test_grid_order() -> None: + position = { + "ROOT_ID": {"type": "ROOT", "children": ["GRID_ID"]}, + "GRID_ID": {"type": "GRID", "children": ["ROW-1"]}, + "ROW-1": {"type": "ROW", "children": ["CHART-a", "CHART-b"]}, + "CHART-a": _chart_node("CHART-a", 1), + "CHART-b": _chart_node("CHART-b", 2), + } + dashboard = _dashboard(position, [2, 1]) + assert _ids(get_charts_in_layout_order(dashboard)) == [1, 2] + + +def test_tab_nested_order() -> None: + position = { + "ROOT_ID": {"type": "ROOT", "children": ["GRID_ID"]}, + "GRID_ID": {"type": "GRID", "children": ["TABS-1"]}, + "TABS-1": {"type": "TABS", "children": ["TAB-1", "TAB-2"]}, + "TAB-1": {"type": "TAB", "children": ["CHART-a"]}, + "TAB-2": {"type": "TAB", "children": ["CHART-b"]}, + "CHART-a": _chart_node("CHART-a", 10), + "CHART-b": _chart_node("CHART-b", 20), + } + dashboard = _dashboard(position, [20, 10]) + assert _ids(get_charts_in_layout_order(dashboard)) == [10, 20] + + +def test_duplicate_chart_placement_exported_once() -> None: + position = { + "ROOT_ID": {"type": "ROOT", "children": ["GRID_ID"]}, + "GRID_ID": {"type": "GRID", "children": ["ROW-1", "ROW-2"]}, + "ROW-1": {"type": "ROW", "children": ["CHART-a"]}, + "ROW-2": {"type": "ROW", "children": ["CHART-a-dup"]}, + "CHART-a": _chart_node("CHART-a", 5), + "CHART-a-dup": _chart_node("CHART-a-dup", 5), + } + dashboard = _dashboard(position, [5]) + assert _ids(get_charts_in_layout_order(dashboard)) == [5] + + +def test_orphan_charts_appended_by_id() -> None: + position = { Review Comment: **Suggestion:** Annotate this local `position` variable with its mapping type in this test to keep type hints complete in added code. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> This test introduces another annotatable local mapping without an explicit type hint, which is exactly the kind of omission the rule flags. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d4e450a28ddc4d3ea0abf3a7b8cb14ae&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d4e450a28ddc4d3ea0abf3a7b8cb14ae&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/dashboards/test_excel_export_layout.py **Line:** 80:80 **Comment:** *Custom Rule: Annotate this local `position` variable with its mapping type in this test to keep type hints complete in added code. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=8ba58d3c29d931cf7daff1fe9547d07d28210f6475f78dadd38f1addbf722081&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=8ba58d3c29d931cf7daff1fe9547d07d28210f6475f78dadd38f1addbf722081&reaction=dislike'>๐</a> ########## tests/unit_tests/dashboards/test_excel_export_layout.py: ########## @@ -0,0 +1,105 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from typing import Any +from unittest.mock import MagicMock + +from superset.dashboards.excel_export.layout import get_charts_in_layout_order + + +def _chart_node(node_id: str, chart_id: int) -> dict[str, Any]: + return {"id": node_id, "type": "CHART", "meta": {"chartId": chart_id}} + + +def _dashboard(position: dict[str, Any], chart_ids: list[int]) -> MagicMock: + dashboard = MagicMock() + dashboard.position = position + dashboard.slices = [MagicMock(id=cid) for cid in chart_ids] + return dashboard + + +def _ids(slices: list[Any]) -> list[int]: + return [slc.id for slc in slices] + + +def test_grid_order() -> None: + position = { + "ROOT_ID": {"type": "ROOT", "children": ["GRID_ID"]}, + "GRID_ID": {"type": "GRID", "children": ["ROW-1"]}, + "ROW-1": {"type": "ROW", "children": ["CHART-a", "CHART-b"]}, + "CHART-a": _chart_node("CHART-a", 1), + "CHART-b": _chart_node("CHART-b", 2), + } + dashboard = _dashboard(position, [2, 1]) + assert _ids(get_charts_in_layout_order(dashboard)) == [1, 2] + + +def test_tab_nested_order() -> None: + position = { + "ROOT_ID": {"type": "ROOT", "children": ["GRID_ID"]}, + "GRID_ID": {"type": "GRID", "children": ["TABS-1"]}, + "TABS-1": {"type": "TABS", "children": ["TAB-1", "TAB-2"]}, + "TAB-1": {"type": "TAB", "children": ["CHART-a"]}, + "TAB-2": {"type": "TAB", "children": ["CHART-b"]}, + "CHART-a": _chart_node("CHART-a", 10), + "CHART-b": _chart_node("CHART-b", 20), + } + dashboard = _dashboard(position, [20, 10]) + assert _ids(get_charts_in_layout_order(dashboard)) == [10, 20] + + +def test_duplicate_chart_placement_exported_once() -> None: + position = { Review Comment: **Suggestion:** Provide an explicit local type annotation for this `position` object to satisfy the rule on relevant variable hints. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> The `position` local in this test is also unannotated in newly added code, so it fits the custom type-hint rule. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c8b2c23ae2b94c5ba426e4ec6a1832a3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c8b2c23ae2b94c5ba426e4ec6a1832a3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/dashboards/test_excel_export_layout.py **Line:** 67:67 **Comment:** *Custom Rule: Provide an explicit local type annotation for this `position` object to satisfy the rule on relevant variable hints. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=2e0ed66996997a878ab96ed8a18cd579e78eff335991f2002a35a3e719c65de1&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=2e0ed66996997a878ab96ed8a18cd579e78eff335991f2002a35a3e719c65de1&reaction=dislike'>๐</a> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
