MCPcopy
hub / github.com/psycopg/psycopg / test_copy_to_leaks

Function test_copy_to_leaks

tests/test_copy.py:830–873  ·  view source on GitHub ↗
(conn_cls, dsn, faker, fmt, set_types, method, gc)

Source from the content-addressed store, hash-verified

828)
829@pytest.mark.parametrize("method", ["read", "iter", "row", "rows"])
830def test_copy_to_leaks(conn_cls, dsn, faker, fmt, set_types, method, gc):
831 faker.format = PyFormat.from_pq(fmt)
832 faker.choose_schema(ncols=20)
833 faker.make_records(20)
834
835 def work():
836 with conn_cls.connect(dsn) as conn:
837 with conn.cursor(binary=fmt) as cur:
838 cur.execute(faker.drop_stmt)
839 cur.execute(faker.create_stmt)
840 with faker.find_insert_problem(conn):
841 cur.executemany(faker.insert_stmt, faker.records)
842
843 stmt = sql.SQL(
844 "copy (select {} from {} order by id) to stdout (format {})"
845 ).format(
846 sql.SQL(", ").join(faker.fields_names),
847 faker.table_name,
848 sql.SQL(fmt.name),
849 )
850
851 with cur.copy(stmt) as copy:
852 if set_types:
853 copy.set_types(faker.types_names)
854
855 if method == "read":
856 while copy.read():
857 pass
858 elif method == "iter":
859 list(copy)
860 elif method == "row":
861 while copy.read_row() is not None:
862 pass
863 elif method == "rows":
864 list(copy.rows())
865
866 gc.collect()
867 n = []
868 for i in range(3):
869 work()
870 gc.collect()
871 n.append(gc.count())
872
873 assert n[0] == n[1] == n[2], f"objects leaked: {n[1] - n[0]}, {n[2] - n[1]}"
874
875
876@pytest.mark.slow

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