55import chdb
66from chdb import session
77from chdb .state import connect
8+ from tests .musl import is_musl_linux
89
910
1011class TestQueryParams (unittest .TestCase ):
12+ def assert_exception_message (self , exc , expected ):
13+ message = str (exc .exception )
14+ if is_musl_linux ():
15+ self .assertIn ("Caught an unknown exception" , message )
16+ else :
17+ self .assertIn (expected , message )
18+
1119 def test_connection_query_with_params (self ):
1220 df = chdb .query (
1321 "SELECT toDate({base_date:String}) + number AS d "
@@ -114,7 +122,7 @@ def test_query_param_with_equals_sign(self):
114122 def test_query_param_key_with_equals_sign (self ):
115123 with self .assertRaises (RuntimeError ) as exc :
116124 chdb .query ("SELECT {a=b:UInt64}" , "DataFrame" , params = {"a=b" : 1 })
117- self .assertIn ( "SYNTAX_ERROR" , str ( exc . exception ) )
125+ self .assert_exception_message ( exc , "SYNTAX_ERROR" )
118126
119127 def test_query_with_array_param (self ):
120128 df = chdb .query (
@@ -135,12 +143,12 @@ def test_query_with_tuple_param_string_encoded(self):
135143 def test_query_with_params_missing_value (self ):
136144 with self .assertRaises (RuntimeError ) as exc :
137145 chdb .query ("SELECT {x:UInt64} AS v" )
138- self .assertIn ( "Substitution `x` is not set" , str ( exc . exception ) )
146+ self .assert_exception_message ( exc , "Substitution `x` is not set" )
139147
140148 def test_query_with_params_invalid_type (self ):
141149 with self .assertRaises (RuntimeError ) as exc :
142150 chdb .query ("SELECT {x:UInt64} AS v" , params = {"x" : "not-a-number" })
143- self .assertIn ( "cannot be parsed as UInt64" , str ( exc . exception ) )
151+ self .assert_exception_message ( exc , "cannot be parsed as UInt64" )
144152
145153 def test_session_send_query_with_params_missing_value_stream (self ):
146154 sess = session .Session (":memory:" )
@@ -149,7 +157,7 @@ def test_session_send_query_with_params_missing_value_stream(self):
149157 with stream :
150158 with self .assertRaises (RuntimeError ) as exc :
151159 stream .fetch ()
152- self .assertIn ( "Substitution `n` is not set" , str ( exc . exception ) )
160+ self .assert_exception_message ( exc , "Substitution `n` is not set" )
153161 finally :
154162 sess .close ()
155163
@@ -160,7 +168,7 @@ def test_session_send_query_with_params_invalid_type_stream(self):
160168 with stream :
161169 with self .assertRaises (RuntimeError ) as exc :
162170 stream .fetch ()
163- self .assertIn ( "cannot be parsed as UInt64" , str ( exc . exception ) )
171+ self .assert_exception_message ( exc , "cannot be parsed as UInt64" )
164172 finally :
165173 sess .close ()
166174
0 commit comments