class_docstr: OSS Filesystem Tests
docstr: Test directory operations
docstr_tok: ["Test","directory","operations"]
code: def test_dir_operations(self):
      """Test directory operations"""
  
      d = get_oss_path("d1/d2/d3/d4")
      gfile.MakeDirs(d)
      self.assertTrue(gfile.Stat(d).is_directory)
  
      # Test listing test directory with and without trailing '/'
      content = gfile.ListDirectory(
          "oss://%s\x01id=%s\x02key=%s\x02host=%s"
          % (bucket, access_id, access_key, host)
          + "/oss_fs_test"
      )
      content_s = gfile.ListDirectory(
          "oss://%s\x01id=%s\x02key=%s\x02host=%s"
          % (bucket, access_id, access_key, host)
          + "/oss_fs_test/"
      )
      self.assertEqual(content, content_s)
      self.assertIn("d1", content)
  
      # Test listing sub directories.
      content = gfile.ListDirectory(get_oss_path("d1"))
      content_s = gfile.ListDirectory(get_oss_path("d1/"))
      self.assertEqual(content, content_s)
      self.assertIn("d2", content)
  
      content = gfile.ListDirectory(get_oss_path("d1/d2/d3/d4"))
      content_s = gfile.ListDirectory(get_oss_path("d1/d2/d3/d4"))
      self.assertEqual(content, content_s)
      self.assertEqual([], content)
  
      # Test Rename directories
      self.assertTrue(gfile.Exists(get_oss_path("d1")))
      gfile.Rename(
          get_oss_path("d1"), get_oss_path("rename_d1"), overwrite=True
      )
      self.assertTrue(gfile.Exists(get_oss_path("rename_d1")))
      self.assertFalse(gfile.Exists(get_oss_path("d1")))
  
      content = gfile.ListDirectory(get_oss_path("rename_d1"))
      content_s = gfile.ListDirectory(get_oss_path("rename_d1/"))
      self.assertEqual(content, content_s)
      self.assertIn("d2", content)
  
      # Test Rename non-empty directories
      not_empty_dir = get_oss_path("not_empty_dir/")
      rename_not_empty_dir = get_oss_path("rename_not_empty_dir/")
      gfile.MakeDirs(not_empty_dir)
      not_empty_file = get_oss_path("not_empty_dir/not_empty_file")
      rename_not_empty_file = get_oss_path(
          "rename_not_empty_dir/not_empty_file"
      )
      with gfile.Open(not_empty_file, mode="w") as fh:
          content = "file content"
          fh.write(content)
      self.assertTrue(gfile.Exists(not_empty_dir))
      self.assertTrue(gfile.Exists(not_empty_file))
      gfile.Rename(not_empty_dir, rename_not_empty_dir, overwrite=True)
      self.assertFalse(gfile.Exists(not_empty_dir))
      self.assertFalse(gfile.Exists(not_empty_file))
      self.assertTrue(gfile.Exists(rename_not_empty_dir))
      self.assertTrue(gfile.Exists(rename_not_empty_file))
  
imports: import os
  import unittest
  from tensorflow.python.framework import errors
  from tensorflow.python.lib.io import file_io
  from tensorflow.python.platform import test
  from tensorflow.python.platform import gfile
  import tensorflow
  import tensorflow_io
label_desc: Use image node_id 6 for calling the OSSFSTest obj's underlying member method code with example usage: obj.test_dir_operations() without return types