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

Method test_record_subclass_06

tests/test_record.py:547–590  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

fetchrowMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected