codeant-ai-for-open-source[bot] commented on code in PR #41780:
URL: https://github.com/apache/superset/pull/41780#discussion_r3526399697


##########
tests/unit_tests/translations/utils_test.py:
##########
@@ -0,0 +1,71 @@
+# 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 hashlib
+from collections.abc import Iterator
+
+import pytest
+
+from superset.translations import utils as translations_utils
+from superset.translations.utils import (
+    get_language_pack_filename,
+    get_language_pack_version,
+)
+
+
[email protected](autouse=True)
+def _clear_version_cache() -> Iterator[None]:
+    translations_utils.ALL_LANGUAGE_PACK_VERSIONS.clear()
+    yield
+    translations_utils.ALL_LANGUAGE_PACK_VERSIONS.clear()
+
+
+def test_language_pack_filename_resolution() -> None:
+    assert 
get_language_pack_filename("fr").endswith("/fr/LC_MESSAGES/messages.json")
+    assert 
get_language_pack_filename("en").endswith("/empty_language_pack.json")
+    assert get_language_pack_filename("").endswith("/empty_language_pack.json")
+
+
+def test_version_is_short_content_hash(tmp_path, monkeypatch) -> None:

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not require explicit type annotations for fixture-injected parameters 
in test functions; unannotated pytest fixtures are acceptable in test modules 
to match the repository convention.
   
   **Applied to:**
     - `**/test/**`
     - `**/tests/**`
     - `**/*test*.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
tests/unit_tests/translations/utils_test.py:
##########
@@ -0,0 +1,71 @@
+# 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 hashlib
+from collections.abc import Iterator
+
+import pytest
+
+from superset.translations import utils as translations_utils
+from superset.translations.utils import (
+    get_language_pack_filename,
+    get_language_pack_version,
+)
+
+
[email protected](autouse=True)
+def _clear_version_cache() -> Iterator[None]:
+    translations_utils.ALL_LANGUAGE_PACK_VERSIONS.clear()
+    yield
+    translations_utils.ALL_LANGUAGE_PACK_VERSIONS.clear()
+
+
+def test_language_pack_filename_resolution() -> None:
+    assert 
get_language_pack_filename("fr").endswith("/fr/LC_MESSAGES/messages.json")
+    assert 
get_language_pack_filename("en").endswith("/empty_language_pack.json")
+    assert get_language_pack_filename("").endswith("/empty_language_pack.json")
+
+
+def test_version_is_short_content_hash(tmp_path, monkeypatch) -> None:
+    pack_file = tmp_path / "fr" / "LC_MESSAGES" / "messages.json"
+    pack_file.parent.mkdir(parents=True)
+    pack_file.write_bytes(b'{"domain": "superset"}')
+    monkeypatch.setattr(translations_utils, "DIR", str(tmp_path))
+
+    version = get_language_pack_version("fr")
+
+    expected = hashlib.sha256(b'{"domain": "superset"}').hexdigest()[:12]
+    assert version == expected
+
+
+def test_version_is_cached_and_changes_with_content(tmp_path, monkeypatch) -> 
None:

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag standard unannotated pytest fixtures (e.g. tmp_path, 
monkeypatch) in test files; match the repository's existing test convention.
   
   **Applied to:**
     - `**/test/**`
     - `**/tests/**`
     - `**/*test*.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
tests/unit_tests/views/test_language_pack_script.py:
##########
@@ -0,0 +1,115 @@
+# 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 pathlib import Path
+from typing import Any
+from unittest.mock import patch
+
+FAKE_PACK = {"domain": "superset", "locale_data": {"superset": {"": {}}}}

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not require explicit type annotations for module-level constants in 
test files when they are already covered by the `tests.*` mypy override; keep 
test-file constant handling consistent across sibling test modules.
   
   **Applied to:**
     - `**/test/**`
     - `**/tests/**`
     - `**/*test*.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset/translations/utils.py:
##########
@@ -37,11 +70,7 @@ def get_language_pack(locale: str) -> Optional[dict[str, 
Any]]:
     """
     pack = ALL_LANGUAGE_PACKS.get(locale)
     if not pack:
-        filename = DIR + f"/{locale}/LC_MESSAGES/messages.json"
-        if not locale or locale == "en":
-            # Forcing a dummy, quasy-empty language pack for English since the 
file
-            # in the en directory is contains data with empty mappings
-            filename = DIR + "/empty_language_pack.json"
+        filename = get_language_pack_filename(locale)

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag missing explicit type annotations for local variables in 
Python when their type is clearly inferred from an annotated helper return type.
   
   **Applied to:**
     - `**/*.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



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