code: def convert(filename, cache):
      """
      Convert the named file into a png file.  Returns the name of the
      created file.
  
      If *cache* is True, the result of the conversion is cached in
      `matplotlib._get_cachedir() + '/test_cache/'`.  The caching is based
      on a hash of the exact contents of the input file.  The is no limit
      on the size of the cache, so it may need to be manually cleared
      periodically.
  
      """
      base, extension = filename.rsplit(".", 1)
      if extension not in converter:
          reason = (
              "Don't know how to convert %s files to png" % extension
          )
          from . import is_called_from_pytest
  
          if is_called_from_pytest():
              import pytest
  
              pytest.skip(reason)
          else:
              from nose import SkipTest
  
              raise SkipTest(reason)
      newname = base + "_" + extension + ".png"
      if not os.path.exists(filename):
          raise IOError("'%s' does not exist" % filename)
  
      # Only convert the file if the destination doesn't already exist or
      # is out of date.
      if (
          not os.path.exists(newname)
          or os.stat(newname).st_mtime < os.stat(filename).st_mtime
      ):
          if cache:
              cache_dir = get_cache_dir()
          else:
              cache_dir = None
  
          if cache_dir is not None:
              hash_value = get_file_hash(filename)
              new_ext = os.path.splitext(newname)[1]
              cached_file = os.path.join(
                  cache_dir, hash_value + new_ext
              )
              if os.path.exists(cached_file):
                  shutil.copyfile(cached_file, newname)
                  return newname
  
          converter[extension](filename, newname)
  
          if cache_dir is not None:
              shutil.copyfile(newname, cached_file)
  
      return newname
  
imports: from __future__ import absolute_import, division, print_function
  import six
  import atexit
  import functools
  import hashlib
  import itertools
  import os
  import re
  import shutil
  import sys
  from tempfile import TemporaryFile
  import numpy
  import matplotlib
  from matplotlib.compat import subprocess
  from matplotlib.testing.exceptions import ImageComparisonFailure
  from matplotlib import _png
  from matplotlib import _get_cachedir
  from matplotlib import cbook
label_desc: Use image node_id 9 for calling a global function with example usage: convert(filename, cache) and returns: newname, newname