| 535 | self.assertEqual(next(iter(r)), 1) |
| 536 | |
| 537 | async def test_record_subclass_06(self): |
| 538 | class MyRecord(asyncpg.Record): |
| 539 | def __init__(self): |
| 540 | raise AssertionError('this is not supposed to be called') |
| 541 | |
| 542 | class MyRecord2(asyncpg.Record): |
| 543 | def __new__(cls): |
| 544 | raise AssertionError('this is not supposed to be called') |
| 545 | |
| 546 | class MyRecordBad: |
| 547 | pass |
| 548 | |
| 549 | with self.assertRaisesRegex( |
| 550 | asyncpg.InterfaceError, |
| 551 | 'record_class must not redefine __new__ or __init__', |
| 552 | ): |
| 553 | await self.con.fetchrow( |
| 554 | "SELECT 1 as a, '2' as b", |
| 555 | record_class=MyRecord, |
| 556 | ) |
| 557 | |
| 558 | with self.assertRaisesRegex( |
| 559 | asyncpg.InterfaceError, |
| 560 | 'record_class must not redefine __new__ or __init__', |
| 561 | ): |
| 562 | await self.con.fetchrow( |
| 563 | "SELECT 1 as a, '2' as b", |
| 564 | record_class=MyRecord2, |
| 565 | ) |
| 566 | |
| 567 | with self.assertRaisesRegex( |
| 568 | asyncpg.InterfaceError, |
| 569 | 'record_class is expected to be a subclass of asyncpg.Record', |
| 570 | ): |
| 571 | await self.con.fetchrow( |
| 572 | "SELECT 1 as a, '2' as b", |
| 573 | record_class=MyRecordBad, |
| 574 | ) |
| 575 | |
| 576 | with self.assertRaisesRegex( |
| 577 | asyncpg.InterfaceError, |
| 578 | 'record_class is expected to be a subclass of asyncpg.Record', |
| 579 | ): |
| 580 | await self.connect(record_class=MyRecordBad) |