Dev-iL commented on code in PR #64972:
URL: https://github.com/apache/airflow/pull/64972#discussion_r3154925007


##########
scripts/tests/ci/prek/test_check_migration_patterns.py:
##########
@@ -0,0 +1,333 @@
+#
+# 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.
+"""Unit tests for ``scripts/ci/prek/check_migration_patterns.py``."""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+from ci.prek.check_migration_patterns import (
+    _get_noqa_codes,
+    _line_has_noqa,
+    check_mig001,
+    check_mig002,
+    check_mig003,
+    main,
+)
+
+# ---------------------------------------------------------------------------
+# Helpers
+# ---------------------------------------------------------------------------
+
+
+def write_migration(tmp_path: Path, source: str) -> Path:
+    """Write *source* to a temp file that looks like a migration file."""
+    p = tmp_path / "0099_test_migration.py"
+    p.write_text(source)
+    return p
+
+
+# ---------------------------------------------------------------------------
+# _get_noqa_codes
+# ---------------------------------------------------------------------------
+
+
+class TestGetNoqaCodes:
+    def test_single_code(self):
+        assert _get_noqa_codes("op.execute(...)  # noqa: MIG001") == {"MIG001"}
+
+    def test_multiple_codes(self):
+        assert _get_noqa_codes("op.execute(...)  # noqa: MIG001, MIG003") == 
{"MIG001", "MIG003"}
+
+    def test_code_with_reason_suffix(self):
+        # Reason after '--' should NOT be included in the code set.
+        codes = _get_noqa_codes("op.execute(...)  # noqa: MIG003 -- safe in 
offline mode")
+        assert "MIG003" in codes
+        assert "--" not in "".join(codes)
+        assert "safe" not in "".join(codes)
+
+    def test_no_noqa_comment(self):
+        assert _get_noqa_codes("op.execute('UPDATE foo SET x=1')") == set()
+
+    def test_empty_string(self):
+        assert _get_noqa_codes("") == set()
+
+
+# ---------------------------------------------------------------------------
+# _line_has_noqa
+# ---------------------------------------------------------------------------
+
+
+class TestLineHasNoqa:
+    def test_line_has_matching_code(self):
+        lines = ["op.execute('UPDATE ...')  # noqa: MIG001"]
+        assert _line_has_noqa(lines, 1, "MIG001") is True
+
+    def test_line_has_different_code(self):
+        lines = ["op.execute('UPDATE ...')  # noqa: MIG002"]
+        assert _line_has_noqa(lines, 1, "MIG001") is False
+
+    def test_out_of_bounds_zero(self):
+        assert _line_has_noqa(["some line"], 0, "MIG001") is False
+
+    def test_out_of_bounds_beyond_end(self):
+        assert _line_has_noqa(["some line"], 2, "MIG001") is False
+
+
+# ---------------------------------------------------------------------------
+# check_mig001
+# ---------------------------------------------------------------------------
+
+
+class TestCheckMig001:

Review Comment:
   reorganized/grouped/parameterized



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

Reply via email to