Пример #1
0
 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'))
Пример #2
0
    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)
Пример #3
0
 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()
Пример #4
0
    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)
Пример #5
0
 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)
Пример #6
0
 def test_iobase_ctor_accepts_anything(self):
     _io._IOBase()
     _io._IOBase(1, '2', kw=3)
Пример #7
0
 def test_writelines_err(self):
     self.assertRaises(AttributeError,
                       _io._IOBase().writelines, ['aaa', 'bbb'])
Пример #8
0
 def test_iter(self):
     x = _io._IOBase()
     self.assertIs(x, x.__iter__())
     x.close()
     self.assertRaises(ValueError, x.__iter__)
Пример #9
0
 def test_isatty(self):
     x = _io._IOBase()
     self.assertFalse(x.isatty())
     x.close()
     self.assertRaises(ValueError, x.isatty)
Пример #10
0
 def test_exit_accepts_varargs(self):
     x = _io._IOBase()
     x.__exit__(1, 2, 3)
     with self.assertRaises(TypeError):
         x.__exit__(kw=1)
Пример #11
0
 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)
Пример #12
0
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: