MCPcopy
hub / github.com/psycopg/psycopg / test_standard_row_factory

Function test_standard_row_factory

tests/test_cursor_server_async.py:364–379  ·  view source on GitHub ↗
(aconn, row_factory)

Source from the content-addressed store, hash-verified

362
363@pytest.mark.parametrize("row_factory", ["tuple_row", "dict_row", "namedtuple_row"])
364async def test_standard_row_factory(aconn, row_factory):
365 if row_factory == "tuple_row":
366 getter = lambda r: r[0] # noqa: E731
367 elif row_factory == "dict_row":
368 getter = lambda r: r["bar"] # noqa: E731
369 elif row_factory == "namedtuple_row":
370 getter = lambda r: r.bar # noqa: E731
371 else:
372 assert False, row_factory
373
374 row_factory = getattr(rows, row_factory)
375 async with aconn.cursor("foo", row_factory=row_factory) as cur:
376 await cur.execute("select generate_series(1, 5) as bar")
377 assert getter(await cur.fetchone()) == 1
378 assert list(map(getter, await cur.fetchmany(2))) == [2, 3]
379 assert list(map(getter, await cur.fetchall())) == [4, 5]
380
381
382@pytest.mark.crdb_skip("scroll cursor")

Callers

nothing calls this directly

Calls 5

cursorMethod · 0.45
executeMethod · 0.45
fetchoneMethod · 0.45
fetchmanyMethod · 0.45
fetchallMethod · 0.45

Tested by

no test coverage detected