MCPcopy Index your code
hub / github.com/davispuh/MySQL-for-Python-3 / test_fetchmany

Method test_fetchmany

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

Source from the content-addressed store, hash-verified

538 return populate
539
540 def test_fetchmany(self):
541 con = self._connect()
542 try:
543 cur = con.cursor()
544
545 # cursor.fetchmany should raise an Error if called without
546 #issuing a query
547 self.assertRaises(self.driver.Error,cur.fetchmany,4)
548
549 self.executeDDL1(cur)
550 for sql in self._populate():
551 cur.execute(sql)
552
553 cur.execute('select name from %sbooze' % self.table_prefix)
554 r = cur.fetchmany()
555 self.assertEqual(len(r),1,
556 'cursor.fetchmany retrieved incorrect number of rows, '
557 'default of arraysize is one.'
558 )
559 cur.arraysize=10
560 r = cur.fetchmany(3) # Should get 3 rows
561 self.assertEqual(len(r),3,
562 'cursor.fetchmany retrieved incorrect number of rows'
563 )
564 r = cur.fetchmany(4) # Should get 2 more
565 self.assertEqual(len(r),2,
566 'cursor.fetchmany retrieved incorrect number of rows'
567 )
568 r = cur.fetchmany(4) # Should be an empty sequence
569 self.assertEqual(len(r),0,
570 'cursor.fetchmany should return an empty sequence after '
571 'results are exhausted'
572 )
573 self.assertTrue(cur.rowcount in (-1,6))
574
575 # Same as above, using cursor.arraysize
576 cur.arraysize=4
577 cur.execute('select name from %sbooze' % self.table_prefix)
578 r = cur.fetchmany() # Should get 4 rows
579 self.assertEqual(len(r),4,
580 'cursor.arraysize not being honoured by fetchmany'
581 )
582 r = cur.fetchmany() # Should get 2 more
583 self.assertEqual(len(r),2)
584 r = cur.fetchmany() # Should be an empty sequence
585 self.assertEqual(len(r),0)
586 self.assertTrue(cur.rowcount in (-1,6))
587
588 cur.arraysize=6
589 cur.execute('select name from %sbooze' % self.table_prefix)
590 rows = cur.fetchmany() # Should get all rows
591 self.assertTrue(cur.rowcount in (-1,6))
592 self.assertEqual(len(rows),6)
593 self.assertEqual(len(rows),6)
594 rows = [r[0] for r in rows]
595 rows.sort()
596
597 # 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.80
executeMethod · 0.80
closeMethod · 0.80
fetchmanyMethod · 0.45

Tested by

no test coverage detected