-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathtest_nextset.py
84 lines (59 loc) · 1.88 KB
/
test_nextset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import asyncio
import pytest
from pymysql.err import ProgrammingError
@pytest.mark.run_loop
async def test_nextset(cursor):
await cursor.execute("SELECT 1; SELECT 2;")
r = await cursor.fetchall()
assert [(1,)] == list(r)
r = await cursor.nextset()
assert r
r = await cursor.fetchall()
assert [(2,)] == list(r)
res = await cursor.nextset()
assert res is None
@pytest.mark.run_loop
async def test_skip_nextset(cursor):
await cursor.execute("SELECT 1; SELECT 2;")
r = await cursor.fetchall()
assert [(1,)] == list(r)
await cursor.execute("SELECT 42")
r = await cursor.fetchall()
assert [(42,)] == list(r)
@pytest.mark.run_loop
async def test_nextset_error(cursor):
await cursor.execute("SELECT 1; xyzzy;")
# nextset shouldn't hang on error, it should raise syntax error
with pytest.raises(ProgrammingError):
await asyncio.wait_for(cursor.nextset(), 5)
@pytest.mark.run_loop
async def test_ok_and_next(cursor):
await cursor.execute("SELECT 1; commit; SELECT 2;")
r = await cursor.fetchall()
assert [(1,)] == list(r)
res = await cursor.nextset()
assert res
res = await cursor.nextset()
assert res
r = await cursor.fetchall()
assert [(2,)] == list(r)
res = await cursor.nextset()
assert res is None
@pytest.mark.xfail
@pytest.mark.run_loop
async def test_multi_cursorxx(connection):
cur1 = await connection.cursor()
cur2 = await connection.cursor()
await cur1.execute("SELECT 1; SELECT 2;")
await cur2.execute("SELECT 42")
r1 = await cur1.fetchall()
r2 = await cur2.fetchall()
assert [(1,)] == list(r1)
assert [(42,)] == list(r2)
res = await cur1.nextset()
assert res
assert [(2,)] == list(r1)
res = await cur1.nextset()
assert res is None
# TODO: How about SSCursor and nextset?
# It's very hard to implement correctly...