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