MCPcopy
hub / github.com/psycopg/psycopg / test_fetchmany

Method test_fetchmany

tests/dbapi20.py:556–636  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

554 return populate
555
556 def test_fetchmany(self):
557 con = self._connect()
558 try:
559 cur = con.cursor()
560
561 # cursor.fetchmany should raise an Error if called without
562 #issuing a query
563 self.assertRaises(self.driver.Error,cur.fetchmany,4)
564
565 self.executeDDL1(cur)
566 for sql in self._populate():
567 cur.execute(sql)
568
569 cur.execute('select name from %sbooze' % self.table_prefix)
570 r = cur.fetchmany()
571 self.assertEqual(len(r),1,
572 'cursor.fetchmany retrieved incorrect number of rows, '
573 'default of arraysize is one.'
574 )
575 cur.arraysize=10
576 r = cur.fetchmany(3) # Should get 3 rows
577 self.assertEqual(len(r),3,
578 'cursor.fetchmany retrieved incorrect number of rows'
579 )
580 r = cur.fetchmany(4) # Should get 2 more
581 self.assertEqual(len(r),2,
582 'cursor.fetchmany retrieved incorrect number of rows'
583 )
584 r = cur.fetchmany(4) # Should be an empty sequence
585 self.assertEqual(len(r),0,
586 'cursor.fetchmany should return an empty sequence after '
587 'results are exhausted'
588 )
589 self.assertTrue(cur.rowcount in (-1,6))
590
591 # Same as above, using cursor.arraysize
592 cur.arraysize=4
593 cur.execute('select name from %sbooze' % self.table_prefix)
594 r = cur.fetchmany() # Should get 4 rows
595 self.assertEqual(len(r),4,
596 'cursor.arraysize not being honoured by fetchmany'
597 )
598 r = cur.fetchmany() # Should get 2 more
599 self.assertEqual(len(r),2)
600 r = cur.fetchmany() # Should be an empty sequence
601 self.assertEqual(len(r),0)
602 self.assertTrue(cur.rowcount in (-1,6))
603
604 cur.arraysize=6
605 cur.execute('select name from %sbooze' % self.table_prefix)
606 rows = cur.fetchmany() # Should get all rows
607 self.assertTrue(cur.rowcount in (-1,6))
608 self.assertEqual(len(rows),6)
609 self.assertEqual(len(rows),6)
610 rows = [r[0] for r in rows]
611 rows.sort()
612
613 # Make sure we get the right data back out

Callers

nothing calls this directly

Calls 8

_connectMethod · 0.95
executeDDL1Method · 0.95
_populateMethod · 0.95
executeDDL2Method · 0.95
cursorMethod · 0.45
executeMethod · 0.45
fetchmanyMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected