Skip to content

Commit 5096b3e

Browse files
committed
Add test for cursor rowcount
1 parent 980bbc5 commit 5096b3e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/client/test_cursor.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@ def test_cursor_description(mocked_connection):
7979

8080
assert cursor.description is None
8181

82+
83+
def test_cursor_rowcount(mocked_connection):
84+
""" Verify the logic of cursor.rowcount"""
85+
cursor = mocked_connection.cursor()
86+
response = {
87+
"col_types": [4, 5],
88+
"cols": ["name", "address"],
89+
"rows": [["foo", "10.10.10.1"], ["bar", "10.10.10.2"]],
90+
"rowcount": 2,
91+
"duration": 123,
92+
}
93+
with mock.patch.object(
94+
mocked_connection.client, "sql", return_value=response
95+
):
96+
cursor.execute("")
97+
assert cursor.rowcount == len(response["rows"])
98+
99+
cursor._result = None
100+
assert cursor.rowcount == -1
101+
102+
cursor.execute("")
103+
cursor._result = {}
104+
assert cursor.rowcount == -1
105+
106+
cursor.execute("")
107+
cursor.close()
108+
assert cursor.rowcount == -1
109+
110+
111+
82112
def test_cursor_executemany(mocked_connection):
83113
"""
84114
Verify executemany.

0 commit comments

Comments
 (0)