Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 520a2da

Browse files
committed
Python: Add tests for asyncpg
1 parent cb0a567 commit 520a2da

4 files changed

Lines changed: 125 additions & 0 deletions

File tree

python/ql/test/library-tests/frameworks/asyncpg/ConceptsTest.expected

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.meta.ConceptsTest
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import asyncio
2+
import asyncpg
3+
4+
async def test_connection():
5+
conn = await asyncpg.connect()
6+
7+
try:
8+
# The file-like object is passed in as a keyword-only argument.
9+
# See https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.connection.Connection.copy_from_query
10+
await conn.copy_from_query("sql", output="filepath") # $ MISSING: getAPathArgument="filepath" getSql="sql"
11+
await conn.copy_from_query("sql", "arg1", "arg2", output="filepath") # $ MISSING: getAPathArgument="filepath" getSql="sql"
12+
13+
await conn.copy_from_table("table", output="filepath") # $ MISSING: getAPathArgument="filepath"
14+
await conn.copy_to_table("table", source="filepath") # $ MISSING: getAPathArgument="filepath"
15+
16+
finally:
17+
await conn.close()
18+
19+
async def test_connection_pool():
20+
pool = await asyncpg.create_pool()
21+
22+
try:
23+
await pool.copy_from_query("sql", output="filepath") # $ MISSING: getAPathArgument="filepath"
24+
await pool.copy_from_query("sql", "arg1", "arg2", output="filepath") # $ MISSING: getAPathArgument="filepath"
25+
await pool.copy_from_table("table", output="filepath") # $ MISSING: getAPathArgument="filepath"
26+
await pool.copy_to_table("table", source="filepath") # $ MISSING: getAPathArgument="filepath"
27+
28+
finally:
29+
await pool.close()
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import asyncio
2+
import asyncpg
3+
4+
async def test_connection():
5+
conn = await asyncpg.connect()
6+
7+
try:
8+
await conn.copy_from_query("sql", output="filepath") # $ MISSING: getSql="sql" getAPathArgument="filepath"
9+
await conn.execute("sql") # $ MISSING: getSql="sql"
10+
await conn.executemany("sql") # $ MISSING: getSql="sql"
11+
await conn.fetch("sql") # $ MISSING: getSql="sql"
12+
await conn.fetchrow("sql") # $ MISSING: getSql="sql"
13+
await conn.fetchval("sql") # $ MISSING: getSql="sql"
14+
15+
finally:
16+
await conn.close()
17+
18+
19+
async def test_prepared_statement():
20+
conn = await asyncpg.connect()
21+
22+
try:
23+
pstmt = await conn.prepare('psql')
24+
pstmt.executemany() # $ MISSING: getSql="psql"
25+
pstmt.fetch() # $ MISSING: getSql="psql"
26+
pstmt.fetchrow() # $ MISSING: getSql="psql"
27+
pstmt.fetchval() # $ MISSING: getSql="psql"
28+
29+
finally:
30+
await conn.close()
31+
32+
# The sql statement is executed when the `CursorFactory` (obtained by e.g. `conn.cursor()`) is awaited.
33+
# See https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.cursor.CursorFactory
34+
async def test_cursor():
35+
conn = await asyncpg.connect()
36+
37+
try:
38+
async with conn.transaction():
39+
cursor = await conn.cursor("sql") # $ MISSING: getSql="sql"
40+
await cursor.fetch()
41+
42+
pstmt = await conn.prepare('psql')
43+
pcursor = await pstmt.cursor() # $ MISSING: getSql="psql"
44+
await pcursor.fetch()
45+
46+
async for record in conn.cursor("sql"): # $ MISSING: getSql="sql"
47+
pass
48+
49+
async for record in pstmt.cursor(): # $ MISSING: getSql="psql"
50+
pass
51+
52+
cursor_factory = conn.cursor("sql")
53+
cursor = await cursor_factory # $ MISSING: getSql="sql"
54+
55+
pcursor_factory = pstmt.cursor()
56+
pcursor = await pcursor_factory # $ MISSING: getSql="psql"
57+
58+
finally:
59+
await conn.close()
60+
61+
async def test_connection_pool():
62+
pool = await asyncpg.create_pool()
63+
64+
try:
65+
await pool.copy_from_query("sql", output="filepath") # $ MISSING: getSql="sql" getAPathArgument="filepath"
66+
await pool.execute("sql") # $ MISSING: getSql="sql"
67+
await pool.executemany("sql") # $ MISSING: getSql="sql"
68+
await pool.fetch("sql") # $ MISSING: getSql="sql"
69+
await pool.fetchrow("sql") # $ MISSING: getSql="sql"
70+
await pool.fetchval("sql") # $ MISSING: getSql="sql"
71+
72+
async with pool.acquire() as conn:
73+
await conn.execute("sql") # $ MISSING: getSql="sql"
74+
75+
conn = await pool.acquire()
76+
try:
77+
await conn.fetch("sql") # $ MISSING: getSql="sql"
78+
finally:
79+
await pool.release(conn)
80+
81+
finally:
82+
await pool.close()
83+
84+
async with asyncpg.create_pool() as pool:
85+
await pool.execute("sql") # $ MISSING: getSql="sql"
86+
87+
async with pool.acquire() as conn:
88+
await conn.execute("sql") # $ MISSING: getSql="sql"
89+
90+
conn = await pool.acquire()
91+
try:
92+
await conn.fetch("sql") # $ MISSING: getSql="sql"
93+
finally:
94+
await pool.release(conn)

0 commit comments

Comments
 (0)