| 1 |
import unittest |
| 2 |
from test.support import is_emscripten |
| 3 |
|
| 4 |
if not is_emscripten: |
| 5 |
raise unittest.SkipTest("Emscripten-only test") |
| 6 |
|
| 7 |
from _testinternalcapi import emscripten_set_up_async_input_device |
| 8 |
from pathlib import Path |
| 9 |
|
| 10 |
|
| 11 |
class EmscriptenAsyncInputDeviceTest(unittest.TestCase): |
| 12 |
def test_emscripten_async_input_device(self): |
| 13 |
jspi_supported = emscripten_set_up_async_input_device() |
| 14 |
p = Path("/dev/blah") |
| 15 |
self.addCleanup(p.unlink) |
| 16 |
if not jspi_supported: |
| 17 |
with open(p, "r") as f: |
| 18 |
self.assertRaises(OSError, f.readline) |
| 19 |
return |
| 20 |
|
| 21 |
with open(p, "r") as f: |
| 22 |
for _ in range(10): |
| 23 |
self.assertEqual(f.readline().strip(), "ab") |
| 24 |
self.assertEqual(f.readline().strip(), "fi") |
| 25 |
self.assertEqual(f.readline().strip(), "xy") |