Skip to content

Commit 3c6e4d5

Browse files
committed
Update tests for musl linux build.
1 parent eae7b42 commit 3c6e4d5

File tree

5 files changed

+35
-57
lines changed

5 files changed

+35
-57
lines changed

tests/musl.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import platform
2+
import subprocess
3+
4+
5+
def is_musl_linux():
6+
"""Return True when running on a musl-based Linux distribution."""
7+
if platform.system() != "Linux":
8+
return False
9+
try:
10+
result = subprocess.run(
11+
["ldd", "--version"], capture_output=True, text=True
12+
)
13+
print(f"stdout: {result.stdout.lower()}")
14+
print(f"stderr: {result.stderr.lower()}")
15+
output_text = (result.stdout + result.stderr).lower()
16+
return "musl" in output_text
17+
except Exception as e:
18+
print(f"Exception in is_musl_linux: {e}")
19+
return False

tests/test_delta_lake.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,9 @@
22

33
import unittest
44
import sys
5-
import platform
6-
import subprocess
75
import chdb
86
from chdb import session
9-
10-
def is_musl_linux():
11-
"""Check if running on musl Linux"""
12-
if platform.system() != "Linux":
13-
return False
14-
try:
15-
result = subprocess.run(['ldd', '--version'], capture_output=True, text=True)
16-
print(f"stdout: {result.stdout.lower()}")
17-
print(f"stderr: {result.stderr.lower()}")
18-
# Check both stdout and stderr for musl
19-
output_text = (result.stdout + result.stderr).lower()
20-
return 'musl' in output_text
21-
except Exception as e:
22-
print(f"Exception in is_musl_linux: {e}")
23-
return False
7+
from tests.musl import is_musl_linux
248

259
@unittest.skipUnless(sys.platform.startswith("linux") and not is_musl_linux(), "Runs only on Linux platforms")
2610
class TestDeltaLake(unittest.TestCase):

tests/test_query_params.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
import chdb
66
from chdb import session
77
from chdb.state import connect
8+
from tests.musl import is_musl_linux
89

910

1011
class 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

tests/test_session_concurrency.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,13 @@
44
import shutil
55
import os
66
import threading
7-
import platform
8-
import subprocess
97
from chdb import session
8+
from tests.musl import is_musl_linux
109

1110

1211
test_concurrent_dir = ".tmp_test_session_concurrency"
1312

1413

15-
def is_musl_linux():
16-
if platform.system() != "Linux":
17-
return False
18-
try:
19-
result = subprocess.run(['ldd', '--version'], capture_output=True, text=True)
20-
print(f"stdout: {result.stdout.lower()}")
21-
print(f"stderr: {result.stderr.lower()}")
22-
# Check both stdout and stderr for musl
23-
output_text = (result.stdout + result.stderr).lower()
24-
return 'musl' in output_text
25-
except Exception as e:
26-
print(f"Exception in is_musl_linux: {e}")
27-
return False
28-
29-
3014
class TestSessionConcurrency(unittest.TestCase):
3115
def setUp(self) -> None:
3216
shutil.rmtree(test_concurrent_dir, ignore_errors=True)

tests/test_unsupported_arrow_types.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
#!/usr/bin/env python3
22

33
import unittest
4-
import platform
5-
import subprocess
64
import pyarrow as pa
75
import pyarrow.compute as pc
86
import chdb
97
from chdb import ChdbError
10-
11-
12-
def is_musl_linux():
13-
"""Check if running on musl Linux"""
14-
if platform.system() != "Linux":
15-
return False
16-
try:
17-
result = subprocess.run(['ldd', '--version'], capture_output=True, text=True)
18-
print(f"stdout: {result.stdout.lower()}")
19-
print(f"stderr: {result.stderr.lower()}")
20-
# Check both stdout and stderr for musl
21-
output_text = (result.stdout + result.stderr).lower()
22-
return 'musl' in output_text
23-
except Exception as e:
24-
print(f"Exception in is_musl_linux: {e}")
25-
return False
8+
from tests.musl import is_musl_linux
269

2710

2811
class TestUnsupportedArrowTypes(unittest.TestCase):

0 commit comments

Comments
 (0)