code: def create_output_dir_if_not_exist(dirpath, testfile_name="testfile"):
      """Ensure output dir exists and can be written to.
  
      If dir doesn't exist, attempts to create it. Writes and deletes a test file to
      confirm we have write permissions.
  
      Args:
        dirpath: local directory path.
  
      Raises:
        OSError: Directory can't be created.
        IOError: Test file can't be written.
      """
      if not os.path.isdir(dirpath):
          logging.info(
              "Output dir %s doesn't exist, so attempting to create it."
              % dirpath
          )
          os.makedirs(dirpath)
  
      with open(os.path.join(dirpath, testfile_name), "w") as testfile:
          testfile.write("")
          logging.debug("Successfully wrote test file to output dir.")
      os.remove(os.path.join(dirpath, testfile_name))
      logging.info(
          "Confirmed we have permissions to write to output dir."
      )
  
file_path: facets/facets_atlasmaker/atlasmaker_io.py
imports: import io
  import json
  import os
  import time
  import sys
  from absl import logging
  from PIL import Image
  import requests
  from requests.exceptions import Timeout
label_desc: Use image node_id 1 for calling a global function with example usage: create_output_dir_if_not_exist(dirpath, testfile_name) without return types