Skip to content

Commit

Permalink
Added test for Automap with SQLAlchemy - #74
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 11, 2024
1 parent 8be15b2 commit 3fa840e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
from sqlalchemy import create_engine, insert, inspect, select, text, MetaData, Table, Column, Index, Integer
from sqlalchemy.exc import StatementError
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from sqlalchemy.orm import declarative_base, mapped_column, Session
from sqlalchemy.sql import func
Expand Down Expand Up @@ -403,6 +404,16 @@ def test_insert_bulk(self):
def test_insert_text(self):
session.execute(text('INSERT INTO sqlalchemy_orm_item (embedding) VALUES (:embedding)'), {'embedding': np.array([1, 2, 3])})

def test_automap(self):
metadata = MetaData()
metadata.reflect(engine, only=['sqlalchemy_orm_item'])
AutoBase = automap_base(metadata=metadata)
AutoBase.prepare()
AutoItem = AutoBase.classes.sqlalchemy_orm_item
session.execute(insert(AutoItem), [{'embedding': np.array([1, 2, 3])}])
item = session.query(AutoItem).first()
assert item.embedding.tolist() == [1, 2, 3]

@pytest.mark.asyncio
async def test_async(self):
engine = create_async_engine('postgresql+psycopg://localhost/pgvector_python_test')
Expand Down

0 comments on commit 3fa840e

Please sign in to comment.