Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Install uv
uses: astral-sh/setup-uv@v4
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3
with:
python-version: "3.11"
enable-cache: true
Expand All @@ -30,7 +30,7 @@ jobs:

- name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Install uv
uses: astral-sh/setup-uv@v5
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3
with:
python-version: "3.11"
enable-cache: true
Expand All @@ -21,7 +21,7 @@ jobs:
run: uv sync --all-extras

- name: Run Ruff
uses: astral-sh/ruff-action@v3
uses: astral-sh/ruff-action@0c50076f12c38c3d0115b7b519b54a91cb9cf0ad # v3.5.0
with:
args: check .

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
- uses: google-github-actions/release-please-action@e4dc86ba9405554aeba3c6bb2d169500e7d3b4ee # v4.1.1
id: release
with:
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json

# Only release to PyPI when a new release is created
- uses: actions/checkout@v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
if: ${{ steps.release.outputs.release_created }}

- name: Install uv
if: ${{ steps.release.outputs.release_created }}
uses: astral-sh/setup-uv@v5
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3
with:
python-version: "3.11"
enable-cache: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
STACKONE_API_KEY: ${{ secrets.STACKONE_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Install uv
uses: astral-sh/setup-uv@v5
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3
with:
python-version: "3.11"
enable-cache: true
Expand Down
62 changes: 54 additions & 8 deletions examples/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import subprocess
import importlib.util
import sys
from pathlib import Path

import pytest
import responses


def get_example_files() -> list[str]:
Expand All @@ -21,19 +22,64 @@ def get_example_files() -> list[str]:

EXAMPLES = get_example_files()

# Map of example files to required optional packages
OPTIONAL_DEPENDENCIES = {
"openai_integration.py": ["openai"],
"langchain_integration.py": ["langchain_openai"],
"crewai_integration.py": ["crewai"],
}

def test_example_files_exist():

def test_example_files_exist() -> None:
"""Verify that we found example files to test"""
assert len(EXAMPLES) > 0, "No example files found"
print(f"Found {len(EXAMPLES)} examples")


@pytest.mark.parametrize("example_file", EXAMPLES)
def test_run_example(example_file):
@responses.activate
def test_run_example(example_file: str) -> None:
"""Run each example file directly using python"""
# Skip if optional dependencies are not available
if example_file in OPTIONAL_DEPENDENCIES:
for module in OPTIONAL_DEPENDENCIES[example_file]:
try:
__import__(module)
except ImportError:
pytest.skip(f"Skipping {example_file}: {module} not installed")

# Setup mock responses for examples that need them
if example_file in ["index.py", "file_uploads.py"]:
# Mock employee list endpoint
responses.add(
responses.GET,
"https://api.stackone.com/unified/hris/employees",
json={
"data": [
{
"id": "test-employee-1",
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]"
}
]
},
status=200
)

# Mock document upload endpoint
responses.add(
responses.POST,
"https://api.stackone.com/unified/hris/employees/c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA/documents/upload",
json={"success": True, "document_id": "test-doc-123"},
status=200
)

example_path = Path(__file__).parent / example_file
result = subprocess.run([sys.executable, str(example_path)], capture_output=True, text=True)
if result.returncode != 0:
print(f"stdout: {result.stdout}")
print(f"stderr: {result.stderr}")
pytest.fail(f"Example {example_file} failed with return code {result.returncode}")

# Import and run the example module directly
spec = importlib.util.spec_from_file_location("example", example_path)
if spec and spec.loader:
module = importlib.util.module_from_spec(spec)
sys.modules["example"] = module
spec.loader.exec_module(module)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dev = [
"pytest-asyncio>=0.25.3",
"pytest-cov>=6.0.0",
"pytest-snapshot>=0.9.0",
"responses>=0.25.8",
"ruff>=0.9.6",
"stackone-ai",
"types-requests>=2.31.0.20240311",
Expand Down
Loading