MCPcopy
hub / github.com/pyodide/pyodide / test_custom_stdin_bytes

Function test_custom_stdin_bytes

src/tests/test_streams.py:201–234  ·  view source on GitHub ↗
(selenium)

Source from the content-addressed store, hash-verified

199
200@run_in_pyodide
201def test_custom_stdin_bytes(selenium):
202 from pyodide.code import run_js
203 from pyodide_js import setStdin
204
205 run_js(
206 """
207 const sg = [
208 0x61,
209 0x62,
210 0x00,
211 null,
212 0x63,
213 0x64,
214 null,
215 0x65,
216 0x66,
217 0x67,
218 ][Symbol.iterator]();
219 function stdin() {
220 return sg.next().value;
221 }
222 pyodide.setStdin({stdin});
223 """
224 )
225 try:
226 import sys
227
228 assert sys.stdin.read(5) == "ab\x00"
229 assert sys.stdin.read(5) == "cd"
230 assert sys.stdin.read(2) == "ef"
231 assert sys.stdin.read(2) == "g"
232 assert sys.stdin.read(2) == ""
233 finally:
234 setStdin()
235
236
237@run_in_pyodide

Callers

nothing calls this directly

Calls 3

run_jsFunction · 0.90
setStdinFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…