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

Method test_custom_codec_on_enum

tests/test_codecs.py:1417–1432  ·  view source on GitHub ↗

Test encoding/decoding using a custom codec on an enum.

(self)

Source from the content-addressed store, hash-verified

1415 await self.con.reset_type_codec(t, schema='pg_catalog')
1416
1417 async def test_custom_codec_on_enum(self):
1418 """Test encoding/decoding using a custom codec on an enum."""
1419 await self.con.execute('''
1420 CREATE TYPE custom_codec_t AS ENUM ('foo', 'bar', 'baz')
1421 ''')
1422
1423 try:
1424 await self.con.set_type_codec(
1425 'custom_codec_t',
1426 encoder=lambda v: str(v).lstrip('enum :'),
1427 decoder=lambda v: 'enum: ' + str(v))
1428
1429 v = await self.con.fetchval('SELECT $1::custom_codec_t', 'foo')
1430 self.assertEqual(v, 'enum: foo')
1431 finally:
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.

Callers

nothing calls this directly

Calls 3

set_type_codecMethod · 0.80
executeMethod · 0.45
fetchvalMethod · 0.45

Tested by

no test coverage detected