MCPcopy
hub / github.com/psycopg/psycopg / test_row_factory

Function test_row_factory

tests/test_connection.py:625–649  ·  view source on GitHub ↗
(conn_cls, dsn)

Source from the content-addressed store, hash-verified

623
624
625def test_row_factory(conn_cls, dsn):
626 defaultconn = conn_cls.connect(dsn)
627 assert defaultconn.row_factory is tuple_row
628 defaultconn.close()
629
630 conn = conn_cls.connect(dsn, row_factory=my_row_factory)
631 assert conn.row_factory is my_row_factory
632
633 cur = conn.execute("select 'a' as ve")
634 assert cur.fetchone() == ["Ave"]
635
636 with conn.cursor(row_factory=lambda c: lambda t: set(t)) as cur1:
637 cur1.execute("select 1, 1, 2")
638 assert cur1.fetchall() == [{1, 2}]
639
640 with conn.cursor(row_factory=tuple_row) as cur2:
641 cur2.execute("select 1, 1, 2")
642 assert cur2.fetchall() == [(1, 1, 2)]
643
644 # TODO: maybe fix something to get rid of 'type: ignore' below.
645 conn.row_factory = tuple_row
646 cur3 = conn.execute("select 'vale'")
647 r = cur3.fetchone()
648 assert r and r == ("vale",)
649 conn.close()
650
651
652def test_str(conn):

Callers

nothing calls this directly

Calls 6

connectMethod · 0.45
closeMethod · 0.45
executeMethod · 0.45
fetchoneMethod · 0.45
cursorMethod · 0.45
fetchallMethod · 0.45

Tested by

no test coverage detected