MCPcopy
hub / github.com/psycopg/psycopg / test_subclass_nulling_dumper

Function test_subclass_nulling_dumper

tests/test_copy.py:355–374  ·  view source on GitHub ↗
(conn, format)

Source from the content-addressed store, hash-verified

353
354@pytest.mark.parametrize("format", pq.Format)
355def test_subclass_nulling_dumper(conn, format):
356 Base: type = StrNoneDumper if format == pq.Format.TEXT else StrNoneBinaryDumper
357
358 class MyStrDumper(Base): # type: ignore
359
360 def dump(self, obj):
361 return super().dump(obj) if obj else None
362
363 conn.adapters.register_dumper(str, MyStrDumper)
364
365 cur = conn.cursor()
366 ensure_table(cur, sample_tabledef)
367
368 with cur.copy(f"copy copy_in (data) from stdin (format {format.name})") as copy:
369 copy.write_row(("hello",))
370 copy.write_row(("",))
371
372 cur.execute("select data from copy_in order by col1")
373 recs = cur.fetchall()
374 assert recs == [("hello",), (None,)]
375
376
377@pytest.mark.parametrize("format", pq.Format)

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected