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

Method test_fetchall

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

Source from the content-addressed store, hash-verified

620 con.close()
621
622 def test_fetchall(self):
623 con = self._connect()
624 try:
625 cur = con.cursor()
626 # cursor.fetchall should raise an Error if called
627 # without executing a query that may return rows (such
628 # as a select)
629 self.assertRaises(self.driver.Error, cur.fetchall)
630
631 self.executeDDL1(cur)
632 for sql in self._populate():
633 cur.execute(sql)
634
635 # cursor.fetchall should raise an Error if called
636 # after executing a a statement that cannot return rows
637 self.assertRaises(self.driver.Error,cur.fetchall)
638
639 cur.execute('select name from %sbooze' % self.table_prefix)
640 rows = cur.fetchall()
641 self.assertTrue(cur.rowcount in (-1,len(self.samples)))
642 self.assertEqual(len(rows),len(self.samples),
643 'cursor.fetchall did not retrieve all rows'
644 )
645 rows = [r[0] for r in rows]
646 rows.sort()
647 for i in range(0,len(self.samples)):
648 self.assertEqual(rows[i],self.samples[i],
649 'cursor.fetchall retrieved incorrect rows'
650 )
651 rows = cur.fetchall()
652 self.assertEqual(
653 len(rows),0,
654 'cursor.fetchall should return an empty list if called '
655 'after the whole result set has been fetched'
656 )
657 self.assertTrue(cur.rowcount in (-1,len(self.samples)))
658
659 self.executeDDL2(cur)
660 cur.execute('select name from %sbarflys' % self.table_prefix)
661 rows = cur.fetchall()
662 self.assertTrue(cur.rowcount in (-1,0))
663 self.assertEqual(len(rows),0,
664 'cursor.fetchall should return an empty list if '
665 'a select query returns no rows'
666 )
667
668 finally:
669 con.close()
670
671 def test_mixedfetch(self):
672 con = self._connect()

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
fetchallMethod · 0.45

Tested by

no test coverage detected