This guide explains the PyStackQL testing framework. The tests have been designed to:
- Focus on provider-agnostic queries where possible
- Use the Homebrew provider for provider-specific tests (no authentication required)
- Be organized into logical modules based on functionality
- Support both local execution and GitHub Codespaces
The tests are organized into these main files:
test_constants.py: Common constants and helper functionsconftest.py: Test fixtures and setuptest_core.py: Core functionality teststest_query_execution.py: Query execution teststest_output_formats.py: Output format teststest_magic.py: Magic extension teststest_async.py: Async functionality teststest_server.py: Server mode tests
To run all tests:
python run_tests.pyTo run specific test files:
python run_tests.py tests/test_core.py tests/test_query_execution.pypython run_tests.py -vServer tests are skipped by default because they require a running StackQL server. To run these tests:
-
Start a StackQL server:
stackql srv --pgsrv.address 127.0.0.1 --pgsrv.port 5466
-
Run the server tests:
python run_tests.py tests/test_server.py -v
Tests the basic properties and attributes of the StackQL class:
properties()methodversion,package_version,platformattributes- Binary path and download directory
- Upgrade functionality
Tests the query execution functionality with provider-agnostic queries:
- Literal values (integers, strings, floats)
- Expressions
- JSON extraction
- Homebrew provider queries
- Registry pull operations
Tests the different output formats:
- Dict output
- Pandas output with type checking
- CSV output with different separators and headers
- Error handling for invalid configurations
Tests the Jupyter magic extensions:
- Line and cell magic in non-server mode
- Line and cell magic in server mode
- Result storage in user namespace
- Display options
Tests the async query execution functionality:
executeQueriesAsyncwith different output formats- Concurrent queries with the Homebrew provider
- Error handling
Tests the server mode functionality (requires a running server):
- Server connectivity
- Query execution in server mode
- Statement execution in server mode
- Different output formats in server mode
The tests use:
-
Simple literals and expressions:
SELECT 1 as literal_int_value SELECT 1.001 as literal_float_value SELECT 'test' as literal_string_value SELECT 1=1 as expression
-
Homebrew provider queries:
SELECT name, full_name, tap FROM homebrew.formula.formula WHERE formula_name = 'stackql' SELECT * FROM homebrew.formula.vw_usage_metrics WHERE formula_name = 'stackql'
-
Registry operations:
REGISTRY PULL homebrew
When running in GitHub Codespaces:
- The tests automatically detect if they're running in GitHub Actions and skip the binary upgrade
- The server tests are skipped by default (can be enabled if needed)
- Async tests might be skipped on Windows due to asyncio issues
When adding new tests:
- Use provider-agnostic queries where possible
- For provider-specific tests, prefer the Homebrew provider
- Add new tests to the appropriate test file based on functionality
- Update
run_tests.pyif adding a new test file - Follow the existing patterns for consistency