Copilot commented on code in PR #2403:
URL: https://github.com/apache/iceberg-python/pull/2403#discussion_r2309169273


##########
tests/catalog/test_rest.py:
##########
@@ -1845,3 +1845,76 @@ def test_rest_catalog_with_google_credentials_path(
     assert len(history) == 1
     actual_headers = history[0].headers
     assert actual_headers["Authorization"] == expected_auth_header
+
+
+class TestRestCatalogClose:
+    """Tests RestCatalog close functionality"""
+
+    EXPECTED_ADAPTERS = 2
+    EXPECTED_ADAPTERS_SIGV4 = 3
+
+    def test_catalog_close(self, rest_mock: Mocker) -> None:
+        rest_mock.get(
+            f"{TEST_URI}v1/config",
+            json={"defaults": {}, "overrides": {}},
+            status_code=200,
+        )
+
+        catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
+        catalog.close()
+        # Verify session still exists after close the session pooled 
connections
+        assert hasattr(catalog, "_session")
+        assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS
+        # Second close should not raise any exception
+        catalog.close()
+
+    def test_rest_catalog_close_sigv4(self, rest_mock: Mocker) -> None:
+        catalog = None

Review Comment:
   The `catalog = None` initialization is unnecessary since the variable is 
immediately assigned in the context manager. This line can be removed.
   ```suggestion
   
   ```



##########
tests/catalog/test_rest.py:
##########
@@ -1845,3 +1845,76 @@ def test_rest_catalog_with_google_credentials_path(
     assert len(history) == 1
     actual_headers = history[0].headers
     assert actual_headers["Authorization"] == expected_auth_header
+
+
+class TestRestCatalogClose:
+    """Tests RestCatalog close functionality"""
+
+    EXPECTED_ADAPTERS = 2
+    EXPECTED_ADAPTERS_SIGV4 = 3
+
+    def test_catalog_close(self, rest_mock: Mocker) -> None:
+        rest_mock.get(
+            f"{TEST_URI}v1/config",
+            json={"defaults": {}, "overrides": {}},
+            status_code=200,
+        )
+
+        catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
+        catalog.close()
+        # Verify session still exists after close the session pooled 
connections
+        assert hasattr(catalog, "_session")
+        assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS
+        # Second close should not raise any exception
+        catalog.close()
+
+    def test_rest_catalog_close_sigv4(self, rest_mock: Mocker) -> None:
+        catalog = None
+        rest_mock.get(
+            f"{TEST_URI}v1/config",
+            json={"defaults": {}, "overrides": {}},
+            status_code=200,
+        )
+
+        catalog = RestCatalog("rest", **{"uri": TEST_URI, "token": TEST_TOKEN, 
"rest.sigv4-enabled": "true"})
+        catalog.close()
+        assert hasattr(catalog, "_session")
+        assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS_SIGV4
+
+    def test_rest_catalog_context_manager_with_exception(self, rest_mock: 
Mocker) -> None:
+        """Test RestCatalog context manager properly closes with exceptions."""
+        catalog = None

Review Comment:
   The `catalog = None` initialization is unnecessary since the variable is 
immediately assigned in the context manager. This line can be removed.
   ```suggestion
   
   ```



##########
tests/catalog/test_rest.py:
##########
@@ -1845,3 +1845,76 @@ def test_rest_catalog_with_google_credentials_path(
     assert len(history) == 1
     actual_headers = history[0].headers
     assert actual_headers["Authorization"] == expected_auth_header
+
+
+class TestRestCatalogClose:
+    """Tests RestCatalog close functionality"""
+
+    EXPECTED_ADAPTERS = 2
+    EXPECTED_ADAPTERS_SIGV4 = 3
+
+    def test_catalog_close(self, rest_mock: Mocker) -> None:
+        rest_mock.get(
+            f"{TEST_URI}v1/config",
+            json={"defaults": {}, "overrides": {}},
+            status_code=200,
+        )
+
+        catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
+        catalog.close()
+        # Verify session still exists after close the session pooled 
connections
+        assert hasattr(catalog, "_session")
+        assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS
+        # Second close should not raise any exception
+        catalog.close()
+
+    def test_rest_catalog_close_sigv4(self, rest_mock: Mocker) -> None:
+        catalog = None
+        rest_mock.get(
+            f"{TEST_URI}v1/config",
+            json={"defaults": {}, "overrides": {}},
+            status_code=200,
+        )
+
+        catalog = RestCatalog("rest", **{"uri": TEST_URI, "token": TEST_TOKEN, 
"rest.sigv4-enabled": "true"})
+        catalog.close()
+        assert hasattr(catalog, "_session")
+        assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS_SIGV4
+
+    def test_rest_catalog_context_manager_with_exception(self, rest_mock: 
Mocker) -> None:
+        """Test RestCatalog context manager properly closes with exceptions."""
+        catalog = None
+        rest_mock.get(
+            f"{TEST_URI}v1/config",
+            json={"defaults": {}, "overrides": {}},
+            status_code=200,
+        )
+
+        try:
+            with RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) as cat:
+                catalog = cat
+                raise ValueError("Test exception")
+        except ValueError:
+            pass
+
+        assert catalog is not None and hasattr(catalog, "_session")
+        assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS
+
+    def test_rest_catalog_context_manager_with_exception_sigv4(self, 
rest_mock: Mocker) -> None:
+        """Test RestCatalog context manager properly closes with exceptions."""
+        catalog = None

Review Comment:
   The `catalog = None` initialization is unnecessary since the variable is 
immediately assigned in the context manager. This line can be removed.
   ```suggestion
   
   ```



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