Skip to content

Commit d963813

Browse files
committed
Updated style [skip ci]
1 parent 634215c commit d963813

4 files changed

Lines changed: 31 additions & 31 deletions

File tree

tests/test_asyncpg.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ async def test_vector(self):
2727
embedding2 = [4.5, 5, 6]
2828
embedding3 = np.array([7.5, 8, 9]) if NUMPY_AVAILABLE else [7.5, 8, 9]
2929
embedding4 = None
30-
await conn.execute("INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2), ($3), ($4)", embedding, embedding2, embedding3, embedding4)
30+
await conn.execute('INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2), ($3), ($4)', embedding, embedding2, embedding3, embedding4)
3131

32-
res = await conn.fetch("SELECT * FROM asyncpg_items ORDER BY id")
32+
res = await conn.fetch('SELECT * FROM asyncpg_items ORDER BY id')
3333
assert res[0]['embedding'] == embedding
3434
assert res[1]['embedding'] == Vector(embedding2)
3535
assert res[2]['embedding'] == Vector(embedding3)
3636
assert res[3]['embedding'] is None
3737

3838
# ensures binary format is correct
39-
text_res = await conn.fetch("SELECT embedding::text FROM asyncpg_items ORDER BY id LIMIT 1")
39+
text_res = await conn.fetch('SELECT embedding::text FROM asyncpg_items ORDER BY id LIMIT 1')
4040
assert text_res[0]['embedding'] == '[1.5,2,3]'
4141

4242
await conn.close()
@@ -50,15 +50,15 @@ async def test_halfvec(self):
5050
embedding = HalfVector([1.5, 2, 3])
5151
embedding2 = [4.5, 5, 6]
5252
embedding3 = None
53-
await conn.execute("INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2), ($3)", embedding, embedding2, embedding3)
53+
await conn.execute('INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2), ($3)', embedding, embedding2, embedding3)
5454

55-
res = await conn.fetch("SELECT * FROM asyncpg_items ORDER BY id")
55+
res = await conn.fetch('SELECT * FROM asyncpg_items ORDER BY id')
5656
assert res[0]['embedding'] == embedding
5757
assert res[1]['embedding'] == HalfVector(embedding2)
5858
assert res[2]['embedding'] is None
5959

6060
# ensures binary format is correct
61-
text_res = await conn.fetch("SELECT embedding::text FROM asyncpg_items ORDER BY id LIMIT 1")
61+
text_res = await conn.fetch('SELECT embedding::text FROM asyncpg_items ORDER BY id LIMIT 1')
6262
assert text_res[0]['embedding'] == '[1.5,2,3]'
6363

6464
await conn.close()
@@ -71,15 +71,15 @@ async def test_bit(self):
7171

7272
embedding = asyncpg.BitString('101') # type: ignore
7373
embedding2 = None
74-
await conn.execute("INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2)", embedding, embedding2)
74+
await conn.execute('INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2)', embedding, embedding2)
7575

76-
res = await conn.fetch("SELECT * FROM asyncpg_items ORDER BY id")
76+
res = await conn.fetch('SELECT * FROM asyncpg_items ORDER BY id')
7777
assert res[0]['embedding'].as_string() == '101'
7878
assert res[0]['embedding'].to_int() == 5
7979
assert res[1]['embedding'] is None
8080

8181
# ensures binary format is correct
82-
text_res = await conn.fetch("SELECT embedding::text FROM asyncpg_items ORDER BY id LIMIT 1")
82+
text_res = await conn.fetch('SELECT embedding::text FROM asyncpg_items ORDER BY id LIMIT 1')
8383
assert text_res[0]['embedding'] == '101'
8484

8585
await conn.close()
@@ -92,14 +92,14 @@ async def test_sparsevec(self):
9292

9393
embedding = SparseVector([1.5, 2, 3])
9494
embedding2 = None
95-
await conn.execute("INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2)", embedding, embedding2)
95+
await conn.execute('INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2)', embedding, embedding2)
9696

97-
res = await conn.fetch("SELECT * FROM asyncpg_items ORDER BY id")
97+
res = await conn.fetch('SELECT * FROM asyncpg_items ORDER BY id')
9898
assert res[0]['embedding'] == embedding
9999
assert res[1]['embedding'] is None
100100

101101
# ensures binary format is correct
102-
text_res = await conn.fetch("SELECT embedding::text FROM asyncpg_items ORDER BY id LIMIT 1")
102+
text_res = await conn.fetch('SELECT embedding::text FROM asyncpg_items ORDER BY id LIMIT 1')
103103
assert text_res[0]['embedding'] == '{1:1.5,2:2,3:3}/3'
104104

105105
await conn.close()
@@ -111,16 +111,16 @@ async def test_vector_array(self):
111111
await conn.execute('CREATE TABLE asyncpg_items (id bigserial PRIMARY KEY, embeddings vector[])')
112112

113113
embeddings = [Vector([1.5, 2, 3]), Vector([4.5, 5, 6])]
114-
await conn.execute("INSERT INTO asyncpg_items (embeddings) VALUES ($1)", embeddings)
114+
await conn.execute('INSERT INTO asyncpg_items (embeddings) VALUES ($1)', embeddings)
115115

116116
embeddings2 = [[1.5, 2, 3], [4.5, 5, 6]]
117-
await conn.execute("INSERT INTO asyncpg_items (embeddings) VALUES (ARRAY[$1, $2]::vector[])", embeddings2[0], embeddings2[1])
117+
await conn.execute('INSERT INTO asyncpg_items (embeddings) VALUES (ARRAY[$1, $2]::vector[])', embeddings2[0], embeddings2[1])
118118

119119
if NUMPY_AVAILABLE:
120120
embeddings3 = [np.array([1.5, 2, 3]), np.array([4.5, 5, 6])]
121-
await conn.execute("INSERT INTO asyncpg_items (embeddings) VALUES (ARRAY[$1, $2]::vector[])", embeddings3[0], embeddings3[1])
121+
await conn.execute('INSERT INTO asyncpg_items (embeddings) VALUES (ARRAY[$1, $2]::vector[])', embeddings3[0], embeddings3[1])
122122

123-
res = await conn.fetch("SELECT * FROM asyncpg_items ORDER BY id")
123+
res = await conn.fetch('SELECT * FROM asyncpg_items ORDER BY id')
124124
assert res[0]['embeddings'] == embeddings
125125
assert res[1]['embeddings'] == [Vector(e) for e in embeddings2]
126126
if NUMPY_AVAILABLE:
@@ -143,9 +143,9 @@ async def init(conn):
143143
embedding = Vector([1.5, 2, 3])
144144
embedding2 = [1.5, 2, 3]
145145
embedding3 = None
146-
await conn.execute("INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2), ($3)", embedding, embedding2, embedding3)
146+
await conn.execute('INSERT INTO asyncpg_items (embedding) VALUES ($1), ($2), ($3)', embedding, embedding2, embedding3)
147147

148-
res = await conn.fetch("SELECT * FROM asyncpg_items ORDER BY id")
148+
res = await conn.fetch('SELECT * FROM asyncpg_items ORDER BY id')
149149
assert res[0]['embedding'] == embedding
150150
assert res[1]['embedding'] == Vector(embedding2)
151151
assert res[2]['embedding'] is None

tests/test_django.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Migration(migrations.Migration):
131131
sql_statements = loader.collect_sql([(migration, False)])
132132

133133
with connection.cursor() as cursor:
134-
cursor.execute("DROP TABLE IF EXISTS django_app_item")
134+
cursor.execute('DROP TABLE IF EXISTS django_app_item')
135135
cursor.execute('\n'.join(sql_statements))
136136

137137

tests/test_psycopg.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,19 @@ def test_sparsevec_text_format(self):
128128
def test_text_copy_from(self):
129129
embedding = [1.5, 2, 3]
130130
cur = conn.cursor()
131-
with cur.copy("COPY psycopg_items (embedding, half_embedding, binary_embedding, sparse_embedding) FROM STDIN") as copy:
131+
with cur.copy('COPY psycopg_items (embedding, half_embedding, binary_embedding, sparse_embedding) FROM STDIN') as copy:
132132
copy.write_row([Vector(embedding), HalfVector(embedding), '101', SparseVector(embedding)])
133133

134134
def test_binary_copy_from(self):
135135
embedding = [1.5, 2, 3]
136136
cur = conn.cursor()
137-
with cur.copy("COPY psycopg_items (embedding, half_embedding, binary_embedding, sparse_embedding) FROM STDIN WITH (FORMAT BINARY)") as copy:
137+
with cur.copy('COPY psycopg_items (embedding, half_embedding, binary_embedding, sparse_embedding) FROM STDIN WITH (FORMAT BINARY)') as copy:
138138
copy.write_row([Vector(embedding), HalfVector(embedding), Bit('101'), SparseVector(embedding)])
139139

140140
def test_binary_copy_from_set_types(self):
141141
embedding = [1.5, 2, 3]
142142
cur = conn.cursor()
143-
with cur.copy("COPY psycopg_items (id, embedding, half_embedding, binary_embedding, sparse_embedding) FROM STDIN WITH (FORMAT BINARY)") as copy:
143+
with cur.copy('COPY psycopg_items (id, embedding, half_embedding, binary_embedding, sparse_embedding) FROM STDIN WITH (FORMAT BINARY)') as copy:
144144
copy.set_types(['int8', 'vector', 'halfvec', 'bit', 'sparsevec'])
145145
copy.write_row([1, Vector(embedding), HalfVector(embedding), Bit('101'), SparseVector(embedding)])
146146

@@ -149,17 +149,17 @@ def test_text_copy_to(self):
149149
half_embedding = HalfVector([1.5, 2, 3])
150150
conn.execute('INSERT INTO psycopg_items (embedding, half_embedding) VALUES (%s, %s)', (embedding, half_embedding))
151151
cur = conn.cursor()
152-
with cur.copy("COPY psycopg_items (embedding, half_embedding) TO STDOUT") as copy:
152+
with cur.copy('COPY psycopg_items (embedding, half_embedding) TO STDOUT') as copy:
153153
for row in copy.rows():
154-
assert row[0] == "[1.5,2,3]"
155-
assert row[1] == "[1.5,2,3]"
154+
assert row[0] == '[1.5,2,3]'
155+
assert row[1] == '[1.5,2,3]'
156156

157157
def test_binary_copy_to(self):
158158
embedding = Vector([1.5, 2, 3])
159159
half_embedding = HalfVector([1.5, 2, 3])
160160
conn.execute('INSERT INTO psycopg_items (embedding, half_embedding) VALUES (%s, %s)', (embedding, half_embedding))
161161
cur = conn.cursor()
162-
with cur.copy("COPY psycopg_items (embedding, half_embedding) TO STDOUT WITH (FORMAT BINARY)") as copy:
162+
with cur.copy('COPY psycopg_items (embedding, half_embedding) TO STDOUT WITH (FORMAT BINARY)') as copy:
163163
for row in copy.rows():
164164
assert Vector.from_binary(row[0]) == embedding
165165
assert HalfVector.from_binary(row[1]) == half_embedding
@@ -169,7 +169,7 @@ def test_binary_copy_to_set_types(self):
169169
half_embedding = HalfVector([1.5, 2, 3])
170170
conn.execute('INSERT INTO psycopg_items (embedding, half_embedding) VALUES (%s, %s)', (embedding, half_embedding))
171171
cur = conn.cursor()
172-
with cur.copy("COPY psycopg_items (embedding, half_embedding) TO STDOUT WITH (FORMAT BINARY)") as copy:
172+
with cur.copy('COPY psycopg_items (embedding, half_embedding) TO STDOUT WITH (FORMAT BINARY)') as copy:
173173
copy.set_types(['vector', 'halfvec'])
174174
for row in copy.rows():
175175
assert row[0] == embedding

tests/test_sqlalchemy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
psycopg2_type_engine = create_engine('postgresql+psycopg2://localhost/pgvector_python_test')
2121

2222

23-
@event.listens_for(psycopg2_type_engine, "connect")
23+
@event.listens_for(psycopg2_type_engine, 'connect')
2424
def psycopg2_connect(dbapi_connection, connection_record):
2525
from pgvector.psycopg2 import register_vector
2626
register_vector(dbapi_connection)
@@ -32,7 +32,7 @@ def psycopg2_connect(dbapi_connection, connection_record):
3232
psycopg_type_engine = create_engine('postgresql+psycopg://localhost/pgvector_python_test')
3333

3434

35-
@event.listens_for(psycopg_type_engine, "connect")
35+
@event.listens_for(psycopg_type_engine, 'connect')
3636
def psycopg_connect(dbapi_connection, connection_record):
3737
from pgvector.psycopg import register_vector
3838
register_vector(dbapi_connection)
@@ -42,7 +42,7 @@ def psycopg_connect(dbapi_connection, connection_record):
4242
psycopg_async_type_engine = create_async_engine('postgresql+psycopg://localhost/pgvector_python_test')
4343

4444

45-
@event.listens_for(psycopg_async_type_engine.sync_engine, "connect")
45+
@event.listens_for(psycopg_async_type_engine.sync_engine, 'connect')
4646
def psycopg_async_connect(dbapi_connection, connection_record):
4747
from pgvector.psycopg import register_vector_async
4848
dbapi_connection.run_async(register_vector_async)
@@ -52,7 +52,7 @@ def psycopg_async_connect(dbapi_connection, connection_record):
5252
asyncpg_type_engine = create_async_engine('postgresql+asyncpg://localhost/pgvector_python_test')
5353

5454

55-
@event.listens_for(asyncpg_type_engine.sync_engine, "connect")
55+
@event.listens_for(asyncpg_type_engine.sync_engine, 'connect')
5656
def asyncpg_connect(dbapi_connection, connection_record):
5757
from pgvector.asyncpg import register_vector
5858
dbapi_connection.run_async(register_vector)

0 commit comments

Comments
 (0)