Skip to content

Commit aaa3a52

Browse files
SNOW-241508 stabilizing codecov (snowflakedb#564)
1 parent 13e05e8 commit aaa3a52

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

Diff for: src/snowflake/connector/cursor.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272

7373
ASYNC_NO_DATA_MAX_RETRY = 24
7474
ASYNC_RETRY_PATTERN = [1, 1, 2, 3, 4, 8, 10]
75+
INCIDENT_BLACKLIST = (KeyError, ValueError, TypeError)
7576

7677

7778
def exit_handler(*_): # pragma: no cover
@@ -516,10 +517,9 @@ def execute(self,
516517
# TODO we could probably rework this to not make dicts like this: {'1': 'value', '2': '13'}
517518
processed_params = self._connection._process_params_qmarks(params, self)
518519
# Skip reporting Key, Value and Type errors
519-
except (KeyError, ValueError, TypeError):
520-
raise
521-
except Exception:
522-
self.connection.incident.report_incident()
520+
except Exception as exc: # pragma: no cover
521+
if not isinstance(exc, INCIDENT_BLACKLIST):
522+
self.connection.incident.report_incident()
523523
raise
524524

525525
m = DESC_TABLE_RE.match(query)
@@ -954,7 +954,7 @@ def wait_until_ready():
954954
status = self.connection.get_query_status(sfqid)
955955
if not self.connection.is_still_running(status):
956956
break
957-
if status == QueryStatus.NO_DATA:
957+
if status == QueryStatus.NO_DATA: # pragma: no cover
958958
no_data_counter += 1
959959
if no_data_counter > ASYNC_NO_DATA_MAX_RETRY:
960960
raise DatabaseError("Cannot retrieve data on the status of this query. No information returned "

Diff for: test/integ/test_async.py

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
QueryStatus = None
1919

2020

21+
def test_simple_async(conn_cnx):
22+
"""Simple test to that shows the most simple usage of fire and forget.
23+
24+
This test also makes sure that wait_until_ready function's sleeping is tested.
25+
"""
26+
with conn_cnx() as con:
27+
with con.cursor() as cur:
28+
cur.execute_async('select count(*) from table(generator(timeLimit => 5))')
29+
cur.get_results_from_sfqid(cur.sfqid)
30+
assert len(cur.fetchall()) == 1
31+
32+
2133
def test_async_exec(conn_cnx):
2234
"""Tests whether simple async query execution works.
2335

Diff for: test/integ/test_connection.py

+11
Original file line numberDiff line numberDiff line change
@@ -924,3 +924,14 @@ def test_process_param_dict_error(conn_cnx):
924924
side_effect=Exception('test')):
925925
conn._process_params({'asd': 'something'})
926926
assert pe.errno == ER_FAILED_PROCESSING_PYFORMAT
927+
928+
929+
@pytest.mark.skipolddriver
930+
def test_process_param_error(conn_cnx):
931+
"""Tests whether exceptions in __process_params_dict are handled correctly."""
932+
with conn_cnx() as conn:
933+
with pytest.raises(ProgrammingError, match="Failed processing pyformat-parameters; test") as pe:
934+
with mock.patch('snowflake.connector.converter.SnowflakeConverter.to_snowflake',
935+
side_effect=Exception('test')):
936+
conn._process_params(mock.Mock())
937+
assert pe.errno == ER_FAILED_PROCESSING_PYFORMAT

Diff for: test/unit/test_converter.py

+16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
from logging import getLogger
88

9+
import pytest
10+
11+
from snowflake.connector import ProgrammingError
912
from snowflake.connector.connection import DefaultConverterClass
13+
from snowflake.connector.converter import SnowflakeConverter
1014
from snowflake.connector.converter_snowsql import SnowflakeConverterSnowSQL
1115

1216
logger = getLogger(__name__)
@@ -66,3 +70,15 @@ def test_more_timestamps():
6670
assert m('-2208943503.8765432') == '1900-01-01 12:34:56.123456800'
6771
assert m('-2208943503.0000000') == '1900-01-01 12:34:57.000000000'
6872
assert m('-2208943503.0120000') == '1900-01-01 12:34:56.988000000'
73+
74+
75+
def test_converter_to_snowflake_error():
76+
converter = SnowflakeConverter()
77+
with pytest.raises(ProgrammingError, match=r'Binding data in type \(bogus\) is not supported'):
78+
converter._bogus_to_snowflake('Bogus')
79+
80+
81+
def test_converter_to_snowflake_bindings_error():
82+
converter = SnowflakeConverter()
83+
with pytest.raises(ProgrammingError, match=r'Binding data in type \(somethingsomething\) is not supported'):
84+
converter._somethingsomething_to_snowflake_bindings('Bogus')

Diff for: tox.ini

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ show_missing = True
55
branch = true
66
parallel = true
77
omit = */snowflake/connector/tool/*
8+
src/snowflake/connector/incident.py
89
[coverage:paths]
910
source = src/snowflake/connector
1011
*/.tox/*/lib/python*/site-packages/snowflake/connector
@@ -45,7 +46,9 @@ setenv =
4546
unit: SNOWFLAKE_TEST_TYPE = unit
4647
integ: SNOWFLAKE_TEST_TYPE = integ
4748
# Add common parts into pytest command
48-
SNOWFLAKE_PYTEST_CMD = pytest {env:SNOWFLAKE_PYTEST_OPTS:} --cov snowflake.connector --junitxml {env:JUNIT_REPORT_DIR:{toxworkdir}}/junit.{envname}-{env:cloud_provider:dev}.xml
49+
SNOWFLAKE_PYTEST_COV_LOCATION = {env:JUNIT_REPORT_DIR:{toxworkdir}}/junit.{envname}-{env:cloud_provider:dev}.xml
50+
SNOWFLAKE_PYTEST_COV_CMD = --cov snowflake.connector --junitxml {env:SNOWFLAKE_PYTEST_COV_LOCATION} --cov-report=
51+
SNOWFLAKE_PYTEST_CMD = pytest {env:SNOWFLAKE_PYTEST_OPTS:} {env:SNOWFLAKE_PYTEST_COV_CMD}
4952
passenv =
5053
AWS_ACCESS_KEY_ID
5154
AWS_SECRET_ACCESS_KEY

0 commit comments

Comments
 (0)