Skip to content

Commit b151e77

Browse files
Linting fix for CI to pass
1 parent 0176ddb commit b151e77

File tree

2 files changed

+28
-45
lines changed

2 files changed

+28
-45
lines changed

src/snowflake/connector/aio/_pandas_tools.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
from snowflake.connector import ProgrammingError
1010
from snowflake.connector.options import pandas
11+
12+
# Import utilities from sync version
13+
from snowflake.connector.pandas_tools import (
14+
_iceberg_config_statement_helper,
15+
build_location_helper,
16+
chunk_helper,
17+
)
1118
from snowflake.connector.telemetry import TelemetryData, TelemetryField
1219

1320
from .._utils import (
@@ -16,13 +23,6 @@
1623
random_name_for_temp_object,
1724
)
1825
from ..constants import _PARAM_USE_SCOPED_TEMP_FOR_PANDAS_TOOLS
19-
20-
# Import utilities from sync version
21-
from ..pandas_tools import (
22-
_iceberg_config_statement_helper,
23-
build_location_helper,
24-
chunk_helper,
25-
)
2626
from ._cursor import SnowflakeCursor
2727

2828
if TYPE_CHECKING: # pragma: no cover

test/integ/aio_it/test_pandas_tools_async.py

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
from __future__ import annotations
33

44
import math
5-
import re
65
from datetime import datetime, timedelta, timezone
76
from typing import TYPE_CHECKING, Any, Callable, Generator
87
from unittest import mock
9-
from unittest.mock import MagicMock
8+
from unittest.mock import AsyncMock, MagicMock
109

1110
import numpy.random
1211
import pytest
@@ -24,11 +23,9 @@
2423
try:
2524
from snowflake.connector.aio._pandas_tools import write_pandas
2625
from snowflake.connector.options import pandas
27-
from snowflake.connector.pandas_tools import _iceberg_config_statement_helper
2826
except ImportError:
2927
pandas = None
3028
write_pandas = None
31-
_iceberg_config_statement_helper = None
3229

3330
if TYPE_CHECKING:
3431
from snowflake.connector.aio import SnowflakeConnection
@@ -520,7 +517,10 @@ async def mocked_execute(*args, **kwargs):
520517
if len(args) >= 1 and args[0].startswith("COPY INTO"):
521518
assert kwargs["params"][0] == expected_location
522519
cur = SnowflakeCursor(cnx)
523-
cur._result = iter([])
520+
# Create a mock result iterator with fetch_all_data method
521+
mock_result = MagicMock()
522+
mock_result.fetch_all_data = AsyncMock(return_value=[])
523+
cur._result = mock_result
524524
return cur
525525

526526
with mock.patch(
@@ -572,7 +572,10 @@ async def mocked_execute(*args, **kwargs):
572572
db_schema = ".".join(args[0].split(" ")[-1].split(".")[:-1])
573573
assert db_schema == expected_db_schema
574574
cur = SnowflakeCursor(cnx)
575-
cur._result = iter([])
575+
# Create a mock result iterator with fetch_all_data method
576+
mock_result = MagicMock()
577+
mock_result.fetch_all_data = AsyncMock(return_value=[])
578+
cur._result = mock_result
576579
return cur
577580

578581
with mock.patch(
@@ -626,7 +629,10 @@ async def mocked_execute(*args, **kwargs):
626629
db_schema = ".".join(args[0].split(" ")[-1].split(".")[:-1])
627630
assert db_schema == expected_db_schema
628631
cur = SnowflakeCursor(cnx)
629-
cur._result = iter([])
632+
# Create a mock result iterator with fetch_all_data method
633+
mock_result = MagicMock()
634+
mock_result.fetch_all_data = AsyncMock(return_value=[])
635+
cur._result = mock_result
630636
return cur
631637

632638
with mock.patch(
@@ -682,13 +688,18 @@ async def mocked_execute(*args, **kwargs):
682688
db_schema = ".".join(args[0].split(" ")[3].split(".")[:-1])
683689
assert db_schema == expected_db_schema
684690
cur = SnowflakeCursor(cnx)
691+
mock_result = MagicMock()
685692
if args[0].startswith("SELECT"):
686693
cur._rownumber = 0
687-
cur._result = iter(
688-
[(col, "") for col in sf_connector_version_df.get().columns]
694+
# Create a mock result iterator with fetch_all_data method
695+
mock_result.fetch_all_data = AsyncMock(
696+
return_value=[
697+
(col, "") for col in sf_connector_version_df.get().columns
698+
]
689699
)
690700
else:
691-
cur._result = iter([])
701+
mock_result.fetch_all_data = AsyncMock(return_value=[])
702+
cur._result = mock_result
692703
return cur
693704

694705
with mock.patch(
@@ -1032,34 +1043,6 @@ async def mock_execute(*args, **kwargs):
10321043
await cnx.execute_string(f"drop schema if exists {target_schema}")
10331044

10341045

1035-
def test__iceberg_config_statement_helper():
1036-
config = {
1037-
"EXTERNAL_VOLUME": "vol",
1038-
"CATALOG": "'SNOWFLAKE'",
1039-
"BASE_LOCATION": "/root",
1040-
"CATALOG_SYNC": "foo",
1041-
"STORAGE_SERIALIZATION_POLICY": "bar",
1042-
}
1043-
assert (
1044-
_iceberg_config_statement_helper(config)
1045-
== "EXTERNAL_VOLUME='vol' CATALOG='SNOWFLAKE' BASE_LOCATION='/root' CATALOG_SYNC='foo' STORAGE_SERIALIZATION_POLICY='bar'"
1046-
)
1047-
1048-
config["STORAGE_SERIALIZATION_POLICY"] = None
1049-
assert (
1050-
_iceberg_config_statement_helper(config)
1051-
== "EXTERNAL_VOLUME='vol' CATALOG='SNOWFLAKE' BASE_LOCATION='/root' CATALOG_SYNC='foo'"
1052-
)
1053-
1054-
config["foo"] = True
1055-
config["bar"] = True
1056-
with pytest.raises(
1057-
ProgrammingError,
1058-
match=re.escape("Invalid iceberg configurations option(s) provided BAR, FOO"),
1059-
):
1060-
_iceberg_config_statement_helper(config)
1061-
1062-
10631046
async def test_write_pandas_with_on_error(
10641047
conn_cnx: Callable[..., Generator[SnowflakeConnection]],
10651048
):

0 commit comments

Comments
 (0)