MCPcopy
hub / github.com/psycopg/psycopg / test_namedtuple_row

Function test_namedtuple_row

tests/test_rows.py:31–68  ·  view source on GitHub ↗
(conn)

Source from the content-addressed store, hash-verified

29
30
31def test_namedtuple_row(conn):
32 rows._make_nt.cache_clear()
33 cur = conn.cursor(row_factory=rows.namedtuple_row)
34 cur.execute("select 'bob' as name, 3 as id")
35 (person1,) = cur.fetchall()
36 assert f"{person1.name} {person1.id}" == "bob 3"
37
38 ci1 = rows._make_nt.cache_info()
39 assert ci1.hits == 0 and ci1.misses == 1
40
41 cur.execute("select 'alice' as name, 1 as id")
42 (person2,) = cur.fetchall()
43 assert type(person2) is type(person1)
44
45 ci2 = rows._make_nt.cache_info()
46 assert ci2.hits == 1 and ci2.misses == 1
47
48 cur.execute("select 'foo', 1 as id")
49 (r0,) = cur.fetchall()
50 assert r0.f_column_ == "foo"
51 assert r0.id == 1
52
53 cur.execute("select 'a' as letter; select 1 as number")
54 (r1,) = cur.fetchall()
55 assert r1.letter == "a"
56 assert cur.nextset()
57 (r2,) = cur.fetchall()
58 assert r2.number == 1
59 assert not cur.nextset()
60 assert type(r1) is not type(r2)
61
62 cur.execute(f'select 1 as üåäö, 2 as _, 3 as "123", 4 as "a-b", 5 as "{eur}eur"')
63 (r3,) = cur.fetchall()
64 assert r3.üåäö == 1
65 assert r3.f_ == 2
66 assert r3.f123 == 3
67 assert r3.a_b == 4
68 assert r3.f_eur == 5
69
70
71def test_class_row(conn):

Callers

nothing calls this directly

Calls 4

nextsetMethod · 0.80
cursorMethod · 0.45
executeMethod · 0.45
fetchallMethod · 0.45

Tested by

no test coverage detected