(conn_cls, dsn, faker, fmt, set_types, gc)
| 201 | ) |
| 202 | @pytest.mark.crdb_skip("copy array") |
| 203 | def 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 | |
| 241 | def copyopt(format): |
nothing calls this directly
no test coverage detected