MCPcopy
hub / github.com/MagicStack/asyncpg / test_custom_codec_on_enum

Method test_custom_codec_on_enum

tests/test_codecs.py:1371–1386  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

1369 await self.con.reset_type_codec(t, schema='pg_catalog')
1370
1371 async def test_custom_codec_on_enum(self):
1372 """Test encoding/decoding using a custom codec on an enum."""
1373 await self.con.execute('''
1374 CREATE TYPE custom_codec_t AS ENUM ('foo', 'bar', 'baz')
1375 ''')
1376
1377 try:
1378 await self.con.set_type_codec(
1379 'custom_codec_t',
1380 encoder=lambda v: str(v).lstrip('enum :'),
1381 decoder=lambda v: 'enum: ' + str(v))
1382
1383 v = await self.con.fetchval('SELECT $1::custom_codec_t', 'foo')
1384 self.assertEqual(v, 'enum: foo')
1385 finally:
1386 await self.con.execute('DROP TYPE custom_codec_t')
1387
1388 async def test_custom_codec_on_enum_array(self):
1389 """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