MCPcopy
hub / github.com/psycopg/psycopg / test_subclass_adapter

Function test_subclass_adapter

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

Source from the content-addressed store, hash-verified

324
325@pytest.mark.parametrize("format", pq.Format)
326def test_subclass_adapter(conn, format):
327 if format == pq.Format.TEXT:
328 from psycopg.types.string import StrDumper as BaseDumper
329 else:
330 from psycopg.types.string import StrBinaryDumper
331
332 BaseDumper = StrBinaryDumper # type: ignore
333
334 class MyStrDumper(BaseDumper):
335
336 def dump(self, obj):
337 rv = super().dump(obj)
338 assert rv
339 return bytes(rv) * 2
340
341 conn.adapters.register_dumper(str, MyStrDumper)
342
343 cur = conn.cursor()
344 ensure_table(cur, sample_tabledef)
345
346 with cur.copy(f"copy copy_in (data) from stdin (format {format.name})") as copy:
347 copy.write_row(("hello",))
348
349 cur.execute("select data from copy_in")
350 rec = cur.fetchone()
351 assert rec[0] == "hellohello"
352
353
354@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
fetchoneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…