Skip to content

Commit

Permalink
Added tests for Psycopg 2 cursor factories
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Aug 25, 2024
1 parent 472bdab commit a8a1bf1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_psycopg2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from pgvector.psycopg2 import register_vector, SparseVector
import psycopg2
from psycopg2.extras import DictCursor, NamedTupleCursor

conn = psycopg2.connect(dbname='pgvector_python_test')
conn.autocommit = True
Expand Down Expand Up @@ -53,3 +54,16 @@ def test_sparsevec(self):
res = cur.fetchall()
assert res[0][0].to_list() == [1.5, 2, 3]
assert res[1][0] is None

def test_cursor_factory(self):
for cursor_factory in [DictCursor, NamedTupleCursor]:
conn = psycopg2.connect(dbname='pgvector_python_test')
cur = conn.cursor(cursor_factory=cursor_factory)
register_vector(cur)
conn.close()

def test_cursor_factory_connection(self):
for cursor_factory in [DictCursor, NamedTupleCursor]:
conn = psycopg2.connect(dbname='pgvector_python_test', cursor_factory=cursor_factory)
register_vector(conn)
conn.close()

0 comments on commit a8a1bf1

Please sign in to comment.