Skip to content

Commit f2d5dab

Browse files
committed
Added tests for copy
1 parent a0b7897 commit f2d5dab

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 0.1.7 (unreleased)
22

3-
- Fixed binary copy for psycopg3
3+
- Fixed `set_types` for psycopg3
44

55
## 0.1.6 (2022-05-22)
66

tests/test_psycopg.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,22 @@ def test_binary_format_non_contiguous(self):
5151
assert not embedding.data.contiguous
5252
res = conn.execute('SELECT %b::vector', (embedding,)).fetchone()[0]
5353
assert np.array_equal(res, np.array([3, 2, 1.5]))
54+
55+
def test_text_copy(self):
56+
embedding = np.array([1.5, 2, 3])
57+
cur = conn.cursor()
58+
with cur.copy("COPY item (embedding) FROM STDIN") as copy:
59+
copy.write_row([embedding])
60+
61+
def test_binary_copy(self):
62+
embedding = np.array([1.5, 2, 3])
63+
cur = conn.cursor()
64+
with cur.copy("COPY item (embedding) FROM STDIN WITH (FORMAT BINARY)") as copy:
65+
copy.write_row([embedding])
66+
67+
def test_binary_copy_set_types(self):
68+
embedding = np.array([1.5, 2, 3])
69+
cur = conn.cursor()
70+
with cur.copy("COPY item (id, embedding) FROM STDIN WITH (FORMAT BINARY)") as copy:
71+
copy.set_types(['int8', 'vector'])
72+
copy.write_row([1, embedding])

0 commit comments

Comments
 (0)