Test encoding/decoding of standard data types and arrays thereof.
(self)
| 482 | class 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: |
nothing calls this directly
no test coverage detected