def test_close(self): x = _io._IOBase() self.assertFalse(x.closed) self.assertFalse('__IOBase_closed' in dir(x)) x.close() self.assertTrue(x.closed) self.assertEqual(True, getattr(x, '__IOBase_closed'))
def test_default_implementations(self): import _io file = _io._IOBase() raises(_io.UnsupportedOperation, file.seek, 0, 1) raises(_io.UnsupportedOperation, file.fileno) raises(_io.UnsupportedOperation, file.truncate)
def test_flush(self): x = _io._IOBase() x.flush() x.close() self.assertRaises(ValueError, x.flush) # the value of __IOBase_closed does not matter, only its presence setattr(x, '__IOBase_closed', False) self.assertRaises(ValueError, x.flush) delattr(x, '__IOBase_closed') x.flush()
def test_check_writable(self): self.assertFalse(_io._IOBase().writable()) ret_val = False class X(_io._IOBase): def writable(self): return ret_val self.assertRaises(_io.UnsupportedOperation, X()._checkWritable) ret_val = True self.assertTrue(X()._checkWritable()) ret_val = 42 # _checkWritable accepts only explicit True self.assertRaises(_io.UnsupportedOperation, X()._checkWritable) ret_val = (1, ) self.assertRaises(_io.UnsupportedOperation, X()._checkWritable)
def test_iobase_ctor_accepts_anything(self): _io._IOBase() _io._IOBase(1, '2', kw=3)
def test_writelines_err(self): self.assertRaises(AttributeError, _io._IOBase().writelines, ['aaa', 'bbb'])
def test_iter(self): x = _io._IOBase() self.assertIs(x, x.__iter__()) x.close() self.assertRaises(ValueError, x.__iter__)
def test_isatty(self): x = _io._IOBase() self.assertFalse(x.isatty()) x.close() self.assertRaises(ValueError, x.isatty)
def test_exit_accepts_varargs(self): x = _io._IOBase() x.__exit__(1, 2, 3) with self.assertRaises(TypeError): x.__exit__(kw=1)
def test_unsupported(self): self.assertRaises(_io.UnsupportedOperation, _io._IOBase().seek) self.assertRaises(_io.UnsupportedOperation, _io._IOBase().truncate) self.assertRaises(_io.UnsupportedOperation, _io._IOBase().fileno)
import _io i = _io._IOBase() i.close() try: i.fileno() except _io.UnsupportedOperation: try: i.readline(1) except AttributeError: try: i.readlines(0) except ValueError: try: i.seek() except _io.UnsupportedOperation: try: i.tell() except _io.UnsupportedOperation: try: i.truncate() except _io.UnsupportedOperation: try: i.writelines([]) except ValueError: try: i.write() except AttributeError: try: i.read() except AttributeError: try: