(conn)
| 524 | |
| 525 | |
| 526 | def 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 | |
| 558 | def test_copy_in_allchars(conn): |
nothing calls this directly
no test coverage detected