Skip to content

Commit 8443333

Browse files
NO-SNOW: Tests for metadata preservation added
1 parent dd3ec3e commit 8443333

File tree

3 files changed

+82
-82
lines changed

3 files changed

+82
-82
lines changed

src/snowflake/connector/aio/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from functools import update_wrapper, wraps
3+
from functools import update_wrapper
44
from typing import (
55
Any,
66
Callable,
@@ -185,9 +185,6 @@ class _AsyncConnectWrapper:
185185
as the synchronous snowflake.connector.connect function.
186186
"""
187187

188-
def __init__(self) -> None: ...
189-
190-
@wraps(SnowflakeConnection.__init__)
191188
def __call__(
192189
self, **kwargs: Any
193190
) -> HybridCoroutineContextManager[SnowflakeConnection]:

test/integ/aio_it/test_connection_async.py

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import snowflake.connector.aio
2626
from snowflake.connector import DatabaseError, OperationalError, ProgrammingError
27-
from snowflake.connector.aio import SnowflakeConnection, connect
27+
from snowflake.connector.aio import SnowflakeConnection
2828
from snowflake.connector.aio._description import CLIENT_NAME
2929
from snowflake.connector.compat import IS_WINDOWS
3030
from snowflake.connector.connection import DEFAULT_CLIENT_PREFETCH_THREADS
@@ -1751,80 +1751,3 @@ async def test_no_new_warnings_or_errors_on_successful_basic_select(conn_cnx, ca
17511751
f"Error count increased from {baseline_error_count} to {test_error_count}. "
17521752
f"New errors: {[r.getMessage() for r in caplog.records if r.levelno >= logging.ERROR]}"
17531753
)
1754-
1755-
1756-
@pytest.mark.skipolddriver
1757-
async def test_connect_metadata_preservation():
1758-
"""Test that the async connect function preserves metadata from SnowflakeConnection.__init__.
1759-
1760-
This test verifies that various inspection methods return consistent metadata,
1761-
ensuring IDE support, type checking, and documentation generation work correctly.
1762-
"""
1763-
import inspect
1764-
1765-
# Test 1: Check __name__ and __qualname__ are overridden correctly
1766-
# tODO: the only difference is that this is __init__ in synch connect
1767-
assert (
1768-
connect.__name__ == "connect"
1769-
), f"connect.__name__ should be 'connect', but got '{connect.__name__}'"
1770-
assert (
1771-
connect.__qualname__ == "connect"
1772-
), f"connect.__qualname__ should be 'connect', but got '{connect.__qualname__}'"
1773-
1774-
# Test 2: Check __wrapped__ points to SnowflakeConnection.__init__
1775-
assert hasattr(connect, "__wrapped__"), "connect should have __wrapped__ attribute"
1776-
assert (
1777-
connect.__wrapped__ is SnowflakeConnection.__init__
1778-
), "connect.__wrapped__ should reference SnowflakeConnection.__init__"
1779-
1780-
# Test 3: Check __module__ is preserved
1781-
assert hasattr(connect, "__module__"), "connect should have __module__ attribute"
1782-
assert connect.__module__ == SnowflakeConnection.__init__.__module__, (
1783-
f"connect.__module__ should match SnowflakeConnection.__init__.__module__, "
1784-
f"but got '{connect.__module__}' vs '{SnowflakeConnection.__init__.__module__}'"
1785-
)
1786-
1787-
# Test 4: Check __doc__ is preserved
1788-
assert hasattr(connect, "__doc__"), "connect should have __doc__ attribute"
1789-
assert (
1790-
connect.__doc__ == SnowflakeConnection.__init__.__doc__
1791-
), "connect.__doc__ should match SnowflakeConnection.__init__.__doc__"
1792-
1793-
# Test 5: Check __annotations__ are preserved (or at least available)
1794-
assert hasattr(
1795-
connect, "__annotations__"
1796-
), "connect should have __annotations__ attribute"
1797-
src_annotations = getattr(SnowflakeConnection.__init__, "__annotations__", {})
1798-
connect_annotations = getattr(connect, "__annotations__", {})
1799-
assert connect_annotations == src_annotations, (
1800-
f"connect.__annotations__ should match SnowflakeConnection.__init__.__annotations__, "
1801-
f"but got {connect_annotations} vs {src_annotations}"
1802-
)
1803-
1804-
# Test 6: Check inspect.signature works correctly
1805-
try:
1806-
connect_sig = inspect.signature(connect)
1807-
source_sig = inspect.signature(SnowflakeConnection.__init__)
1808-
assert str(connect_sig) == str(source_sig), (
1809-
f"inspect.signature(connect) should match inspect.signature(SnowflakeConnection.__init__), "
1810-
f"but got '{connect_sig}' vs '{source_sig}'"
1811-
)
1812-
except Exception as e:
1813-
pytest.fail(f"inspect.signature(connect) failed: {e}")
1814-
1815-
# Test 7: Check inspect.getdoc works correctly
1816-
connect_doc = inspect.getdoc(connect)
1817-
source_doc = inspect.getdoc(SnowflakeConnection.__init__)
1818-
assert connect_doc == source_doc, (
1819-
"inspect.getdoc(connect) should match inspect.getdoc(SnowflakeConnection.__init__)"
1820-
)
1821-
1822-
# Test 8: Check that connect is callable and returns expected type
1823-
assert callable(connect), "connect should be callable"
1824-
1825-
# Test 9: Verify the instance has proper introspection capabilities
1826-
# IDEs and type checkers should be able to resolve parameters
1827-
sig = inspect.signature(connect)
1828-
params = list(sig.parameters.keys())
1829-
assert len(params) > 0, "connect should have parameters from SnowflakeConnection.__init__"
1830-

test/unit/aio/test_connection_async_unit.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,3 +863,83 @@ async def test_large_query_through_proxy_async(
863863
"/queries/v1/query-request" in r["request"]["url"]
864864
for r in target_reqs["requests"]
865865
)
866+
867+
868+
@pytest.mark.skipolddriver
869+
async def test_connect_metadata_preservation():
870+
"""Test that the async connect function preserves metadata from SnowflakeConnection.__init__.
871+
872+
This test verifies that various inspection methods return consistent metadata,
873+
ensuring IDE support, type checking, and documentation generation work correctly.
874+
"""
875+
import inspect
876+
877+
from snowflake.connector.aio import SnowflakeConnection, connect
878+
879+
# Test 1: Check __name__ and __qualname__ are overridden correctly
880+
# tODO: the only difference is that this is __init__ in synch connect
881+
assert (
882+
connect.__name__ == "connect"
883+
), f"connect.__name__ should be 'connect', but got '{connect.__name__}'"
884+
assert (
885+
connect.__qualname__ == "connect"
886+
), f"connect.__qualname__ should be 'connect', but got '{connect.__qualname__}'"
887+
888+
# Test 2: Check __wrapped__ points to SnowflakeConnection.__init__
889+
assert hasattr(connect, "__wrapped__"), "connect should have __wrapped__ attribute"
890+
assert (
891+
connect.__wrapped__ is SnowflakeConnection.__init__
892+
), "connect.__wrapped__ should reference SnowflakeConnection.__init__"
893+
894+
# Test 3: Check __module__ is preserved
895+
assert hasattr(connect, "__module__"), "connect should have __module__ attribute"
896+
assert connect.__module__ == SnowflakeConnection.__init__.__module__, (
897+
f"connect.__module__ should match SnowflakeConnection.__init__.__module__, "
898+
f"but got '{connect.__module__}' vs '{SnowflakeConnection.__init__.__module__}'"
899+
)
900+
901+
# Test 4: Check __doc__ is preserved
902+
assert hasattr(connect, "__doc__"), "connect should have __doc__ attribute"
903+
assert (
904+
connect.__doc__ == SnowflakeConnection.__init__.__doc__
905+
), "connect.__doc__ should match SnowflakeConnection.__init__.__doc__"
906+
907+
# Test 5: Check __annotations__ are preserved (or at least available)
908+
assert hasattr(
909+
connect, "__annotations__"
910+
), "connect should have __annotations__ attribute"
911+
src_annotations = getattr(SnowflakeConnection.__init__, "__annotations__", {})
912+
connect_annotations = getattr(connect, "__annotations__", {})
913+
assert connect_annotations == src_annotations, (
914+
f"connect.__annotations__ should match SnowflakeConnection.__init__.__annotations__, "
915+
f"but got {connect_annotations} vs {src_annotations}"
916+
)
917+
918+
# Test 6: Check inspect.signature works correctly
919+
try:
920+
connect_sig = inspect.signature(connect)
921+
source_sig = inspect.signature(SnowflakeConnection.__init__)
922+
assert str(connect_sig) == str(source_sig), (
923+
f"inspect.signature(connect) should match inspect.signature(SnowflakeConnection.__init__), "
924+
f"but got '{connect_sig}' vs '{source_sig}'"
925+
)
926+
except Exception as e:
927+
pytest.fail(f"inspect.signature(connect) failed: {e}")
928+
929+
# Test 7: Check inspect.getdoc works correctly
930+
connect_doc = inspect.getdoc(connect)
931+
source_doc = inspect.getdoc(SnowflakeConnection.__init__)
932+
assert (
933+
connect_doc == source_doc
934+
), "inspect.getdoc(connect) should match inspect.getdoc(SnowflakeConnection.__init__)"
935+
936+
# Test 8: Check that connect is callable and returns expected type
937+
assert callable(connect), "connect should be callable"
938+
939+
# Test 9: Verify the instance has proper introspection capabilities
940+
# IDEs and type checkers should be able to resolve parameters
941+
sig = inspect.signature(connect)
942+
params = list(sig.parameters.keys())
943+
assert (
944+
len(params) > 0
945+
), "connect should have parameters from SnowflakeConnection.__init__"

0 commit comments

Comments
 (0)