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

Method test_custom_codec_composite_tuple

tests/test_codecs.py:1593–1618  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1591 await conn.close()
1592
1593 async def test_custom_codec_composite_tuple(self):
1594 await self.con.execute('''
1595 CREATE TYPE mycomplex AS (r float, i float);
1596 ''')
1597
1598 try:
1599 await self.con.set_type_codec(
1600 'mycomplex',
1601 encoder=lambda x: (x.real, x.imag),
1602 decoder=lambda t: complex(t[0], t[1]),
1603 format='tuple',
1604 )
1605
1606 num = complex('1+2j')
1607
1608 res = await self.con.fetchval(
1609 'SELECT $1::mycomplex',
1610 num,
1611 )
1612
1613 self.assertEqual(num, res)
1614
1615 finally:
1616 await self.con.execute('''
1617 DROP TYPE mycomplex;
1618 ''')
1619
1620 async def test_custom_codec_composite_non_tuple(self):
1621 await self.con.execute('''

Callers

nothing calls this directly

Calls 3

set_type_codecMethod · 0.80
executeMethod · 0.45
fetchvalMethod · 0.45

Tested by

no test coverage detected