MCPcopy
hub / github.com/psycopg/psycopg / test_copy_from_leaks

Function test_copy_from_leaks

tests/crdb/test_copy.py:203–238  ·  view source on GitHub ↗
(conn_cls, dsn, faker, fmt, set_types, gc)

Source from the content-addressed store, hash-verified

201)
202@pytest.mark.crdb_skip("copy array")
203def test_copy_from_leaks(conn_cls, dsn, faker, fmt, set_types, gc):
204 faker.format = PyFormat.from_pq(fmt)
205 faker.choose_schema(ncols=20)
206 faker.make_records(20)
207
208 def work():
209 with conn_cls.connect(dsn) as conn:
210 with conn.cursor(binary=fmt) as cur:
211 cur.execute(faker.drop_stmt)
212 cur.execute(faker.create_stmt)
213
214 stmt = sql.SQL("copy {} ({}) from stdin {}").format(
215 faker.table_name,
216 sql.SQL(", ").join(faker.fields_names),
217 sql.SQL("with binary" if fmt else ""),
218 )
219 with cur.copy(stmt) as copy:
220 if set_types:
221 copy.set_types(faker.types_names)
222 for row in faker.records:
223 copy.write_row(row)
224
225 cur.execute(faker.select_stmt)
226 recs = cur.fetchall()
227
228 for got, want in zip(recs, faker.records):
229 faker.assert_record(got, want)
230
231 gc.collect()
232 n = []
233 for i in range(3):
234 work()
235 gc.collect()
236 n.append(gc.count())
237
238 assert n[0] == n[1] == n[2], f"objects leaked: {n[1] - n[0]}, {n[2] - n[1]}"
239
240
241def copyopt(format):

Callers

nothing calls this directly

Calls 6

from_pqMethod · 0.80
choose_schemaMethod · 0.80
make_recordsMethod · 0.80
collectMethod · 0.80
countMethod · 0.80
workFunction · 0.70

Tested by

no test coverage detected