Skip to content

Commit 8441b46

Browse files
committed
Improved tests [skip ci]
1 parent c7cd058 commit 8441b46

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

tests/test_psycopg2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_halfvec(self):
4646

4747
cur.execute('SELECT half_embedding FROM psycopg2_items ORDER BY id')
4848
res = cur.fetchall()
49-
assert res[0][0].to_list() == [1.5, 2, 3]
49+
assert res[0][0] == HalfVector([1.5, 2, 3])
5050
assert res[1][0] is None
5151

5252
def test_bit(self):
@@ -64,7 +64,7 @@ def test_sparsevec(self):
6464

6565
cur.execute('SELECT sparse_embedding FROM psycopg2_items ORDER BY id')
6666
res = cur.fetchall()
67-
assert res[0][0].to_list() == [1.5, 2, 3]
67+
assert res[0][0] == SparseVector([1.5, 2, 3])
6868
assert res[1][0] is None
6969

7070
def test_vector_array(self):
@@ -82,17 +82,17 @@ def test_halfvec_array(self):
8282

8383
cur.execute('SELECT half_embeddings FROM psycopg2_items ORDER BY id')
8484
res = cur.fetchone()
85-
assert res[0][0].to_list() == [1.5, 2, 3]
86-
assert res[0][1].to_list() == [4.5, 5, 6]
85+
assert res[0][0] == HalfVector([1.5, 2, 3])
86+
assert res[0][1] == HalfVector([4.5, 5, 6])
8787

8888
def test_sparsevec_array(self):
8989
embeddings = [SparseVector([1.5, 2, 3]), SparseVector([4.5, 5, 6])]
9090
cur.execute('INSERT INTO psycopg2_items (sparse_embeddings) VALUES (%s::sparsevec[])', (embeddings,))
9191

9292
cur.execute('SELECT sparse_embeddings FROM psycopg2_items ORDER BY id')
9393
res = cur.fetchone()
94-
assert res[0][0].to_list() == [1.5, 2, 3]
95-
assert res[0][1].to_list() == [4.5, 5, 6]
94+
assert res[0][0] == SparseVector([1.5, 2, 3])
95+
assert res[0][1] == SparseVector([4.5, 5, 6])
9696

9797
def test_cursor_factory(self):
9898
for cursor_factory in [DictCursor, RealDictCursor, NamedTupleCursor]:

tests/test_sparse_vector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_equality(self):
5656
assert SparseVector([1, 0, 2, 0, 3, 0]) == SparseVector([1, 0, 2, 0, 3, 0])
5757
assert SparseVector([1, 0, 2, 0, 3, 0]) != SparseVector([1, 0, 2, 0, 3, 1])
5858
assert SparseVector([1, 0, 2, 0, 3, 0]) == SparseVector({2: 2, 4: 3, 0: 1, 3: 0}, 6)
59+
assert SparseVector({}, 1) != SparseVector({}, 2)
5960

6061
def test_dimensions(self):
6162
assert SparseVector([1, 0, 2, 0, 3, 0]).dimensions() == 6

0 commit comments

Comments
 (0)