MCPcopy
hub / github.com/PyMySQL/PyMySQL / test_SSCursor

Method test_SSCursor

pymysql/tests/test_SSCursor.py:9–113  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

7
8class TestSSCursor(base.PyMySQLTestCase):
9 def test_SSCursor(self):
10 affected_rows = 18446744073709551615
11
12 conn = self.connect(client_flag=CLIENT.MULTI_STATEMENTS)
13 data = [
14 ("America", "", "America/Jamaica"),
15 ("America", "", "America/Los_Angeles"),
16 ("America", "", "America/Lima"),
17 ("America", "", "America/New_York"),
18 ("America", "", "America/Menominee"),
19 ("America", "", "America/Havana"),
20 ("America", "", "America/El_Salvador"),
21 ("America", "", "America/Costa_Rica"),
22 ("America", "", "America/Denver"),
23 ("America", "", "America/Detroit"),
24 ]
25
26 cursor = conn.cursor(pymysql.cursors.SSCursor)
27
28 # Create table
29 cursor.execute(
30 "CREATE TABLE tz_data (region VARCHAR(64), zone VARCHAR(64), name VARCHAR(64))"
31 )
32
33 conn.begin()
34 # Test INSERT
35 for i in data:
36 cursor.execute("INSERT INTO tz_data VALUES (%s, %s, %s)", i)
37 self.assertEqual(conn.affected_rows(), 1, "affected_rows does not match")
38 conn.commit()
39
40 # Test fetchone()
41 iter = 0
42 cursor.execute("SELECT * FROM tz_data")
43 while True:
44 row = cursor.fetchone()
45 if row is None:
46 break
47 iter += 1
48
49 # Test cursor.rowcount
50 self.assertEqual(
51 cursor.rowcount,
52 affected_rows,
53 "cursor.rowcount != %s" % (str(affected_rows)),
54 )
55
56 # Test cursor.rownumber
57 self.assertEqual(
58 cursor.rownumber, iter, "cursor.rowcount != %s" % (str(iter))
59 )
60
61 # Test row came out the same as it went in
62 self.assertEqual((row in data), True, "Row not found in source data")
63
64 # Test fetchall
65 cursor.execute("SELECT * FROM tz_data")
66 self.assertEqual(

Callers

nothing calls this directly

Calls 12

cursorMethod · 0.80
executeMethod · 0.80
beginMethod · 0.80
affected_rowsMethod · 0.80
commitMethod · 0.80
executemanyMethod · 0.80
connectMethod · 0.45
fetchoneMethod · 0.45
fetchallMethod · 0.45
fetchmanyMethod · 0.45
nextsetMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected