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

Method test_custom_codec_on_enum_array

tests/test_codecs.py:1434–1460  ·  view source on GitHub ↗

Test encoding/decoding using a custom codec on an enum array. Bug: https://github.com/MagicStack/asyncpg/issues/590

(self)

Source from the content-addressed store, hash-verified

1432 await self.con.execute('DROP TYPE custom_codec_t')
1433
1434 async def test_custom_codec_on_enum_array(self):
1435 """Test encoding/decoding using a custom codec on an enum array.
1436
1437 Bug: https://github.com/MagicStack/asyncpg/issues/590
1438 """
1439 await self.con.execute('''
1440 CREATE TYPE custom_codec_t AS ENUM ('foo', 'bar', 'baz')
1441 ''')
1442
1443 try:
1444 await self.con.set_type_codec(
1445 'custom_codec_t',
1446 encoder=lambda v: str(v).lstrip('enum :'),
1447 decoder=lambda v: 'enum: ' + str(v))
1448
1449 v = await self.con.fetchval(
1450 "SELECT ARRAY['foo', 'bar']::custom_codec_t[]")
1451 self.assertEqual(v, ['enum: foo', 'enum: bar'])
1452
1453 v = await self.con.fetchval(
1454 'SELECT ARRAY[$1]::custom_codec_t[]', 'foo')
1455 self.assertEqual(v, ['enum: foo'])
1456
1457 v = await self.con.fetchval("SELECT 'foo'::custom_codec_t")
1458 self.assertEqual(v, 'enum: foo')
1459 finally:
1460 await self.con.execute('DROP TYPE custom_codec_t')
1461
1462 async def test_custom_codec_override_binary(self):
1463 """Test overriding core codecs."""

Callers

nothing calls this directly

Calls 3

set_type_codecMethod · 0.80
executeMethod · 0.45
fetchvalMethod · 0.45

Tested by

no test coverage detected