MCPcopy
hub / github.com/psycopg/psycopg / test_copy_table_across

Function test_copy_table_across

tests/test_copy.py:921–949  ·  view source on GitHub ↗
(conn_cls, dsn, faker, mode)

Source from the content-addressed store, hash-verified

919@pytest.mark.slow
920@pytest.mark.parametrize("mode", ["row", "block", "binary"])
921def test_copy_table_across(conn_cls, dsn, faker, mode):
922 faker.choose_schema(ncols=20)
923 faker.make_records(20)
924
925 connect = conn_cls.connect
926 with connect(dsn) as conn1, connect(dsn) as conn2:
927 faker.table_name = sql.Identifier("copy_src")
928 conn1.execute(faker.drop_stmt)
929 conn1.execute(faker.create_stmt)
930 conn1.cursor().executemany(faker.insert_stmt, faker.records)
931
932 faker.table_name = sql.Identifier("copy_tgt")
933 conn2.execute(faker.drop_stmt)
934 conn2.execute(faker.create_stmt)
935
936 fmt = "(format binary)" if mode == "binary" else ""
937 with conn1.cursor().copy(f"copy copy_src to stdout {fmt}") as copy1:
938 with conn2.cursor().copy(f"copy copy_tgt from stdin {fmt}") as copy2:
939 if mode == "row":
940 for row in copy1.rows():
941 copy2.write_row(row)
942 else:
943 for data in copy1:
944 copy2.write(data)
945
946 cur = conn2.execute(faker.select_stmt)
947 recs = cur.fetchall()
948 for got, want in zip(recs, faker.records):
949 faker.assert_record(got, want)
950
951
952def test_copy_concurrency(conn):

Callers

nothing calls this directly

Calls 11

choose_schemaMethod · 0.80
make_recordsMethod · 0.80
assert_recordMethod · 0.80
executeMethod · 0.45
executemanyMethod · 0.45
cursorMethod · 0.45
copyMethod · 0.45
rowsMethod · 0.45
write_rowMethod · 0.45
writeMethod · 0.45
fetchallMethod · 0.45

Tested by

no test coverage detected