@@ -116,18 +116,27 @@ def test_char(trino_connection):
116116def test_varbinary (trino_connection ):
117117 SqlTest (trino_connection ) \
118118 .add_field (sql = "X'65683F'" , python = 'ZWg/' ) \
119- .add_field (sql = "X'0001020304050607080DF9367AA7000000 '" , python = 'AAECAwQFBgcIDfk2eqcAAAA= ' ) \
119+ .add_field (sql = "X''" , python = '' ) \
120120 .add_field (sql = "CAST('' AS VARBINARY)" , python = '' ) \
121121 .add_field (sql = "from_utf8(CAST('😂😂😂😂😂😂' AS VARBINARY))" , python = '😂😂😂😂😂😂' ) \
122122 .add_field (sql = "CAST(null AS VARBINARY)" , python = None ) \
123123 .execute ()
124124
125125
126+ def test_varbinary_failure (trino_connection ):
127+ SqlExpectFailureTest (trino_connection ) \
128+ .execute ("CAST(42 AS VARBINARY)" )
129+
130+
126131def test_json (trino_connection ):
127132 SqlTest (trino_connection ) \
128133 .add_field (sql = "CAST('{}' AS JSON)" , python = '"{}"' ) \
129134 .add_field (sql = "CAST('null' AS JSON)" , python = '"null"' ) \
130135 .add_field (sql = "CAST(null AS JSON)" , python = None ) \
136+ .add_field (sql = "CAST('3.14' AS JSON)" , python = '"3.14"' ) \
137+ .add_field (sql = "CAST('a string' AS JSON)" , python = '"a string"' ) \
138+ .add_field (sql = "CAST('a \" complex '' string :' AS JSON)" , python = '"a \\ " complex \' string :"' ) \
139+ .add_field (sql = "CAST('[]' AS JSON)" , python = '"[]"' ) \
131140 .execute ()
132141
133142
@@ -219,3 +228,20 @@ def _compare_results(self, actual, expected):
219228 continue
220229
221230 assert actual_val == expected_val
231+
232+
233+ class SqlExpectFailureTest :
234+ def __init__ (self , trino_connection ):
235+ self .cur = trino_connection .cursor (experimental_python_types = True )
236+
237+ def execute (self , field ):
238+ sql = 'SELECT ' + field
239+
240+ try :
241+ self .cur .execute (sql )
242+ self .cur .fetchall ()
243+ success = True
244+ except Exception :
245+ success = False
246+
247+ assert not success , "Test not expected to succeed"
0 commit comments