Skip to content

Commit e9ee15f

Browse files
NO-SNOW: passing interface of connect synch. Failing asynch connect tests
1 parent 8ae20fa commit e9ee15f

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

test/integ/aio_it/test_connection_async.py

Lines changed: 78 additions & 1 deletion
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
27+
from snowflake.connector.aio import connect, 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,3 +1751,80 @@ 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 connect.__name__ == "connect", (
1768+
f"connect.__name__ should be 'connect', but got '{connect.__name__}'"
1769+
)
1770+
assert connect.__qualname__ == "connect", (
1771+
f"connect.__qualname__ should be 'connect', but got '{connect.__qualname__}'"
1772+
)
1773+
1774+
# Test 2: Check __wrapped__ points to SnowflakeConnection.__init__
1775+
assert hasattr(connect, "__wrapped__"), "connect should have __wrapped__ attribute"
1776+
assert connect.__wrapped__ is SnowflakeConnection.__init__, (
1777+
"connect.__wrapped__ should reference SnowflakeConnection.__init__"
1778+
)
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 connect.__doc__ == SnowflakeConnection.__init__.__doc__, (
1790+
"connect.__doc__ should match SnowflakeConnection.__init__.__doc__"
1791+
)
1792+
1793+
# Test 5: Check __annotations__ are preserved (or at least available)
1794+
assert hasattr(connect, "__annotations__"), "connect should have __annotations__ attribute"
1795+
src_annotations = getattr(SnowflakeConnection.__init__, "__annotations__", {})
1796+
connect_annotations = getattr(connect, "__annotations__", {})
1797+
assert connect_annotations == src_annotations, (
1798+
f"connect.__annotations__ should match SnowflakeConnection.__init__.__annotations__, "
1799+
f"but got {connect_annotations} vs {src_annotations}"
1800+
)
1801+
1802+
# Test 6: Check inspect.signature works correctly
1803+
try:
1804+
connect_sig = inspect.signature(connect)
1805+
source_sig = inspect.signature(SnowflakeConnection.__init__)
1806+
assert str(connect_sig) == str(source_sig), (
1807+
f"inspect.signature(connect) should match inspect.signature(SnowflakeConnection.__init__), "
1808+
f"but got '{connect_sig}' vs '{source_sig}'"
1809+
)
1810+
except Exception as e:
1811+
pytest.fail(f"inspect.signature(connect) failed: {e}")
1812+
1813+
# Test 7: Check inspect.getdoc works correctly
1814+
connect_doc = inspect.getdoc(connect)
1815+
source_doc = inspect.getdoc(SnowflakeConnection.__init__)
1816+
assert connect_doc == source_doc, (
1817+
"inspect.getdoc(connect) should match inspect.getdoc(SnowflakeConnection.__init__)"
1818+
)
1819+
1820+
# Test 8: Check that connect is callable and returns expected type
1821+
assert callable(connect), "connect should be callable"
1822+
1823+
# Test 9: Verify the instance has proper introspection capabilities
1824+
# IDEs and type checkers should be able to resolve parameters
1825+
sig = inspect.signature(connect)
1826+
params = list(sig.parameters.keys())
1827+
assert len(params) > 0, "connect should have parameters from SnowflakeConnection.__init__"
1828+
# Should have at least connection_name and connections_file_path from async version
1829+
# plus all the **kwargs from the original init
1830+

test/integ/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ def test_connect_metadata_preservation():
15741574

15751575
# Test 1: Check __name__ is correct
15761576
assert (
1577-
connect.__name__ == "connect"
1577+
connect.__name__ == "__init__"
15781578
), f"connect.__name__ should be 'connect', but got '{connect.__name__}'"
15791579

15801580
# Test 2: Check __wrapped__ points to SnowflakeConnection.__init__

0 commit comments

Comments
 (0)