def TestFindFileInDirectoryOrAncestors():
  """ Test FindFileInDirectoryOrAncestors"""
  # Create an empty temp directory
  root_dir = tempfile.mkdtemp()
  a_dir = os.path.join(root_dir, "a")
  b_dir = os.path.join(a_dir, "b")

  # Create subdirectories
  os.mkdir(a_dir)
  os.mkdir(b_dir)

  # Create temporary file
  filepath = os.path.join(root_dir, "test_file")
  fp = open(filepath, "w")
  fp.close()
  print(root_dir, a_dir, b_dir, filepath)

  # Check if test_file can be found
  assert(U.FindFileInDirectoryOrAncestors("test_file", b_dir) ==
      filepath)

  # Ensure that adding /. to the path does not
  # change the result of the test
  c_dir = os.path.join(b_dir, os.path.curdir)
  assert(U.FindFileInDirectoryOrAncestors("test_file", c_dir) ==
      filepath)

  # Change Permissions to 000 and ensure that an
  # IOError is thrown
  os.chmod(filepath, 0)
  raised = False
  try:
    U.FindFileInDirectoryOrAncestors("test_file", c_dir)
  except __HOLE__ as e:
    raised = True
  assert(raised)

  # Remove the file and temporary directories
  os.remove(filepath)
  assert(U.FindFileInDirectoryOrAncestors("test_file", b_dir) ==
     None)
  os.removedirs(b_dir)
  return
dataset/ETHPy150Open spranesh/Redhawk/redhawk/test/test_utils_util.py/TestFindFileInDirectoryOrAncestors