def testGlobChaining(self): """ This tests glob with chained file systems. """ temp_dir = self.get_temp_dir() on_disk = temp_dir.split("://")[1] with open(posixpath.join(on_disk, "foo.txt"), "wb") as myfile: myfile.write(b"foo") with open(posixpath.join(on_disk, "bar.txt"), "wb") as myfile: myfile.write(b"bar") foo_raw = posixpath.join(temp_dir, "foo.txt") foo_cached = "simplecache::" + foo_raw self.assertTrue(gfile.exists(foo_raw)) self.assertTrue(gfile.exists(foo_cached)) cache_dir = "simplecache::" + temp_dir files = gfile.glob(posixpath.join(cache_dir, "*.txt")) self.assertCountEqual( files, [ posixpath.join(cache_dir, "foo.txt"), posixpath.join(cache_dir, "bar.txt"), ], )
def testComplexChaining(self): path = "simplecache::zip://*::file://banana/bar" with self.assertRaisesRegexp( errors.InvalidArgumentError, "fsspec URL must only have paths in the last chained filesystem", ): gfile.exists(path)
def predict(self, path): if exists(self.model_path): model = load_model(self.model_path) X = imgprocess.load_img(path, target_size=(self.width, self.height)) X = imgprocess.img_to_array(X) X = np.expand_dims(X, axis=0) return self.interpret_class(X, model)
def _create_symlink_dir(self): if gfile.exists(self.dest_path): raise ValueError( "Dashboard already exists - Couldn't create directory") else: for run in self.runs: run_path = run['path'] run_name = run['name'] if not gfile.exists( os.path.dirname(os.path.join(self.dest_path, run_name))): gfile.makedirs( os.path.dirname(os.path.join(self.dest_path, run_name))) os.symlink(run_path, os.path.join(self.dest_path, run_name), target_is_directory=True)
def testExists(self): temp_dir = self.get_temp_dir() self._CreateDeepDirectoryStructure(temp_dir) ckpt_path = os.path.join(temp_dir, "model.ckpt") self.assertTrue(gfile.exists(temp_dir)) self.assertTrue(gfile.exists(ckpt_path))
def testExists(self): temp_dir = self._CreateDeepS3Structure() ckpt_path = self._PathJoin(temp_dir, 'model.ckpt') self.assertTrue(gfile.exists(temp_dir)) self.assertTrue(gfile.exists(ckpt_path))
def testExists(self): temp_dir = tempfile.mkdtemp(prefix=self.base_temp_dir) self._CreateDeepDirectoryStructure(temp_dir) ckpt_path = os.path.join(temp_dir, 'model.ckpt') self.assertTrue(gfile.exists(temp_dir)) self.assertTrue(gfile.exists(ckpt_path))
def testFileReadBadMode(self): file_path = os.path.join(self._base_dir, "temp_file") gfile.GFile(file_path, mode="w").write("testing") self.assertTrue(gfile.exists(file_path)) with self.assertRaises(errors.PermissionDeniedError): gfile.GFile(file_path, mode="w").read()
def testWriteToString(self): file_path = os.path.join(self._base_dir, "temp_file") gfile._write_string_to_file(file_path, "testing") self.assertTrue(gfile.exists(file_path)) file_contents = gfile._read_file_to_string(file_path) self.assertEqual("testing", file_contents)
def testFileDoesntExist(self): file_path = os.path.join(self._base_dir, "temp_file") self.assertFalse(gfile.exists(file_path)) with self.assertRaises(errors.NotFoundError): _ = gfile._read_file_to_string(file_path)
def testUTF8StringPathExists(self): file_path = os.path.join(self._base_dir, "UTF8测试_file_exist") gfile._write_string_to_file(file_path, "testing") v = gfile.exists(file_path) self.assertEqual(v, True)
def read_class_labels_if_exists(self): if exists(self.class_labels): with open(self.class_labels, 'r') as file: return json.load(file) else: return None