MCPcopy
hub / github.com/pyodide/pyodide / test_gen

Function test_gen

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

Source from the content-addressed store, hash-verified

1528
1529@run_in_pyodide
1530def test_gen(selenium):
1531 from pyodide.code import run_js
1532
1533 def g():
1534 n = 0
1535 for _ in range(3):
1536 n = yield n + 2
1537
1538 p = run_js(
1539 """
1540 (g) => {
1541 assert(() => g instanceof pyodide.ffi.PyGenerator);
1542 assert(() => g instanceof pyodide.ffi.PyIterable);
1543 assert(() => g instanceof pyodide.ffi.PyIterator);
1544 assert(() => !(g instanceof pyodide.ffi.PyAsyncGenerator));
1545 let r = [];
1546 r.push(g.next());
1547 r.push(g.next(3));
1548 r.push(g.next(4));
1549 r.push(g.next(5));
1550 return r;
1551 }
1552 """
1553 )(g())
1554
1555 assert p.to_py() == [
1556 {"done": False, "value": 2},
1557 {"done": False, "value": 5},
1558 {"done": False, "value": 6},
1559 {"done": True, "value": None},
1560 ]
1561
1562
1563@run_in_pyodide

Callers

nothing calls this directly

Calls 3

run_jsFunction · 0.90
gFunction · 0.70
to_pyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…