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
4 changes: 2 additions & 2 deletions integration.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ steps:
timeout: "7200s"
substitutions:
_INSTANCE_ID: test-instance
_GOOGLE_DATABASE: test-google-db
_PG_DATABASE: test-pg-db
_GOOGLE_DATABASE: test-gsql-db
_PG_DATABASE: test-pgsql-db
_VERSION: "3.9"

options:
Expand Down
40 changes: 36 additions & 4 deletions tests/integration/test_spanner_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,41 @@ def client() -> Client:
return Client(project=project_id)


@pytest.fixture(scope="class")
def cleanupGSQL(client):
yield

print("\nPerforming GSQL cleanup after each test...")

database = client.instance(instance_id).database(google_database)
operation = database.update_ddl(
[
f"DROP TABLE IF EXISTS {table_name}",
]
)
operation.result(OPERATION_TIMEOUT_SECONDS)

# Code to perform teardown after each test goes here
print("\nGSQL Cleanup complete.")


@pytest.fixture(scope="class")
def cleanupPGSQL(client):
yield

print("\nPerforming PGSQL cleanup after each test...")

database = client.instance(instance_id).database(pg_database)
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
operation.result(OPERATION_TIMEOUT_SECONDS)

# Code to perform teardown after each test goes here
print("\n PGSQL Cleanup complete.")


class TestSpannerDocumentLoaderGoogleSQL:
@pytest.fixture(autouse=True, scope="class")
def setup_database(self, client):
def setup_database(self, client, cleanupGSQL):
database = client.instance(instance_id).database(google_database)
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
operation.result(OPERATION_TIMEOUT_SECONDS)
Expand Down Expand Up @@ -455,7 +487,7 @@ def test_loader_custom_json_metadata(self, client):

class TestSpannerDocumentLoaderPostgreSQL:
@pytest.fixture(autouse=True, scope="class")
def setup_database(self, client):
def setup_database(self, client, cleanupPGSQL):
database = client.instance(instance_id).database(pg_database)
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
operation.result(OPERATION_TIMEOUT_SECONDS)
Expand Down Expand Up @@ -872,15 +904,15 @@ def test_loader_custom_json_metadata(self, client):

class TestSpannerDocumentSaver:
@pytest.fixture(name="google_client")
def setup_google_client(self, client) -> Client:
def setup_google_client(self, client, cleanupGSQL) -> Client:
database = client.instance(instance_id).database(google_database)
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
print("table dropped")
operation.result(OPERATION_TIMEOUT_SECONDS)
yield client

@pytest.fixture(name="pg_client")
def setup_pg_client(self, client) -> Client:
def setup_pg_client(self, client, cleanupPGSQL) -> Client:
database = client.instance(instance_id).database(pg_database)
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
operation.result(OPERATION_TIMEOUT_SECONDS)
Expand Down
23 changes: 14 additions & 9 deletions tests/integration/test_spanner_vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import pytest
from google.cloud.spanner import Client # type: ignore
from langchain_community.document_loaders import HNLoader
from langchain_community.document_loaders import RecursiveUrlLoader
from langchain_community.embeddings import FakeEmbeddings

from langchain_google_spanner.vector_store import ( # type: ignore
Expand Down Expand Up @@ -245,11 +245,13 @@ def setup_database(self, client):
id_column="row_id",
metadata_columns=[
TableColumn(name="metadata", type="JSON", is_null=True),
TableColumn(name="title", type="STRING(MAX)", is_null=False),
TableColumn(name="title", type="STRING(MAX)"),
],
)

loader = HNLoader("https://news.ycombinator.com/item?id=34817881")
loader = RecursiveUrlLoader(
"https://news.ycombinator.com/item?id=1", max_depth=1
)

embeddings = FakeEmbeddings(size=3)

Expand Down Expand Up @@ -327,7 +329,7 @@ def test_spanner_vector_delete_data(self, setup_database):

docs = loader.load()

deleted = db.delete(documents=[docs[0], docs[1]])
deleted = db.delete(documents=docs)

assert deleted

Expand Down Expand Up @@ -459,7 +461,9 @@ def setup_database(self, client):
],
)

loader = HNLoader("https://news.ycombinator.com/item?id=34817881")
loader = RecursiveUrlLoader(
"https://news.ycombinator.com/item?id=1", max_depth=1
)
embeddings = FakeEmbeddings(size=title_vector_size)

def cleanup_db():
Expand Down Expand Up @@ -552,7 +556,7 @@ def test_delete(self, setup_database):
)

docs = loader.load()
deleted = db.delete(documents=[docs[0], docs[1]])
deleted = db.delete(documents=docs)

assert deleted

Expand Down Expand Up @@ -677,8 +681,9 @@ def setup_database(self, client):
],
)

loader = HNLoader("https://news.ycombinator.com/item?id=34817881")

loader = RecursiveUrlLoader(
"https://news.ycombinator.com/item?id=1", max_depth=1
)
embeddings = FakeEmbeddings(size=3)

yield loader, embeddings
Expand Down Expand Up @@ -755,7 +760,7 @@ def test_spanner_vector_delete_data(self, setup_database):

docs = loader.load()

deleted = db.delete(documents=[docs[0], docs[1]])
deleted = db.delete(documents=docs)

assert deleted

Expand Down