Test encoding/decoding using a custom codec on an enum.
(self)
| 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. |
nothing calls this directly
no test coverage detected