Skip to content

Commit

Permalink
Expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bchinn committed Nov 16, 2023
1 parent 166abfe commit 67c4c01
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions tests/unit/test_error_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,42 @@
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
#

from snowflake.connector import ProgrammingError
from snowflake.connector import OperationalError, ProgrammingError
from snowflake.snowpark._internal.error_message import SnowparkClientExceptionMessages
from snowflake.snowpark.exceptions import SnowparkSQLException


def test_programming_error_sql_exception_attributes():
def test_sql_exception_from_programming_error():
pe = ProgrammingError(
msg="errmsg",
errno=123456,
sqlstate="P0000",
sfqid="the_query_id",
query="select * from foo",
msg="test message",
errno=123,
sfqid="0000-1111",
query="SELECT CURRENT_USER()",
)
sql_exception = (
SnowparkClientExceptionMessages.SQL_EXCEPTION_FROM_PROGRAMMING_ERROR(pe)
ex = SnowparkClientExceptionMessages.SQL_EXCEPTION_FROM_PROGRAMMING_ERROR(pe)
assert type(ex) == SnowparkSQLException
assert ex.error_code == "1304"
assert ex.conn_error == pe
assert ex.sfqid == "0000-1111"
assert ex.query == "SELECT CURRENT_USER()"
assert ex.message == "000123: test message"
assert ex.sql_error_code == 123
assert ex.raw_message == "test message"


def test_sql_exception_from_operational_error():
oe = OperationalError(
msg="test message",
errno=123,
sfqid="0000-1111",
query="SELECT CURRENT_USER()",
)
assert sql_exception.sql_error_code == 123456
assert sql_exception.raw_message == "errmsg"
ex = SnowparkClientExceptionMessages.SQL_EXCEPTION_FROM_OPERATIONAL_ERROR(oe)
assert type(ex) == SnowparkSQLException
assert ex.error_code == "1305"
assert ex.conn_error == oe
assert ex.sfqid == "0000-1111"
assert ex.query == "SELECT CURRENT_USER()"
assert ex.message == "000123: test message"
assert ex.sql_error_code == 123
assert ex.raw_message == "test message"

0 comments on commit 67c4c01

Please sign in to comment.