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

Method test_custom_codec_override_binary

tests/test_codecs.py:1462–1484  ·  view source on GitHub ↗

Test overriding core codecs.

(self)

Source from the content-addressed store, hash-verified

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."""
1464 import json
1465
1466 conn = await self.connect()
1467 try:
1468 def _encoder(value):
1469 return json.dumps(value).encode('utf-8')
1470
1471 def _decoder(value):
1472 return json.loads(value.decode('utf-8'))
1473
1474 await conn.set_type_codec(
1475 'json', encoder=_encoder, decoder=_decoder,
1476 schema='pg_catalog', format='binary'
1477 )
1478
1479 data = {'foo': 'bar', 'spam': 1}
1480 res = await conn.fetchval('SELECT $1::json', data)
1481 self.assertEqual(data, res)
1482
1483 finally:
1484 await conn.close()
1485
1486 async def test_custom_codec_override_text(self):
1487 """Test overriding core codecs."""

Callers

nothing calls this directly

Calls 4

set_type_codecMethod · 0.80
connectMethod · 0.45
fetchvalMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected