Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Enable Astra tests for Python 3.12 only #28

Merged
merged 4 commits into from
Jan 17, 2025
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
30 changes: 24 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,30 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Run `make test`
- name: Test All Stores (3.12 only)
if: ${{ success() && matrix.python-version == '3.12' }}
run:
uv run --package langchain-graph-retriever python -m pytest -vs
./packages/langchain-graph-retriever/tests/unit_tests/
./packages/langchain-graph-retriever/tests/integration_tests/
--stores=mem_norm --stores=mem --stores=cassandra --stores=chroma --stores=opensearch
cd packages/langchain-graph-retriever && uv run pytest -vs .
--stores=all
--junitxml=junit/test-results-${{ matrix.python-version }}.xml
env:
ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }}
ASTRA_DB_API_ENDPOINT: ${{ secrets.ASTRA_DB_API_ENDPOINT }}
ASTRA_DB_KEYSPACE: ci_${{ github.run_id }}_${{ strategy.job-index }}_${{ github.run_attempt }}

- name: Drop Astra Keyspace
if: ${{ matrix.python-version == '3.12' }}
run:
uv run scripts/drop-astra-keyspace.py
env:
ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }}
ASTRA_DB_API_ENDPOINT: ${{ secrets.ASTRA_DB_API_ENDPOINT }}
ASTRA_DB_KEYSPACE: ci_${{ github.run_id }}_${{ strategy.job-index }}_${{ github.run_attempt }}

- name: Test In-Memory Stores (non-3.12)
if: ${{ success() && matrix.python-version != '3.12' }}
run:
cd packages/langchain-graph-retriever && uv run pytest -vs .
--junitxml=junit/test-results-${{ matrix.python-version }}.xml

- name: Run `make mypy`
Expand All @@ -82,7 +100,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: pytest-results-${{ matrix.python-version }}
path: junit/test-results-${{ matrix.python-version }}.xml
path: packages/*/junit/test-results-${{ matrix.python-version }}.xml

# check-docs:
# runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ unit:
.PHONY: test
test: sync-langchain-graph-retriever
@echo "🚀 Testing code: Running pytest"
@cd packages/langchain-graph-retriever && uv run pytest -vs ./tests/unit_tests ./tests/integration_tests --stores=all
@cd packages/langchain-graph-retriever && uv run pytest -vs . --stores=all

.PHONY: mypy
mypy:
Expand Down
52 changes: 52 additions & 0 deletions packages/langchain-graph-retriever/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import asyncio

import pytest
from pytest import Parser

from tests.integration_tests.stores import ALL_STORES, TESTCONTAINER_STORES


@pytest.fixture(scope="session")
def event_loop():
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
yield loop
loop.close()


def pytest_addoption(parser: Parser):
parser.addoption(
"--stores",
action="append",
metavar="STORE",
choices=ALL_STORES + ["all"],
help="run tests for the given store (default: 'mem' and 'mem_norm')",
)
parser.addoption(
"--testcontainer",
action="append",
metavar="STORE",
choices=TESTCONTAINER_STORES + ["none"],
help="which stores to run testcontainers for (default: 'all')",
)


# TODO: Allow marking tests as only supporting a subset of stores?
#
# def pytest_configure(config):
# # register an additional marker
# config.addinivalue_line(
# "markers", "svc(name): tests that require the named service"
# )
#
# def pytest_runtest_setup(item):
# """Skip the test unless all of the marked services are present."""
#
# required_svcs = {mark.args[0] for mark in item.iter_markers(name="svc")}
# provided_svcs = set(item.config.getoption("-S") or [])
#
# missing_svcs = required_svcs - provided_svcs
# if missing_svcs:
# pytest.skip(f"test requires services {missing_svcs!r}")

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def teardown_open_search(store: OpenSearchVectorSearch) -> None:
def _astra_store_factory(_request: pytest.FixtureRequest) -> StoreFactory:
import os

from astrapy import AstraDBDatabaseAdmin
from astrapy.authentication import StaticTokenProvider
from dotenv import load_dotenv
from langchain_astradb import AstraDBVectorStore
Expand All @@ -211,6 +212,9 @@ def _astra_store_factory(_request: pytest.FixtureRequest) -> StoreFactory:
keyspace = os.environ.get("ASTRA_DB_KEYSPACE", "default_keyspace")
api_endpoint = os.environ["ASTRA_DB_API_ENDPOINT"]

admin = AstraDBDatabaseAdmin(api_endpoint=api_endpoint, token=token)
admin.create_keyspace(keyspace)

def create_astra(
name: str, docs: list[Document], embedding: Embeddings
) -> AstraDBVectorStore:
Expand Down
12 changes: 12 additions & 0 deletions scripts/drop-astra-keyspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os

from astrapy import AstraDBDatabaseAdmin
from astrapy.authentication import StaticTokenProvider

token = StaticTokenProvider(os.environ["ASTRA_DB_APPLICATION_TOKEN"])
keyspace = os.environ.get("ASTRA_DB_KEYSPACE", "default_keyspace")
api_endpoint = os.environ["ASTRA_DB_API_ENDPOINT"]

admin = AstraDBDatabaseAdmin(api_endpoint=api_endpoint, token=token)
if keyspace in admin.list_keyspaces():
admin.drop_keyspace(keyspace)
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading