Copilot commented on code in PR #72605:
URL: https://github.com/apache/airflow/pull/72605#discussion_r3945479057


##########
providers/sftp/tests/unit/sftp/test_exceptions.py:
##########
@@ -0,0 +1,114 @@
+# 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 collections.abc import Generator
+from contextlib import contextmanager
+from typing import Any
+
+import pytest
+
+from airflow.providers.common.compat.sdk import AirflowException
+from airflow.providers.sftp.exceptions import ConnectionNotOpenedException
+from airflow.providers.sftp.hooks.sftp import handle_connection_management
+
+
+class FakeSFTPHook:
+    """
+    Minimal stand-in for :class:`~airflow.providers.sftp.hooks.sftp.SFTPHook`.
+
+    ``handle_connection_management`` only reads ``use_managed_conn`` and 
``conn`` and calls
+    ``get_managed_conn``, so the decorator can be exercised without reaching 
an SFTP server.
+    """
+
+    def __init__(self, *, use_managed_conn: bool, conn: Any = None) -> None:
+        self.use_managed_conn = use_managed_conn
+        self.conn = conn
+        self.managed_conn = "managed-conn"
+        self.managed_conn_opened = 0
+        self.managed_conn_released = 0
+        self.conn_seen_by_wrapped: Any = None
+
+    @contextmanager
+    def get_managed_conn(self) -> Generator[str, None, None]:
+        self.managed_conn_opened += 1
+        try:
+            yield self.managed_conn
+        finally:
+            self.managed_conn_released += 1
+
+    @handle_connection_management
+    def do_work(self, path: str, recursive: bool = False) -> str:
+        self.conn_seen_by_wrapped = self.conn
+        return f"{path}:{recursive}"
+
+    @handle_connection_management
+    def do_failing_work(self) -> None:
+        raise RuntimeError("wrapped call failed")
+
+
+class TestConnectionNotOpenedException:
+    def test_subclasses_airflow_exception(self) -> None:
+        # Callers catch the base class, so narrowing this later would be a 
breaking change.
+        assert issubclass(ConnectionNotOpenedException, AirflowException)
+
+    def test_keeps_its_message(self) -> None:
+        assert str(ConnectionNotOpenedException("connection is not open")) == 
"connection is not open"
+

Review Comment:
   `test_keeps_its_message` is asserting Python's default exception message 
behavior (i.e., `Exception.__str__`) rather than provider logic, so it doesn't 
meaningfully guard against regressions in `ConnectionNotOpenedException` (it 
has no custom behavior). Consider removing this test and keeping the message 
assertion on the actual raise site in `handle_connection_management` (which you 
already cover below).



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