Skip to content

Commit aaf04b5

Browse files
committed
updated ci to add async server tests
1 parent ad786a6 commit aaf04b5

File tree

5 files changed

+143
-18
lines changed

5 files changed

+143
-18
lines changed
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: 'Run Async Server Tests'
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
7+
jobs:
8+
run-tests:
9+
strategy:
10+
matrix:
11+
os:
12+
- ubuntu-latest
13+
- windows-latest
14+
- macos-latest
15+
python-version:
16+
- "3.7"
17+
- "3.8"
18+
- "3.9"
19+
- "3.10"
20+
- "3.11"
21+
- "3.12"
22+
exclude:
23+
- os: windows-latest
24+
python-version: "3.12"
25+
runs-on: ${{matrix.os}}
26+
name: 'Run Tests on ${{matrix.os}} with Python ${{matrix.python-version}}'
27+
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
36+
- name: Install dependencies from requirements.txt
37+
shell: bash
38+
run: |
39+
python3 -m pip install --upgrade pip
40+
pip install -r requirements.txt
41+
42+
- name: Install psycopg2 for non-Windows OS
43+
if: matrix.os != 'windows-latest'
44+
run: |
45+
pip install psycopg2
46+
47+
# Windows specific
48+
# whl files downloaded from https://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg
49+
- name: Install psycopg2-binary for Windows using local wheel
50+
if: matrix.os == 'windows-latest'
51+
run: |
52+
# Determine the wheel filename based on the Python version
53+
$wheelFilename = switch ("${{ matrix.python-version }}") {
54+
"3.7" { "psycopg2-2.9.3-cp37-cp37m-win_amd64.whl" }
55+
"3.8" { "psycopg2-2.9.3-cp38-cp38-win_amd64.whl" }
56+
"3.9" { "psycopg2-2.9.3-cp39-cp39-win_amd64.whl" }
57+
"3.10" { "psycopg2-2.9.3-cp310-cp310-win_amd64.whl" }
58+
"3.11" { "psycopg2-2.9.3-cp311-cp311-win_amd64.whl" }
59+
}
60+
61+
# Print the wheel filename for debugging
62+
Write-Host "Determined wheel filename: $wheelFilename"
63+
64+
# Install the wheel
65+
pip install ./tests/whls/$wheelFilename
66+
shell: powershell
67+
# End Windows specific
68+
69+
- name: Install pystackql
70+
run: |
71+
pip install .
72+
73+
- name: Run tests
74+
env:
75+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
76+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
77+
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
78+
AWS_REGIONS: ${{ vars.AWS_REGIONS }}
79+
GCP_PROJECT: ${{ vars.GCP_PROJECT }}
80+
GCP_ZONE: ${{ vars.GCP_ZONE }}
81+
run: |
82+
python3 -m tests.pystackql_async_server_tests

.github/workflows/test.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ jobs:
2222
exclude:
2323
- os: windows-latest
2424
python-version: "3.12"
25-
# - os: macos-latest
26-
# python-version: "3.12"
2725
runs-on: ${{matrix.os}}
2826
name: 'Run Tests on ${{matrix.os}} with Python ${{matrix.python-version}}'
2927

run_async_server_tests

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
. tests/creds/env_vars/test.env
3+
python3 -m tests.pystackql_async_server_tests

tests/pystackql_async_server_tests.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sys, os, unittest, asyncio
2+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
3+
from pystackql import StackQL
4+
from .test_params import *
5+
6+
def async_test_decorator(func):
7+
def wrapper(*args, **kwargs):
8+
if asyncio.iscoroutinefunction(func):
9+
return asyncio.run(func(*args, **kwargs))
10+
else:
11+
return func(*args, **kwargs)
12+
return wrapper
13+
14+
class PyStackQLTestsBase(unittest.TestCase):
15+
pass
16+
17+
def setUpModule():
18+
print("downloading stackql binary...")
19+
PyStackQLTestsBase.stackql = StackQL()
20+
print("downloading aws provider for tests...")
21+
res = PyStackQLTestsBase.stackql.executeStmt(registry_pull_aws_query)
22+
print(res)
23+
print("downloading google provider for tests...")
24+
res = PyStackQLTestsBase.stackql.executeStmt(registry_pull_google_query)
25+
print(res)
26+
print("starting stackql server...")
27+
PyStackQLTestsBase.server_process = subprocess.Popen([PyStackQLTestsBase.stackql.bin_path, "srv", "--pgsrv.address", server_address, "--pgsrv.port", str(server_port)])
28+
time.sleep(5)
29+
30+
def tearDownModule():
31+
print("stopping stackql server...")
32+
if PyStackQLTestsBase.server_process:
33+
PyStackQLTestsBase.server_process.terminate()
34+
PyStackQLTestsBase.server_process.wait()
35+
36+
class PyStackQLAsyncTests(PyStackQLTestsBase):
37+
38+
@async_test_decorator
39+
async def test_executeQueriesAsync_server_mode_default_output(self):
40+
stackql = StackQL(server_mode=True)
41+
result = await stackql.executeQueriesAsync(async_queries)
42+
is_valid_result = isinstance(result, list) and all(isinstance(res, dict) for res in result)
43+
self.assertTrue(is_valid_result, f"Result is not a valid list of dicts: {result}")
44+
print_test_result(f"[ASYNC] Test executeQueriesAsync in server_mode with default output\nRESULT_COUNT: {len(result)}", is_valid_result, True)
45+
46+
@async_test_decorator
47+
async def test_executeQueriesAsync_server_mode_pandas_output(self):
48+
stackql = StackQL(server_mode=True, output='pandas')
49+
result = await stackql.executeQueriesAsync(async_queries)
50+
is_valid_dataframe = isinstance(result, pd.DataFrame) and not result.empty
51+
self.assertTrue(is_valid_dataframe, f"Result is not a valid DataFrame: {result}")
52+
print_test_result(f"[ASYNC] Test executeQueriesAsync in server_mode with pandas output\nRESULT_COUNT: {len(result)}", is_valid_dataframe, True)
53+
54+
def main():
55+
unittest.main(verbosity=0)
56+
57+
if __name__ == '__main__':
58+
main()

tests/pystackql_tests.py

-16
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,6 @@ async def test_16_executeQueriesAsync_with_csv_output(self):
206206
pass
207207
print_test_result(f"[ASYNC] Test executeQueriesAsync with unsupported csv output", exception_caught)
208208

209-
# @async_test_decorator
210-
# async def test_17_executeQueriesAsync_server_mode_default_output(self):
211-
# stackql = StackQL(server_mode=True)
212-
# result = await stackql.executeQueriesAsync(async_queries)
213-
# is_valid_result = isinstance(result, list) and all(isinstance(res, dict) for res in result)
214-
# self.assertTrue(is_valid_result, f"Result is not a valid list of dicts: {result}")
215-
# print_test_result(f"[ASYNC] Test executeQueriesAsync in server_mode with default output\nRESULT_COUNT: {len(result)}", is_valid_result, True)
216-
217-
# @async_test_decorator
218-
# async def test_18_executeQueriesAsync_server_mode_pandas_output(self):
219-
# stackql = StackQL(server_mode=True, output='pandas')
220-
# result = await stackql.executeQueriesAsync(async_queries)
221-
# is_valid_dataframe = isinstance(result, pd.DataFrame) and not result.empty
222-
# self.assertTrue(is_valid_dataframe, f"Result is not a valid DataFrame: {result}")
223-
# print_test_result(f"[ASYNC] Test executeQueriesAsync in server_mode with pandas output\nRESULT_COUNT: {len(result)}", is_valid_dataframe, True)
224-
225209
class PyStackQLServerModeNonAsyncTests(PyStackQLTestsBase):
226210

227211
@pystackql_test_setup(server_mode=True)

0 commit comments

Comments
 (0)