bito-code-review[bot] commented on code in PR #34694:
URL: https://github.com/apache/superset/pull/34694#discussion_r2319186897


##########
tests/views/datasource/test_replace_verbose_with_column.py:
##########
@@ -0,0 +1,83 @@
+#  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.
+
+import pytest
+
+from superset.views.datasource.utils import replace_verbose_with_column
+
+
+class Column:
+    def __init__(self, column_name, verbose_name):
+        self.column_name = column_name
+        self.verbose_name = verbose_name
+
+
+class IncompleteColumn:
+    """A column missing required attributes."""
+
+    def __init__(self, only_name):
+        self.only_name = only_name
+
+
+# Test dataset and filters
+columns = [
+    Column("col1", "Column 1"),
+    Column("col3", "Column 3"),
+]
+
+
[email protected](
+    "filters, expected",
+    [
+        # Normal match, should be replaced with the actual column_name
+        ([{"col": "Column 1"}], [{"col": "col1"}]),
+        # Multiple filters, should correctly replace all matching columns
+        (
+            [{"col": "Column 1"}, {"col": "Column 3"}],
+            [{"col": "col1"}, {"col": "col3"}],
+        ),
+        # No matching case, the original value should remain unchanged
+        ([{"col": "Non-existent"}], [{"col": "Non-existent"}]),
+        # Empty filters, no changes should be made
+        ([], []),
+    ],
+)
+def test_replace_verbose_with_column(filters, expected):
+    filters_copy = [dict(f) for f in filters]
+    replace_verbose_with_column(filters_copy, columns)
+    assert filters_copy == expected
+
+
+def test_replace_verbose_with_column_missing_col_key(caplog):
+    """Filter dict missing 'col' should trigger a warning and be skipped."""
+    filters = [{"op": "=="}]  # missing "col"
+    with caplog.at_level("WARNING"):
+        replace_verbose_with_column(filters, columns)
+    assert "Filter missing 'col' key" in caplog.text

Review Comment:
   
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Test assertion mismatch with log message</b></div>
   <div id="fix">
   
   The test assertion will fail because it expects the exact message 'Filter 
missing 'col' key' but the actual function logs 'Filter missing 'col' key: %s' 
with the filter dict appended. Update the assertion to check for 'Filter 
missing 'col' key:' (including the colon) to match the actual log format.
   </div>
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```suggestion
       assert "Filter missing 'col' key:" in caplog.text
   ```
   
   </div>
   </details>
   </div>
   
   
   
   <small><i>Code Review Run <a 
href=https://github.com/apache/superset/pull/34694#issuecomment-3249505496>#7cd4b6</a></i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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]

Reply via email to