7
7
"""
8
8
9
9
import re
10
+ import os
10
11
import pytest
11
12
import pandas as pd
12
13
from unittest .mock import patch
20
21
pystackql_test_setup
21
22
)
22
23
23
- @pytest .mark .usefixtures ("stackql_server" )
24
+ # @pytest.mark.usefixtures("stackql_server")
24
25
class TestServerMode :
25
26
"""Tests for PyStackQL server mode functionality."""
26
27
27
28
StackQL = StackQL # For use with pystackql_test_setup decorator
28
-
29
+ server_available = False # Class-level flag to track server availability
30
+
31
+ # @pystackql_test_setup(server_mode=True)
32
+ # def test_server_mode_connectivity(self):
33
+ # """Test that server mode connects successfully."""
34
+ # # Check server_mode flag is set correctly
35
+ # assert self.stackql.server_mode, "StackQL should be in server mode"
36
+
37
+ # # Check server connection object exists
38
+ # assert hasattr(self.stackql, 'server_connection'), "StackQL should have a server_connection attribute"
39
+ # assert self.stackql.server_connection is not None, "Server connection object should not be None"
40
+
41
+ # # IMPORTANT: Actually test the connection works
42
+ # connection_working = self.stackql.test_connection()
43
+
44
+ # # Print detailed results for debugging
45
+ # if not connection_working:
46
+ # print("⚠️ Server connection test failed: unable to execute a simple query")
47
+ # print(f"Server address: {self.stackql.server_address}")
48
+ # print(f"Server port: {self.stackql.server_port}")
49
+ # print("\n❌ SERVER CONNECTION FAILED - SKIPPING REMAINING SERVER TESTS")
50
+ # else:
51
+ # # Set flag indicating server is available
52
+ # TestServerMode.server_available = True
53
+
54
+ # print_test_result("Server mode connectivity test",
55
+ # self.stackql.server_mode and
56
+ # hasattr(self.stackql, 'server_connection') and
57
+ # self.stackql.server_connection is not None and
58
+ # connection_working, # Include connection check in the pass criteria
59
+ # True)
60
+
61
+ # # Add additional output about the actual connection status
62
+ # print(f" - Connection status: {'✅ WORKING' if connection_working else '❌ NOT WORKING'}")
63
+ # print(f" - Expected status: ✅ WORKING") # Always expected to be working
64
+
65
+ # # Always assert that the connection is working
66
+ # assert connection_working, "Server connection should be working"
67
+
29
68
@pystackql_test_setup (server_mode = True )
30
69
def test_server_mode_connectivity (self ):
31
70
"""Test that server mode connects successfully."""
32
- assert self .stackql .server_mode , "StackQL should be in server mode"
33
- # Updated assertion to check server_connection attribute instead of _conn
34
- assert hasattr (self .stackql , 'server_connection' ), "StackQL should have a server_connection attribute"
35
- assert self .stackql .server_connection is not None , "Server connection object should not be None"
36
-
37
- print_test_result ("Server mode connectivity test" ,
38
- self .stackql .server_mode and
39
- hasattr (self .stackql , 'server_connection' ) and
40
- self .stackql .server_connection is not None ,
41
- True )
42
-
71
+ # Initialize class variable
72
+ TestServerMode .server_available = False
73
+
74
+ # Perform basic server connection test
75
+ connection_working = self .stackql .test_connection ()
76
+
77
+ if not connection_working :
78
+ # Log minimal diagnostic info
79
+ print ("\n ⚠️ Server connection failed" )
80
+ print (f"Address: { self .stackql .server_address } :{ self .stackql .server_port } " )
81
+ print ("❌ Skipping remaining server tests" )
82
+
83
+ # Fail with a concise message - this will be what shows in the error summary
84
+ pytest .fail ("Server connection failed - please start stackql server" )
85
+
86
+ # Connection succeeded
87
+ TestServerMode .server_available = True
88
+ print ("✅ Server connection successful" )
89
+
43
90
@pystackql_test_setup (server_mode = True )
44
91
def test_server_mode_execute_stmt (self ):
45
92
"""Test executeStmt in server mode."""
93
+
94
+ # Skip if server is not available
95
+ if not TestServerMode .server_available :
96
+ pytest .skip ("Server is not available, skipping test" )
97
+
46
98
result = self .stackql .executeStmt (REGISTRY_PULL_HOMEBREW_QUERY )
47
99
48
100
# Check result structure
@@ -60,6 +112,11 @@ def test_server_mode_execute_stmt(self):
60
112
@pystackql_test_setup (server_mode = True , output = 'pandas' )
61
113
def test_server_mode_execute_stmt_pandas (self ):
62
114
"""Test executeStmt in server mode with pandas output."""
115
+
116
+ # Skip if server is not available
117
+ if not TestServerMode .server_available :
118
+ pytest .skip ("Server is not available, skipping test" )
119
+
63
120
result = self .stackql .executeStmt (REGISTRY_PULL_HOMEBREW_QUERY )
64
121
65
122
# Check result structure
@@ -77,6 +134,11 @@ def test_server_mode_execute_stmt_pandas(self):
77
134
@pystackql_test_setup (server_mode = True )
78
135
def test_server_mode_execute (self ):
79
136
"""Test execute in server mode."""
137
+
138
+ # Skip if server is not available
139
+ if not TestServerMode .server_available :
140
+ pytest .skip ("Server is not available, skipping test" )
141
+
80
142
result = self .stackql .execute (LITERAL_INT_QUERY )
81
143
82
144
# Check result structure
@@ -98,6 +160,11 @@ def test_server_mode_execute(self):
98
160
@pystackql_test_setup (server_mode = True , output = 'pandas' )
99
161
def test_server_mode_execute_pandas (self ):
100
162
"""Test execute in server mode with pandas output."""
163
+
164
+ # Skip if server is not available
165
+ if not TestServerMode .server_available :
166
+ pytest .skip ("Server is not available, skipping test" )
167
+
101
168
result = self .stackql .execute (LITERAL_STRING_QUERY )
102
169
103
170
# Check result structure
@@ -115,6 +182,11 @@ def test_server_mode_execute_pandas(self):
115
182
@pystackql_test_setup (server_mode = True )
116
183
def test_server_mode_provider_query (self ):
117
184
"""Test querying a provider in server mode."""
185
+
186
+ # Skip if server is not available
187
+ if not TestServerMode .server_available :
188
+ pytest .skip ("Server is not available, skipping test" )
189
+
118
190
result = self .stackql .execute (HOMEBREW_FORMULA_QUERY )
119
191
120
192
# Check result structure
@@ -135,6 +207,11 @@ def test_server_mode_provider_query(self):
135
207
@patch ('pystackql.core.server.ServerConnection.execute_query' )
136
208
def test_server_mode_execute_mocked (self , mock_execute_query ):
137
209
"""Test execute in server mode with mocked server response."""
210
+
211
+ # Skip if server is not available
212
+ if not TestServerMode .server_available :
213
+ pytest .skip ("Server is not available, skipping test" )
214
+
138
215
# Create a StackQL instance in server mode
139
216
stackql = StackQL (server_mode = True )
140
217
@@ -158,6 +235,11 @@ def test_server_mode_execute_mocked(self, mock_execute_query):
158
235
@patch ('pystackql.core.server.ServerConnection.execute_query' )
159
236
def test_server_mode_execute_pandas_mocked (self , mock_execute_query ):
160
237
"""Test execute in server mode with pandas output and mocked server response."""
238
+
239
+ # Skip if server is not available
240
+ if not TestServerMode .server_available :
241
+ pytest .skip ("Server is not available, skipping test" )
242
+
161
243
# Create a StackQL instance in server mode with pandas output
162
244
stackql = StackQL (server_mode = True , output = 'pandas' )
163
245
@@ -186,6 +268,11 @@ def test_server_mode_execute_pandas_mocked(self, mock_execute_query):
186
268
@patch ('pystackql.core.server.ServerConnection.execute_query' )
187
269
def test_server_mode_execute_stmt_mocked (self , mock_execute_query ):
188
270
"""Test executeStmt in server mode with mocked server response."""
271
+
272
+ # Skip if server is not available
273
+ if not TestServerMode .server_available :
274
+ pytest .skip ("Server is not available, skipping test" )
275
+
189
276
# Create a StackQL instance in server mode
190
277
stackql = StackQL (server_mode = True )
191
278
@@ -208,6 +295,11 @@ def test_server_mode_execute_stmt_mocked(self, mock_execute_query):
208
295
209
296
def test_server_mode_csv_output_error (self ):
210
297
"""Test that server mode with csv output raises an error."""
298
+
299
+ # Skip if server is not available
300
+ if not TestServerMode .server_available :
301
+ pytest .skip ("Server is not available, skipping test" )
302
+
211
303
with pytest .raises (ValueError ) as exc_info :
212
304
StackQL (server_mode = True , output = 'csv' )
213
305
0 commit comments