Exemplo n.º 1
0
    def test_write_read(self):
        ctx = t.Ctx()
        vfs = t.VFS(ctx)

        buffer = b"bar"
        fh = vfs.open(self.path("foo"), "w")
        vfs.write(fh, buffer)
        vfs.close(fh)
        self.assertEqual(vfs.file_size(self.path("foo")), 3)

        fh = vfs.open(self.path("foo"), "r")
        self.assertEqual(vfs.read(fh, 0, 3), buffer)
        vfs.close(fh)

        # write / read empty input
        fh = vfs.open(self.path("baz"), "w")
        vfs.write(fh, b"")
        vfs.close(fh)
        self.assertEqual(vfs.file_size(self.path("baz")), 0)

        fh = vfs.open(self.path("baz"), "r")
        self.assertEqual(vfs.read(fh, 0, 0), b"")
        vfs.close(fh)

        # read from file that does not exist
        with self.assertRaises(t.TileDBError):
            vfs.open(self.path("do_not_exist"), "r")
Exemplo n.º 2
0
    def test_supports(self):
        ctx = t.Ctx()
        vfs = t.VFS(ctx)

        self.assertTrue(vfs.supports("file"))
        self.assertIsInstance(vfs.supports("s3"), bool)
        self.assertIsInstance(vfs.supports("hdfs"), bool)

        with self.assertRaises(ValueError):
            vfs.supports("invalid")
Exemplo n.º 3
0
    def test_io(self):
        ctx = t.Ctx()
        vfs = t.VFS(ctx)

        buffer = b"0123456789"
        io = t.FileIO(vfs, self.path("foo"), mode="w")
        io.write(buffer)
        io.flush()
        self.assertEqual(io.tell(), len(buffer))

        io = t.FileIO(vfs, self.path("foo"), mode="r")
        with self.assertRaises(IOError):
            io.write(b"foo")

        self.assertEqual(vfs.file_size(self.path("foo")), len(buffer))

        io = t.FileIO(vfs, self.path("foo"), mode='r')
        self.assertEqual(io.read(3), b'012')
        self.assertEqual(io.tell(), 3)
        self.assertEqual(io.read(3), b'345')
        self.assertEqual(io.tell(), 6)
        self.assertEqual(io.read(10), b'6789')
        self.assertEqual(io.tell(), 10)

        # seek from beginning
        io.seek(0)
        self.assertEqual(io.tell(), 0)
        self.assertEqual(io.read(), buffer)

        # seek must be positive when SEEK_SET
        with self.assertRaises(ValueError):
            io.seek(-1, 0)

        # seek from current position
        io.seek(5)
        self.assertEqual(io.tell(), 5)
        io.seek(3, 1)
        self.assertEqual(io.tell(), 8)
        io.seek(-3, 1)
        self.assertEqual(io.tell(), 5)

        # seek from end
        io.seek(-4, 2)
        self.assertEqual(io.tell(), 6)

        # Test readall
        io.seek(0)
        self.assertEqual(io.readall(), buffer)
        self.assertEqual(io.tell(), 10)

        io.seek(5)
        self.assertEqual(io.readall(), buffer[5:])
        self.assertEqual(io.readall(), b"")
Exemplo n.º 4
0
    def test_move(self):
        ctx = t.Ctx()
        vfs = t.VFS(ctx)

        vfs.create_dir(self.path("foo"))
        vfs.create_dir(self.path("bar"))
        vfs.touch(self.path("bar/baz"))

        self.assertTrue(vfs.is_file(self.path("bar/baz")))

        vfs.move(self.path("bar/baz"), self.path("foo/baz"))

        self.assertFalse(vfs.is_file(self.path("bar/baz")))
        self.assertTrue(vfs.is_file(self.path("foo/baz")))

        # moving to invalid dir should raise an error
        with self.assertRaises(t.TileDBError):
            vfs.move(self.path("foo/baz"), self.path("do_not_exist/baz"))
Exemplo n.º 5
0
    def test_file(self):
        ctx = t.Ctx()
        vfs = t.VFS(ctx)

        file = self.path("foo")
        self.assertFalse(vfs.is_file(file))

        # create
        vfs.touch(file)
        self.assertTrue(vfs.is_file(file))

        # remove
        vfs.remove_file(file)
        self.assertFalse(vfs.is_file(file))

        # check nested path
        file = self.path("foo/bar")
        with self.assertRaises(t.TileDBError):
            vfs.touch(file)
Exemplo n.º 6
0
    def test_dir(self):
        ctx = t.Ctx()
        vfs = t.VFS(ctx)

        dir = self.path("foo")
        self.assertFalse(vfs.is_dir(dir))

        # create
        vfs.create_dir(dir)
        self.assertTrue(vfs.is_dir(dir))

        # remove
        vfs.remove_dir(dir)
        self.assertFalse(vfs.is_dir(dir))

        # create nested path
        dir = self.path("foo/bar")
        with self.assertRaises(t.TileDBError):
            vfs.create_dir(dir)

        vfs.create_dir(self.path("foo"))
        vfs.create_dir(self.path("foo/bar"))
        self.assertTrue(vfs.is_dir(dir))