def testRead_MoreThanBuffer(self): f = vfs.VfsFile(lambda _: iter([b'foo', b'bar'])) self.assertEqual(f.read(4), b'foob')
def testRead_AllWithSingleBuffer(self): f = vfs.VfsFile(lambda _: iter([b'foo'])) self.assertEqual(f.read(), b'foo')
def testClose_DoesNotFailOnDoubleClose(self): f = vfs.VfsFile(lambda _: iter([])) f.close() f.close()
def testIsatty(self): f = vfs.VfsFile(lambda _: iter([])) self.assertFalse(f.isatty())
def testReadinto1_LessThanBuffer(self): f = vfs.VfsFile(lambda _: iter([b'foo', b'bar', b'quux'])) b = bytearray(2) self.assertEqual(f.readinto1(b), 2) self.assertEqual(b, b'fo')
def testReadinto1_ValueErrorOnFileClosed(self): f = vfs.VfsFile(lambda _: iter([])) f.close() with self.assertRaises(ValueError): f.readinto1(bytearray())
def testTruncate_UnsupportedOperation(self): f = vfs.VfsFile(lambda _: iter([])) with self.assertRaises(io.UnsupportedOperation): f.truncate()
def testRead1_ReadCachedAndWholeNextBuffer(self): f = vfs.VfsFile(lambda _: iter([b'foo', b'bar', b'quux'])) f.read(1) self.assertEqual(f.read1(), b'oobar')
def testSeek_EndWhenceUnsupportedOperation(self): f = vfs.VfsFile(lambda _: iter([])) with self.assertRaises(io.UnsupportedOperation): f.seek(0, whence=io.SEEK_END)
def testTell_ValueErrorOnFileClosed(self): f = vfs.VfsFile(lambda _: iter([])) f.close() with self.assertRaises(ValueError): f.tell()
def testSeek_CurWhence(self): f = vfs.VfsFile(lambda _: iter([b'foobar'])) f.read(5) self.assertEqual(f.seek(-2, whence=io.SEEK_CUR), 3) self.assertEqual(f.read(), b'bar')
def testSeek_SetWhence(self): f = vfs.VfsFile(lambda _: iter([b'foobar'])) f.read(5) self.assertEqual(f.seek(2), 2) self.assertEqual(f.read(), b'obar')
def testSeekable(self): f = vfs.VfsFile(lambda _: iter([])) self.assertTrue(f.seekable())
def testRead_AllWithMultipleBuffers(self): f = vfs.VfsFile(lambda _: iter([b'foo', b'bar'])) self.assertEqual(f.read(), b'foobar')
def testWritable(self): f = vfs.VfsFile(lambda _: iter([])) self.assertFalse(f.writable())
def testRead1_MoreThanBuffer(self): f = vfs.VfsFile(lambda _: iter([b'foo', b'bar', b'quux'])) self.assertEqual(f.read1(5), b'foo')
def testWritelines_UnsupportedOperation(self): f = vfs.VfsFile(lambda _: iter([])) with self.assertRaises(io.UnsupportedOperation): f.writelines([b'foo'])
def testRead1_EmptyOnEof(self): f = vfs.VfsFile(lambda _: iter([b'foo'])) self.assertEqual(f.read1(), b'foo') self.assertEqual(f.read1(), b'') self.assertEqual(f.read1(), b'')
def testDetach_UnsupportedOperation(self): f = vfs.VfsFile(lambda _: iter([])) with self.assertRaises(io.UnsupportedOperation): f.detach()
def testReadinto1_MoreThanBuffer(self): f = vfs.VfsFile(lambda _: iter([b'foo', b'bar', b'quux'])) b = bytearray(5) self.assertEqual(f.readinto1(b), 3) self.assertEqual(b[:3], b'foo')
def testReadable(self): f = vfs.VfsFile(lambda _: iter([])) self.assertTrue(f.readable())
def testClosed_AfterClose(self): f = vfs.VfsFile(lambda _: iter([])) self.assertFalse(f.closed) f.close() self.assertTrue(f.closed)
def testRead_LessThanBuffer(self): f = vfs.VfsFile(lambda _: iter([b'foo'])) self.assertEqual(f.read(2), b'fo')
def testFileno_UnsupportedOperation(self): f = vfs.VfsFile(lambda _: iter([])) with self.assertRaises(io.UnsupportedOperation): f.fileno()
def testFlush_DoesNotFail(self): f = vfs.VfsFile(lambda _: iter([])) f.flush()