| 623 | |
| 624 | |
| 625 | def 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 | |
| 652 | def test_str(conn): |