Skip to content

Commit 8144f63

Browse files
committed
chore: eliminate redundant code
1 parent d4e0be7 commit 8144f63

File tree

5 files changed

+26
-66
lines changed

5 files changed

+26
-66
lines changed

tests/test_delta_lake.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,8 @@
66
import subprocess
77
import chdb
88
from chdb import session
9+
from utils import is_musl_linux
910

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
2411

2512
@unittest.skipUnless(sys.platform.startswith("linux") and not is_musl_linux(), "Runs only on Linux platforms")
2613
class TestDeltaLake(unittest.TestCase):
@@ -44,5 +31,6 @@ def test_delta_lake(self):
4431
''')
4532
self.assertEqual(ret.rows_read(), 0)
4633

34+
4735
if __name__ == "__main__":
4836
unittest.main()

tests/test_issue60.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import time
33
import unittest
44
import chdb
5-
import platform
6-
import subprocess
5+
from utils import is_musl_linux
6+
77

88
data = """url('https://datasets-documentation.s3.eu-west-3.amazonaws.com/house_parquet/house_0.parquet')"""
99

@@ -33,21 +33,6 @@
3333
"COVENTRY","COVENTRY",13927,149269
3434
'''
3535

36-
def is_musl_linux():
37-
"""Check if running on musl Linux"""
38-
if platform.system() != "Linux":
39-
return False
40-
try:
41-
result = subprocess.run(['ldd', '--version'], capture_output=True, text=True)
42-
print(f"stdout: {result.stdout.lower()}")
43-
print(f"stderr: {result.stderr.lower()}")
44-
# Check both stdout and stderr for musl
45-
output_text = (result.stdout + result.stderr).lower()
46-
return 'musl' in output_text
47-
except Exception as e:
48-
print(f"Exception in is_musl_linux: {e}")
49-
return False
50-
5136
result = ""
5237

5338
class myThread(threading.Thread):
@@ -77,5 +62,6 @@ def test_query_in_thread(self):
7762
thread1.join()
7863
self.assertEqual(str(result), expected_result)
7964

65+
8066
if __name__ == '__main__':
8167
unittest.main()

tests/test_session_concurrency.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,12 @@
77
import platform
88
import subprocess
99
from chdb import session
10+
from utils import is_musl_linux
1011

1112

1213
test_concurrent_dir = ".tmp_test_session_concurrency"
1314

1415

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-
3016
class TestSessionConcurrency(unittest.TestCase):
3117
def setUp(self) -> None:
3218
shutil.rmtree(test_concurrent_dir, ignore_errors=True)

tests/test_unsupported_arrow_types.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,7 @@
77
import pyarrow.compute as pc
88
import chdb
99
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
10+
from utils import is_musl_linux
2611

2712

2813
class TestUnsupportedArrowTypes(unittest.TestCase):

tests/utils.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import re
22
import os
3+
import platform
4+
import subprocess
35

46
current_dir = os.path.dirname(os.path.abspath(__file__))
5-
data_file = os.path.join(
6-
current_dir, "../tests/data/alltypes_dictionary.parquet")
7+
data_file = os.path.join(current_dir, "../tests/data/alltypes_dictionary.parquet")
78

89
# reset elapsed time to 0.0 from output, since it will be different each time
910
# eg: "elapsed": 0.001015,
10-
11-
1211
def reset_elapsed(input):
1312
try:
1413
if not isinstance(input, str):
@@ -20,3 +19,19 @@ def reset_elapsed(input):
2019
except UnicodeDecodeError:
2120
pass
2221
return input
22+
23+
24+
def is_musl_linux():
25+
"""Check if running on musl Linux"""
26+
if platform.system() != "Linux":
27+
return False
28+
try:
29+
result = subprocess.run(['ldd', '--version'], capture_output=True, text=True)
30+
print(f"stdout: {result.stdout.lower()}")
31+
print(f"stderr: {result.stderr.lower()}")
32+
# Check both stdout and stderr for musl
33+
output_text = (result.stdout + result.stderr).lower()
34+
return 'musl' in output_text
35+
except Exception as e:
36+
print(f"Exception in is_musl_linux: {e}")
37+
return False

0 commit comments

Comments
 (0)