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

Method test_custom_codec_composite_tuple

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

Source from the content-addressed store, hash-verified

1545 await conn.close()
1546
1547 async def test_custom_codec_composite_tuple(self):
1548 await self.con.execute('''
1549 CREATE TYPE mycomplex AS (r float, i float);
1550 ''')
1551
1552 try:
1553 await self.con.set_type_codec(
1554 'mycomplex',
1555 encoder=lambda x: (x.real, x.imag),
1556 decoder=lambda t: complex(t[0], t[1]),
1557 format='tuple',
1558 )
1559
1560 num = complex('1+2j')
1561
1562 res = await self.con.fetchval(
1563 'SELECT $1::mycomplex',
1564 num,
1565 )
1566
1567 self.assertEqual(num, res)
1568
1569 finally:
1570 await self.con.execute('''
1571 DROP TYPE mycomplex;
1572 ''')
1573
1574 async def test_custom_codec_composite_non_tuple(self):
1575 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