| 685 | ''') |
| 686 | |
| 687 | async def test_invalid_input(self): |
| 688 | # The latter message appears beginning in Python 3.10. |
| 689 | integer_required = ( |
| 690 | r"(an integer is required|" |
| 691 | r"\('str' object cannot be interpreted as an integer\))") |
| 692 | |
| 693 | cases = [ |
| 694 | ('bytea', 'a bytes-like object is required', [ |
| 695 | 1, |
| 696 | 'aaa' |
| 697 | ]), |
| 698 | ('bool', 'a boolean is required', [ |
| 699 | 1, |
| 700 | ]), |
| 701 | ('int2', integer_required, [ |
| 702 | '2', |
| 703 | 'aa', |
| 704 | ]), |
| 705 | ('smallint', 'value out of int16 range', [ |
| 706 | 2**256, # check for the same exception for any big numbers |
| 707 | decimal.Decimal("2000000000000000000000000000000"), |
| 708 | 0xffff, |
| 709 | 0xffffffff, |
| 710 | 32768, |
| 711 | -32769 |
| 712 | ]), |
| 713 | ('float4', 'value out of float32 range', [ |
| 714 | 4.1 * 10 ** 40, |
| 715 | -4.1 * 10 ** 40, |
| 716 | ]), |
| 717 | ('int4', integer_required, [ |
| 718 | '2', |
| 719 | 'aa', |
| 720 | ]), |
| 721 | ('int', 'value out of int32 range', [ |
| 722 | 2**256, # check for the same exception for any big numbers |
| 723 | decimal.Decimal("2000000000000000000000000000000"), |
| 724 | 0xffffffff, |
| 725 | 2**31, |
| 726 | -2**31 - 1, |
| 727 | ]), |
| 728 | ('int8', integer_required, [ |
| 729 | '2', |
| 730 | 'aa', |
| 731 | ]), |
| 732 | ('bigint', 'value out of int64 range', [ |
| 733 | 2**256, # check for the same exception for any big numbers |
| 734 | decimal.Decimal("2000000000000000000000000000000"), |
| 735 | 0xffffffffffffffff, |
| 736 | 2**63, |
| 737 | -2**63 - 1, |
| 738 | ]), |
| 739 | ('text', 'expected str, got bytes', [ |
| 740 | b'foo' |
| 741 | ]), |
| 742 | ('text', 'expected str, got list', [ |
| 743 | [1] |
| 744 | ]), |