itz-puneet commented on code in PR #72605:
URL: https://github.com/apache/airflow/pull/72605#discussion_r3945624349


##########
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:
   Agreed — removed in cfd5a59. The class has no custom `__str__`, so that 
assertion was testing the standard library; the message is still pinned where 
it matters, at the raise site in 
`test_raises_when_unmanaged_and_no_connection_is_open`.



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