Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 31 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

name: Lint
name: Test Suite

on:
pull_request:

push:
branches:
- main
Expand All @@ -11,37 +11,49 @@ env:
POETRY_VERSION: "1.8.3"

jobs:
check:
name: Style-check ${{ matrix.python-version }}
test:
name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} [redis-stack ${{matrix.redis-stack-version}}]
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Only lint on the min and max supported Python versions.
# It's extremely unlikely that there's a lint issue on any version in between
# that doesn't show up on the min or max versions.
#
# GitHub rate-limits how many jobs can be running at any one time.
# Starting new jobs is also relatively slow,
# so linting on fewer versions makes CI faster.
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
python-version: [3.9, '3.10', 3.11, 3.12]
connection: ['hiredis', 'plain']
redis-stack-version: ['6.2.6-v9', 'latest', 'edge']

services:
redis:
image: redis/redis-stack-server:${{matrix.redis-stack-version}}
ports:
- 6379:6379

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}

- name: Install dependencies
run: |
poetry install --all-extras
- name: runt tests

- name: Install hiredis if needed
if: matrix.connection == 'hiredis'
run: |
poetry add hiredis

- name: Set Redis version
run: |
echo "REDIS_VERSION=${{ matrix.redis-stack-version }}" >> $GITHUB_ENV

- name: Run tests
run: |
make test
make ci_test
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
######################

test:
poetry run pytest tests
poetry run pytest tests --run-api-tests

test_watch:
poetry run ptw .

ci_test:
poetry run pytest tests

######################
# LINTING AND FORMATTING
Expand All @@ -32,4 +35,4 @@ lint lint_diff lint_package lint_tests:

format format_diff:
poetry run ruff format $(PYTHON_FILES)
poetry run ruff check --select I --fix $(PYTHON_FILES)
poetry run ruff check --select I --fix $(PYTHON_FILES)
23 changes: 23 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,26 @@ async def clear_redis(redis_url: str) -> None:
client = Redis.from_url(redis_url)
await client.flushall()
await client.aclose() # type: ignore[attr-defined]


def pytest_addoption(parser):
parser.addoption(
"--run-api-tests",
action="store_true",
default=False,
help="Run tests that require API keys"
)

def pytest_configure(config):
config.addinivalue_line(
"markers",
"requires_api_keys: mark test as requiring API keys"
)

def pytest_collection_modifyitems(config, items):
if config.getoption("--run-api-tests"):
return
skip_api = pytest.mark.skip(reason="Skipping test because API keys are not provided. Use --run-api-tests to run these tests.")
for item in items:
if item.get_closest_marker("requires_api_keys"):
item.add_marker(skip_api)
1 change: 1 addition & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ def model() -> ChatOpenAI:
return ChatOpenAI(model="gpt-4-turbo-preview", temperature=0)


@pytest.mark.requires_api_keys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this technique and it's something we should implement over the pond at RedisVL

@pytest.mark.asyncio
async def test_async_redis_checkpointer(
redis_url: str, tools: List[BaseTool], model: ChatOpenAI
Expand Down
1 change: 1 addition & 0 deletions tests/test_async_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ async def test_large_batches(store: AsyncRedisStore) -> None:
)


@pytest.mark.requires_api_keys
@pytest.mark.asyncio
async def test_async_store_with_memory_persistence(
redis_url: str,
Expand Down
1 change: 1 addition & 0 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def test_vector_update_with_score_verification(
assert not any(r.key == "doc4" for r in results_new)


@pytest.mark.requires_api_keys
def test_store_with_memory_persistence(redis_url: str) -> None:
"""Test store functionality with memory persistence.

Expand Down
1 change: 1 addition & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def model() -> ChatOpenAI:
return ChatOpenAI(model="gpt-4-turbo-preview", temperature=0)


@pytest.mark.requires_api_keys
def test_sync_redis_checkpointer(
tools: list[BaseTool], model: ChatOpenAI, redis_url: str
) -> None:
Expand Down
Loading