def testGlobChainingNoProtocol(self):
        """
        This tests the glob prefix application when there's no protocol
        specified on the chained path.
        """
        temp_dir = self.get_temp_dir().split("://")[1]

        with open(posixpath.join(temp_dir, "foo.txt"), "wb") as myfile:
            myfile.write(b"foo")

        with open(posixpath.join(temp_dir, "bar.txt"), "wb") as myfile:
            myfile.write(b"bar")

        foo_raw = posixpath.join(temp_dir, "foo.txt")
        foo_cached = "simplecache::" + foo_raw

        fs = gfile.get_filesystem("file://")
        cached_fs = gfile.get_filesystem("simplecache::file://")

        self.assertTrue(fs.exists(foo_raw))
        self.assertTrue(cached_fs.exists(foo_cached))

        cache_dir = "simplecache::" + temp_dir
        files = cached_fs.glob(posixpath.join(cache_dir, "*.txt"))
        self.assertCountEqual(
            files,
            [
                posixpath.join(cache_dir, "foo.txt"),
                posixpath.join(cache_dir, "bar.txt"),
            ],
        )
 def testExistence(self):
     self.assertIsInstance(
         gfile.get_filesystem("simplecache::nonexistent::file://blah/blah"),
         gfile.FSSpecFileSystem,
     )
    def testJoin(self):
        fs = gfile.get_filesystem("file://foo")

        # relative
        self.assertEqual(
            fs.join("bar", "foo", "hi"),
            "bar/foo/hi",
        )
        # absolute with protocol
        self.assertEqual(
            fs.join("file:///bar", "foo", "hi"),
            "file:///bar/foo/hi",
        )
        # empty path element
        self.assertEqual(
            fs.join("file:///bar", "", "hi"),
            "file:///bar/hi",
        )
        # relative with protocol
        self.assertEqual(
            fs.join("file://bar", "foo"),
            "file://bar/foo",
        )
        # chained relative with protocol
        self.assertEqual(
            fs.join("simplecache::file://bucket/some/path", "bar"),
            "simplecache::file://bucket/some/path/bar",
        )
        # chained absolute without protocol
        self.assertEqual(
            fs.join("simplecache::/some/path", "bar"),
            "simplecache::/some/path/bar",
        )
        # absolute second part
        self.assertEqual(
            fs.join("simplecache::/some/path", "/bar"),
            "simplecache::/bar",
        )
        # absolute second part with protocol
        self.assertEqual(
            fs.join("simplecache::file:///some/path", "/bar"),
            "simplecache::file:///bar",
        )
        # trailing /
        self.assertEqual(
            fs.join("simplecache::/some/path/", "bar/", "foo"),
            "simplecache::/some/path/bar/foo",
        )
        # Trailing slash on the last element
        self.assertEqual(
            fs.join("hello", "world/"),
            "hello/world/",
        )
        # empty path at the end
        self.assertEqual(
            fs.join("hello", "world", ""),
            "hello/world/",
        )
        # absolute path in the middle
        self.assertEqual(
            fs.join("hello", "", "world", "", "/wow"),
            "/wow",
        )
 def testNonExistentFilesystem(self):
     with self.assertRaises(ValueError):
         gfile.get_filesystem("nonexistent::blah://filesystem")