Skip to content

Commit 70d1092

Browse files
SNOW-199087 Moved functions using pytest to test folder (#1362)
Co-authored-by: Mark Keller <[email protected]>
1 parent 9bc2e1f commit 70d1092

File tree

3 files changed

+48
-49
lines changed

3 files changed

+48
-49
lines changed

src/snowflake/connector/test_util.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77

88
import logging
99
import os
10-
import time
11-
12-
import pytest
13-
14-
import snowflake.connector.connection
15-
from snowflake.connector.constants import QueryStatus
1610

1711
from .compat import IS_LINUX
1812

@@ -35,37 +29,3 @@
3529
)
3630
)
3731
rt_plain_logger.addHandler(ch)
38-
39-
40-
def _wait_while_query_running(
41-
con: snowflake.connector.connection.SnowflakeConnection,
42-
sfqid: str,
43-
sleep_time: int,
44-
dont_cache: bool = False,
45-
) -> None:
46-
"""
47-
Checks if the provided still returns that it is still running, and if so,
48-
sleeps for the specified time in a while loop.
49-
"""
50-
query_status = con._get_query_status if dont_cache else con.get_query_status
51-
while con.is_still_running(query_status(sfqid)):
52-
time.sleep(sleep_time)
53-
54-
55-
def _wait_until_query_success(
56-
con: snowflake.connector.connection.SnowflakeConnection,
57-
sfqid: str,
58-
num_checks: int,
59-
sleep_per_check: int,
60-
) -> None:
61-
for _ in range(num_checks):
62-
status = con.get_query_status(sfqid)
63-
if status == QueryStatus.SUCCESS:
64-
break
65-
time.sleep(sleep_per_check)
66-
else:
67-
pytest.fail(
68-
"We should have broke out of wait loop for query success."
69-
f"Query ID: {sfqid}"
70-
f"Final query status: {status}"
71-
)

test/helpers.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44
#
55
from __future__ import annotations
66

7-
from typing import Pattern, Sequence
7+
import time
8+
from typing import TYPE_CHECKING, Pattern, Sequence
89
from unittest.mock import Mock
910

11+
import pytest
12+
1013
from snowflake.connector.compat import OK
1114

15+
if TYPE_CHECKING:
16+
import snowflake.connector.connection
17+
18+
try:
19+
from snowflake.connector.constants import QueryStatus
20+
except ImportError:
21+
QueryStatus = None
22+
1223

1324
def create_mock_response(status_code: int) -> Mock:
1425
"""Create a Mock "Response" with a given status code. See `test_result_batch.py` for examples.
@@ -43,3 +54,37 @@ def verify_log_tuple(
4354
):
4455
return True
4556
return False
57+
58+
59+
def _wait_while_query_running(
60+
con: snowflake.connector.connection.SnowflakeConnection,
61+
sfqid: str,
62+
sleep_time: int,
63+
dont_cache: bool = False,
64+
) -> None:
65+
"""
66+
Checks if the provided still returns that it is still running, and if so,
67+
sleeps for the specified time in a while loop.
68+
"""
69+
query_status = con._get_query_status if dont_cache else con.get_query_status
70+
while con.is_still_running(query_status(sfqid)):
71+
time.sleep(sleep_time)
72+
73+
74+
def _wait_until_query_success(
75+
con: snowflake.connector.connection.SnowflakeConnection,
76+
sfqid: str,
77+
num_checks: int,
78+
sleep_per_check: int,
79+
) -> None:
80+
for _ in range(num_checks):
81+
status = con.get_query_status(sfqid)
82+
if status == QueryStatus.SUCCESS:
83+
break
84+
time.sleep(sleep_per_check)
85+
else:
86+
pytest.fail(
87+
"We should have broke out of wait loop for query success."
88+
f"Query ID: {sfqid}"
89+
f"Final query status: {status}"
90+
)

test/integ/test_multi_statement.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from snowflake.connector.version import VERSION
88

9+
from ..helpers import _wait_until_query_success, _wait_while_query_running
10+
911
pytestmark = [
1012
pytest.mark.skipolddriver,
1113
pytest.mark.xfail(
@@ -17,14 +19,6 @@
1719
import snowflake.connector.cursor
1820
from snowflake.connector import ProgrammingError, errors
1921

20-
try:
21-
from snowflake.connector.test_util import (
22-
_wait_until_query_success,
23-
_wait_while_query_running,
24-
)
25-
except ModuleNotFoundError:
26-
pass
27-
2822
try: # pragma: no cover
2923
from snowflake.connector.constants import (
3024
PARAMETER_MULTI_STATEMENT_COUNT,

0 commit comments

Comments
 (0)