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

Method test_standard_codecs

tests/test_codecs.py:484–558  ·  view source on GitHub ↗

Test encoding/decoding of standard data types and arrays thereof.

(self)

Source from the content-addressed store, hash-verified

482class TestCodecs(tb.ConnectedTestCase):
483
484 async def test_standard_codecs(self):
485 """Test encoding/decoding of standard data types and arrays thereof."""
486 for (typname, intname, sample_data, *metadata) in type_samples:
487 if metadata and self.server_version < metadata[0]:
488 continue
489
490 st = await self.con.prepare(
491 "SELECT $1::" + typname
492 )
493
494 text_in = await self.con.prepare(
495 "SELECT $1::text::" + typname
496 )
497
498 text_out = await self.con.prepare(
499 "SELECT $1::" + typname + "::text"
500 )
501
502 for sample in sample_data:
503 with self.subTest(sample=sample, typname=typname):
504 stmt = st
505 if isinstance(sample, dict):
506 if 'textinput' in sample:
507 inputval = sample['textinput']
508 stmt = text_in
509 else:
510 inputval = sample['input']
511
512 if 'textoutput' in sample:
513 outputval = sample['textoutput']
514 if stmt is text_in:
515 raise ValueError(
516 'cannot test "textin" and'
517 ' "textout" simultaneously')
518 stmt = text_out
519 else:
520 outputval = sample['output']
521
522 if sample.get('query'):
523 stmt = await self.con.prepare(sample['query'])
524 else:
525 inputval = outputval = sample
526
527 result = await stmt.fetchval(inputval)
528 err_msg = (
529 "unexpected result for {} when passing {!r}: "
530 "received {!r}, expected {!r}".format(
531 typname, inputval, result, outputval))
532
533 if typname.startswith('float'):
534 if math.isnan(outputval):
535 if not math.isnan(result):
536 self.fail(err_msg)
537 else:
538 self.assertTrue(
539 math.isclose(result, outputval, rel_tol=1e-6),
540 err_msg)
541 else:

Callers

nothing calls this directly

Calls 4

getMethod · 0.80
get_attributesMethod · 0.80
prepareMethod · 0.45
fetchvalMethod · 0.45

Tested by

no test coverage detected