@@ -31,6 +31,14 @@ class PyStackQLTestsBase(unittest.TestCase):
3131def setUpModule ():
3232 print ("downloading stackql binary..." )
3333 PyStackQLTestsBase .stackql = StackQL ()
34+ # Check whether code is running in GitHub Actions
35+ is_github_actions = os .environ .get ('GITHUB_ACTIONS' ) == 'true'
36+
37+ if not is_github_actions :
38+ # Ensure you have the latest version of stackql, only when running locally
39+ print ("Running tests outside of GitHub Actions, upgrading stackql binary..." )
40+ PyStackQLTestsBase .stackql .upgrade ()
41+
3442 print ("downloading aws provider for tests..." )
3543 res = PyStackQLTestsBase .stackql .executeStmt (registry_pull_aws_query )
3644 print (res )
@@ -39,7 +47,7 @@ def setUpModule():
3947 print (res )
4048 print ("starting stackql server..." )
4149 PyStackQLTestsBase .server_process = subprocess .Popen ([PyStackQLTestsBase .stackql .bin_path , "srv" , "--pgsrv.address" , server_address , "--pgsrv.port" , str (server_port )])
42- time .sleep (5 )
50+ time .sleep (10 )
4351
4452def tearDownModule ():
4553 print ("stopping stackql server..." )
@@ -161,18 +169,26 @@ def test_11_execute_with_defaults(self):
161169 result = self .stackql .execute (google_query )
162170 is_valid_dict = isinstance (result , list ) and all (isinstance (item , dict ) for item in result )
163171 self .assertTrue (is_valid_dict , f"Result is not a valid dict: { result } " )
164- print_test_result (f"Test execute with defaults\n RESULT_COUNT : { len ( result ) } " , is_valid_dict )
172+ print_test_result (f"Test execute with defaults\n RESULT : { result } " , is_valid_dict )
165173
166174 @pystackql_test_setup (output = 'pandas' )
167175 def test_12_execute_with_pandas_output (self ):
168- result = self .stackql .execute (google_query )
176+ result = self .stackql .execute (aws_query )
169177 is_valid_dataframe = isinstance (result , pd .DataFrame )
170178 self .assertTrue (is_valid_dataframe , f"Result is not a valid DataFrame: { result } " )
171- print_test_result (f"Test execute with pandas output\n RESULT_COUNT: { len (result )} " , is_valid_dataframe )
179+ # Check datatypes of the columns
180+ expected_dtypes = {
181+ 'instance_state' : 'object' , # This should be 'object' for older Pandas versions
182+ 'num_instances' : 'int64'
183+ }
184+ for col , expected_dtype in expected_dtypes .items ():
185+ actual_dtype = result [col ].dtype
186+ self .assertEqual (actual_dtype , expected_dtype , f"Column '{ col } ' has dtype '{ actual_dtype } ' but expected '{ expected_dtype } '" )
187+ print_test_result (f"Test execute with pandas output\n RESULT COUNT: { len (result )} " , is_valid_dataframe )
172188
173189 @pystackql_test_setup (output = 'csv' )
174190 def test_13_execute_with_csv_output (self ):
175- result = self .stackql .execute (google_query )
191+ result = self .stackql .execute (aws_query )
176192 is_valid_csv = isinstance (result , str ) and result .count ("\n " ) >= 1 and result .count ("," ) >= 1
177193 self .assertTrue (is_valid_csv , f"Result is not a valid CSV: { result } " )
178194 print_test_result (f"Test execute with csv output\n RESULT_COUNT: { len (result .splitlines ())} " , is_valid_csv )
@@ -233,9 +249,18 @@ def test_21_execute_server_mode_default_output(self):
233249
234250 @pystackql_test_setup (server_mode = True , output = 'pandas' )
235251 def test_22_execute_server_mode_pandas_output (self ):
236- result = self .stackql .execute (google_query )
237- is_valid_pandas_output = isinstance (result , pd .DataFrame )
238- print_test_result (f"""Test execute in server_mode with pandas output\n RESULT_COUNT: { len (result )} """ , is_valid_pandas_output , True )
252+ result = self .stackql .execute (aws_query )
253+ is_valid_dataframe = isinstance (result , pd .DataFrame )
254+ self .assertTrue (is_valid_dataframe , f"Result is not a valid DataFrame: { result } " )
255+ # Check datatypes of the columns
256+ expected_dtypes = {
257+ 'instance_state' : 'object' , # This should be 'object' for older Pandas versions
258+ 'num_instances' : 'int64'
259+ }
260+ for col , expected_dtype in expected_dtypes .items ():
261+ actual_dtype = result [col ].dtype
262+ self .assertEqual (actual_dtype , expected_dtype , f"Column '{ col } ' has dtype '{ actual_dtype } ' but expected '{ expected_dtype } '" )
263+ print_test_result (f"Test execute in server_mode with pandas output\n RESULT COUNT: { len (result )} " , is_valid_dataframe )
239264
240265class MockInteractiveShell :
241266 """A mock class for IPython's InteractiveShell."""
0 commit comments