MCPcopy
hub / github.com/pyodide/pyodide / run

Function run

src/tests/test_database_driver.py:106–202  ·  view source on GitHub ↗
(selenium, host, port, user, password, db)

Source from the content-addressed store, hash-verified

104
105 @run_in_pyodide(packages=["micropip"])
106 async def run(selenium, host, port, user, password, db):
107 import contextlib
108
109 import micropip
110
111 await micropip.install("pymysql==1.1.0")
112
113 import pymysql
114
115 def connect(**kwargs):
116 conn = pymysql.connect(
117 host=host,
118 port=port,
119 user=user,
120 password=password,
121 database=db,
122 unix_socket=False,
123 **kwargs,
124 )
125 return contextlib.closing(conn)
126
127 # 1) Basic DDL/DML
128 with connect(autocommit=True) as conn:
129 with conn.cursor() as cur:
130 cur.execute("DROP TABLE IF EXISTS pyodide_mysql_test")
131 cur.execute(
132 """
133 CREATE TABLE pyodide_mysql_test (
134 id INT PRIMARY KEY AUTO_INCREMENT,
135 name VARCHAR(255) NOT NULL,
136 value INT NOT NULL
137 )
138 """
139 )
140 cur.execute(
141 "INSERT INTO pyodide_mysql_test (name, value) VALUES (%s, %s)",
142 ("alpha", 1),
143 )
144 cur.execute(
145 "INSERT INTO pyodide_mysql_test (name, value) VALUES (%s, %s)",
146 ("beta", 2),
147 )
148 cur.execute(
149 "UPDATE pyodide_mysql_test SET value = value + 10 WHERE name = %s",
150 ("alpha",),
151 )
152 cur.execute("SELECT name, value FROM pyodide_mysql_test ORDER BY id")
153 result = cur.fetchall()
154
155 assert result == (("alpha", 11), ("beta", 2))
156
157 # 2) Transactions + savepoints
158 with connect(autocommit=False) as conn:
159 with conn.cursor() as cur:
160 cur.execute("DROP TABLE IF EXISTS tx_test")
161 cur.execute(
162 "CREATE TABLE tx_test (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50) NOT NULL)"
163 )

Callers 6

test_sqlalchemy_mysqlFunction · 0.70
test_mysql_pymysql_tlsFunction · 0.70
test_sqlalchemy_pg8000Function · 0.70
test_redis_py_featuresFunction · 0.70

Calls 13

UserClass · 0.85
AddressClass · 0.85
installMethod · 0.80
deleteMethod · 0.80
countMethod · 0.80
joinMethod · 0.80
connectMethod · 0.80
setMethod · 0.80
connectFunction · 0.70
closeMethod · 0.45
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected