MCPcopy
hub / github.com/psycopg/psycopg / test_copy_in_text_pinned

Function test_copy_in_text_pinned

tests/test_copy.py:526–555  ·  view source on GitHub ↗
(conn)

Source from the content-addressed store, hash-verified

524
525
526def test_copy_in_text_pinned(conn):
527 cur = conn.cursor()
528 cur.adapters.register_dumper(int, StrictIntDumper)
529
530 cols = [
531 "col1 serial primary key",
532 "col2 int",
533 "col3 int",
534 "col4 double precision",
535 "col5 double precision",
536 ]
537 ensure_table(cur, ",".join(cols))
538
539 with cur.copy(
540 "copy copy_in (col2,col3,col4,col5) from stdin (format text)"
541 ) as copy:
542 # pinned dumpers from set_types: type check & cast done on psycopg side
543 # much faster, allows catching errors early without postgres involvement
544 copy.set_types(["int4", "int4", "double precision", "double precision"])
545 copy.write_row([1, 2, 3, 4.1])
546 with pytest.raises(
547 (e.DataError, TypeError)
548 ): # FIXME: should errors from dumpers be harmonized?
549 copy.write_row([1.0, 2, 3, 4.1])
550 with pytest.raises((e.DataError, TypeError)):
551 copy.write_row([1, "2", 3, 4.1])
552
553 cur.execute("select col2,col3,col4,col5 from copy_in order by 1")
554 data = cur.fetchall()
555 assert data == [(1, 2, 3, 4.1)]
556
557
558def test_copy_in_allchars(conn):

Callers

nothing calls this directly

Calls 9

register_dumperMethod · 0.80
set_typesMethod · 0.80
ensure_tableFunction · 0.70
cursorMethod · 0.45
joinMethod · 0.45
copyMethod · 0.45
write_rowMethod · 0.45
executeMethod · 0.45
fetchallMethod · 0.45

Tested by

no test coverage detected