MCPcopy
hub / github.com/pyodide/pyodide / test_pyproxy_iter

Function test_pyproxy_iter

src/tests/test_pyproxy.py:211–265  ·  view source on GitHub ↗
(selenium)

Source from the content-addressed store, hash-verified

209
210@run_in_pyodide
211def test_pyproxy_iter(selenium):
212 from collections import ChainMap
213
214 from pyodide.code import run_js
215
216 def test_generator():
217 yield from range(10)
218
219 c = test_generator()
220 ty, l = run_js("(c) => [c.type, [...c]]")(c)
221 assert ty == "generator"
222 assert l.to_py() == list(range(10))
223
224 c = ChainMap({"a": 2, "b": 3})
225 ty, l = run_js("(c) => [c.type, [...c]]")(c)
226 assert ty == "ChainMap"
227 assert set(l) == {"a", "b"}
228
229 def test_generator2():
230 acc = 0
231 for i in range(10):
232 r = yield acc
233 acc += i * r
234
235 c = test_generator2()
236
237 result, result2 = run_js(
238 """
239 (c) => {
240 let {done, value} = c.next();
241 let result = [];
242 while(!done){
243 result.push(value);
244 ({done, value} = c.next(value + 1));
245 }
246
247 function* test(){
248 let acc = 0;
249 for(let i=0; i < 10; i++){
250 let r = yield acc;
251 acc += i * r;
252 }
253 }
254 c = test();
255 ({done, value} = c.next());
256 let result2 = [];
257 while(!done){
258 result2.push(value);
259 ({done, value} = c.next(value + 1));
260 }
261 return [result, result2];
262 }
263 """
264 )(c)
265 assert result.to_py() == result2.to_py()
266
267
268@run_in_pyodide

Callers

nothing calls this directly

Calls 6

run_jsFunction · 0.90
test_generatorFunction · 0.85
ChainMapClass · 0.85
setFunction · 0.85
test_generator2Function · 0.85
to_pyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…