| 199 | |
| 200 | @run_in_pyodide |
| 201 | def 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 |