MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / test_prepare_03

Method test_prepare_03

tests/test_prepare.py:37–63  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

35 await self.con.prepare('SELECT a')
36
37 async def test_prepare_03(self):
38 cases = [
39 ('text', ("'NULL'", 'NULL'), [
40 'aaa',
41 None
42 ]),
43
44 ('decimal', ('0', 0), [
45 123,
46 123.5,
47 None
48 ])
49 ]
50
51 for type, (none_name, none_val), vals in cases:
52 st = await self.con.prepare('''
53 SELECT CASE WHEN $1::{type} IS NULL THEN {default}
54 ELSE $1::{type} END'''.format(
55 type=type, default=none_name))
56
57 for val in vals:
58 with self.subTest(type=type, value=val):
59 res = await st.fetchval(val)
60 if val is None:
61 self.assertEqual(res, none_val)
62 else:
63 self.assertEqual(res, val)
64
65 async def test_prepare_04(self):
66 s = await self.con.prepare('SELECT $1::smallint')

Callers

nothing calls this directly

Calls 2

prepareMethod · 0.45
fetchvalMethod · 0.45

Tested by

no test coverage detected