import os, io, fcntl, unittest class TestBlockingIOError(unittest.TestCase): def _make_files(self): r, w = os.pipe() fcntl.fcntl(r, fcntl.F_SETFL, os.O_NDELAY) fcntl.fcntl(w, fcntl.F_SETFL, os.O_NDELAY) rf = io.open(r, mode='rb', closefd=True) wf = io.open(w, mode='wb', closefd=True) return rf, wf def test_read(self): rf, wf = self._make_files() with self.assertRaises(io.BlockingIOError): rf.read(1) def test_write(self): rf, wf = self._make_files() msg = b'X'*10000 with self.assertRaises(io.BlockingIOError): while 1: wf.write(msg) if __name__ == '__main__': unittest.main()