Skip to content

Commit b12c228

Browse files
committed
removed all sql text to services/db/client.py from tests
1 parent 3846c00 commit b12c228

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

test2text/services/db/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,10 @@ def join_all_tables_by_test_cases(
296296
"""
297297
data = self.conn.execute(sql, params)
298298
return data.fetchall()
299+
300+
def get_embeddings_by_id(self, id1: int, from_table: str):
301+
cursor = self.conn.execute(
302+
f"SELECT embedding FROM {from_table} WHERE id = ?",
303+
(id1,)
304+
)
305+
return cursor.fetchone()

tests/test_db/test_tables/test_annotations.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ def test_set_embedding(self):
6767
orig_embedding = [0.1] * self.db.annotations.embedding_size
6868
self.db.annotations.set_embedding(id1, orig_embedding)
6969
self.db.conn.commit()
70-
cursor = self.db.conn.execute(
71-
"SELECT embedding FROM Annotations WHERE id = ?", (id1,)
72-
)
73-
result = cursor.fetchone()
74-
cursor.close()
70+
result = self.db.get_embeddings_by_id(id1, "Annotations")
7571
self.assertIsNotNone(result)
7672
read_embedding = unpack_float32(result[0])
7773
self.assertEqual(len(read_embedding), self.db.annotations.embedding_size)
@@ -80,11 +76,7 @@ def test_set_embedding(self):
8076
new_embedding = [0.9] * self.db.annotations.embedding_size
8177
self.db.annotations.set_embedding(id1, new_embedding)
8278
self.db.conn.commit()
83-
cursor = self.db.conn.execute(
84-
"SELECT embedding FROM Annotations WHERE id = ?", (id1,)
85-
)
86-
result = cursor.fetchone()
87-
cursor.close()
79+
result = self.db.get_embeddings_by_id(id1, "Annotations")
8880
self.assertIsNotNone(result)
8981
read_embedding = unpack_float32(result[0])
9082
self.assertEqual(len(read_embedding), self.db.annotations.embedding_size)

0 commit comments

Comments
 (0)