Comprehensive test suite for the coral-python workflow execution system.
tests/
├── __init__.py # Test package initialization
├── conftest.py # Pytest fixtures and configuration
├── test_executor.py # Core WorkflowExecutor tests
├── test_registry.py # Registry generation tests
├── test_modules.py # Module loading tests
├── test_integration.py # End-to-end workflow tests
└── fixtures/
├── valid_workflows/ # Valid workflow test files (lean: nodes keyed by id, identified by type)
└── valid_nodes/ # Registry fixtures (node-type definitions)
pytestpytest tests/test_executor.py
pytest tests/test_integration.py# Run only integration tests
pytest -m integration
# Run only unit tests
pytest -m unit
# Run only math module tests
pytest -m math
# Run only phiflow tests (requires PhiFlow installed)
pytest -m phiflow
# Skip slow tests
pytest -m "not slow"pytest tests/test_executor.py::TestPrimitiveNodeExecution
pytest tests/test_executor.py::TestPrimitiveNodeExecution::test_int_primitivepytest -v
pytest -vv # Extra verbosepytest -s# Run with coverage report
pytest --cov=. --cov-report=html
# View coverage report
open htmlcov/index.htmlpip install pytest-xdist
pytest -n auto- Test individual components in isolation
- Fast execution
- No external dependencies (except PhiFlow for some module tests)
- Test complete workflows using real JSON files
- Tests the entire execution pipeline
- Uses actual workflow files from project root:
- PhiFlow workflows:
network-from-fe-obstacle.json,network-from-fe-smoke_plume.json - Math workflows:
network-from-fe-math.json,network-from-fe-classes.json,network-from-fe-functions.json
- PhiFlow workflows:
project_root: Path to project root directoryworkflow_files: Dictionary mapping workflow names to file pathsregistry_files: Dictionary mapping registry names to file pathsload_workflow: Factory to load workflow JSON by nameload_registry: Factory to load registry JSON by namesimple_workflow_dict: Simple valid workflow for testingcircular_workflow_dict: Workflow with circular dependencytemp_workflow_file: Factory to create temporary workflow filesmock_print: Mock print function to capture output
def test_example(workflow_files, load_workflow):
# Get path to workflow file
math_workflow_path = workflow_files["math"]
# Load workflow data
workflow_data = load_workflow("math")
# Execute workflow
executor = WorkflowExecutor(str(math_workflow_path), modules=['math'])
results = executor.execute()- Test files:
test_*.py - Test classes:
Test* - Test functions:
test_*
import pytest
from executor import WorkflowExecutor
class TestMyFeature:
"""Test description."""
@pytest.mark.unit
def test_my_specific_case(self, temp_workflow_file):
"""Test specific behavior."""
workflow = {
"workflow": {
"nodes": [...],
"edges": [...]
}
}
file_path = temp_workflow_file(workflow)
executor = WorkflowExecutor(str(file_path), modules=['math'])
results = executor.execute()
assert "expected_node" in results
assert results["expected_node"] == expected_value@pytest.mark.integration # Integration test
@pytest.mark.unit # Unit test
@pytest.mark.phiflow # Requires PhiFlow
@pytest.mark.math # Uses math module
@pytest.mark.string # Uses string module
@pytest.mark.slow # Slow-running testThe test suite covers:
- Primitive Node Execution: int, float, str, bool types
- Function Node Execution: Math operations, chaining
- Constructor Node Execution: Class instantiation
- Method Node Execution: Instance method calls
- Topological Sorting: DAG ordering, cycle detection
- Edge Ordering: Parameter order via
target_input - Module Loading: Dynamic function/class map building
- Registry Generation: Schema creation, type conversion
- Integration: Real workflow execution
- Error Handling: Missing nodes, invalid functions, cycles
To set up CI/CD with GitHub Actions, create .github/workflows/tests.yml:
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install uv
uv pip sync requirements.txt
- name: Run tests
run: pytest --cov=. --cov-report=xml
- name: Upload coverage
uses: codecov/codecov-action@v2If PhiFlow tests are skipped, install PhiFlow:
uv pip install phiflowEnsure you're running tests from the project root:
cd /path/to/coral-python
pytestCheck that test files follow naming conventions:
- Files:
test_*.py - Functions:
test_*() - Classes:
Test*
When adding new features to coral-python:
- Add unit tests in appropriate
test_*.pyfile - Add integration test with a real workflow JSON
- Update fixtures if needed
- Mark tests appropriately (
@pytest.mark.unit, etc.) - Ensure tests are independent and can run in any order
- Use descriptive test names that explain what's being tested
For performance-critical tests:
@pytest.mark.slow
def test_performance(workflow_files):
import time
start = time.time()
executor = WorkflowExecutor(str(workflow_files["math"]), modules=['math'])
results = executor.execute()
elapsed = time.time() - start
assert elapsed < 1.0, f"Execution too slow: {elapsed:.2f}s"