MCPcopy Index your code
hub / github.com/PyMySQL/mysqlclient / test_fetchall

Method test_fetchall

tests/test_MySQLdb_dbapi20.py:29–81  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

27 some things return empty result sets."""
28
29 def test_fetchall(self):
30 con = self._connect()
31 try:
32 cur = con.cursor()
33 # cursor.fetchall should raise an Error if called
34 # without executing a query that may return rows (such
35 # as a select)
36 self.assertRaises(self.driver.Error, cur.fetchall)
37
38 self.executeDDL1(cur)
39 for sql in self._populate():
40 cur.execute(sql)
41
42 # cursor.fetchall should raise an Error if called
43 # after executing a statement that cannot return rows
44 # self.assertRaises(self.driver.Error,cur.fetchall)
45
46 cur.execute("select name from %sbooze" % self.table_prefix)
47 rows = cur.fetchall()
48 self.assertTrue(cur.rowcount in (-1, len(self.samples)))
49 self.assertEqual(
50 len(rows),
51 len(self.samples),
52 "cursor.fetchall did not retrieve all rows",
53 )
54 rows = [r[0] for r in rows]
55 rows.sort()
56 for i in range(0, len(self.samples)):
57 self.assertEqual(
58 rows[i], self.samples[i], "cursor.fetchall retrieved incorrect rows"
59 )
60 rows = cur.fetchall()
61 self.assertEqual(
62 len(rows),
63 0,
64 "cursor.fetchall should return an empty list if called "
65 "after the whole result set has been fetched",
66 )
67 self.assertTrue(cur.rowcount in (-1, len(self.samples)))
68
69 self.executeDDL2(cur)
70 cur.execute("select name from %sbarflys" % self.table_prefix)
71 rows = cur.fetchall()
72 self.assertTrue(cur.rowcount in (-1, 0))
73 self.assertEqual(
74 len(rows),
75 0,
76 "cursor.fetchall should return an empty list if "
77 "a select query returns no rows",
78 )
79
80 finally:
81 con.close()
82
83 def test_fetchone(self):
84 con = self._connect()

Callers

nothing calls this directly

Calls 8

_connectMethod · 0.80
cursorMethod · 0.80
executeDDL1Method · 0.80
_populateMethod · 0.80
executeMethod · 0.80
executeDDL2Method · 0.80
closeMethod · 0.80
fetchallMethod · 0.45

Tested by

no test coverage detected