예제 #1
0
    def testRead_MoreThanBuffer(self):
        f = vfs.VfsFile(lambda _: iter([b'foo', b'bar']))

        self.assertEqual(f.read(4), b'foob')
예제 #2
0
    def testRead_AllWithSingleBuffer(self):
        f = vfs.VfsFile(lambda _: iter([b'foo']))

        self.assertEqual(f.read(), b'foo')
예제 #3
0
    def testClose_DoesNotFailOnDoubleClose(self):
        f = vfs.VfsFile(lambda _: iter([]))

        f.close()
        f.close()
예제 #4
0
    def testIsatty(self):
        f = vfs.VfsFile(lambda _: iter([]))

        self.assertFalse(f.isatty())
예제 #5
0
    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')
예제 #6
0
    def testReadinto1_ValueErrorOnFileClosed(self):
        f = vfs.VfsFile(lambda _: iter([]))

        f.close()
        with self.assertRaises(ValueError):
            f.readinto1(bytearray())
예제 #7
0
    def testTruncate_UnsupportedOperation(self):
        f = vfs.VfsFile(lambda _: iter([]))

        with self.assertRaises(io.UnsupportedOperation):
            f.truncate()
예제 #8
0
    def testRead1_ReadCachedAndWholeNextBuffer(self):
        f = vfs.VfsFile(lambda _: iter([b'foo', b'bar', b'quux']))
        f.read(1)

        self.assertEqual(f.read1(), b'oobar')
예제 #9
0
    def testSeek_EndWhenceUnsupportedOperation(self):
        f = vfs.VfsFile(lambda _: iter([]))

        with self.assertRaises(io.UnsupportedOperation):
            f.seek(0, whence=io.SEEK_END)
예제 #10
0
    def testTell_ValueErrorOnFileClosed(self):
        f = vfs.VfsFile(lambda _: iter([]))

        f.close()
        with self.assertRaises(ValueError):
            f.tell()
예제 #11
0
    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')
예제 #12
0
    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')
예제 #13
0
    def testSeekable(self):
        f = vfs.VfsFile(lambda _: iter([]))

        self.assertTrue(f.seekable())
예제 #14
0
    def testRead_AllWithMultipleBuffers(self):
        f = vfs.VfsFile(lambda _: iter([b'foo', b'bar']))

        self.assertEqual(f.read(), b'foobar')
예제 #15
0
    def testWritable(self):
        f = vfs.VfsFile(lambda _: iter([]))

        self.assertFalse(f.writable())
예제 #16
0
    def testRead1_MoreThanBuffer(self):
        f = vfs.VfsFile(lambda _: iter([b'foo', b'bar', b'quux']))

        self.assertEqual(f.read1(5), b'foo')
예제 #17
0
    def testWritelines_UnsupportedOperation(self):
        f = vfs.VfsFile(lambda _: iter([]))

        with self.assertRaises(io.UnsupportedOperation):
            f.writelines([b'foo'])
예제 #18
0
    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'')
예제 #19
0
    def testDetach_UnsupportedOperation(self):
        f = vfs.VfsFile(lambda _: iter([]))

        with self.assertRaises(io.UnsupportedOperation):
            f.detach()
예제 #20
0
    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')
예제 #21
0
    def testReadable(self):
        f = vfs.VfsFile(lambda _: iter([]))

        self.assertTrue(f.readable())
예제 #22
0
    def testClosed_AfterClose(self):
        f = vfs.VfsFile(lambda _: iter([]))
        self.assertFalse(f.closed)

        f.close()
        self.assertTrue(f.closed)
예제 #23
0
    def testRead_LessThanBuffer(self):
        f = vfs.VfsFile(lambda _: iter([b'foo']))

        self.assertEqual(f.read(2), b'fo')
예제 #24
0
    def testFileno_UnsupportedOperation(self):
        f = vfs.VfsFile(lambda _: iter([]))

        with self.assertRaises(io.UnsupportedOperation):
            f.fileno()
예제 #25
0
 def testFlush_DoesNotFail(self):
     f = vfs.VfsFile(lambda _: iter([]))
     f.flush()