code: def cleanup(style=None):
      """
      A decorator to ensure that any global state is reset before
      running a test.
  
      Parameters
      ----------
      style : str, optional
          The name of the style to apply.
      """
  
      # If cleanup is used without arguments, `style` will be a
      # callable, and we pass it directly to the wrapper generator.  If
      # cleanup if called with an argument, it is a string naming a
      # style, and the function will be passed as an argument to what we
      # return.  This is a confusing, but somewhat standard, pattern for
      # writing a decorator with optional arguments.
  
      def make_cleanup(func):
          if inspect.isgeneratorfunction(func):
  
              @functools.wraps(func)
              def wrapped_callable(*args, **kwargs):
                  original_units_registry = (
                      matplotlib.units.registry.copy()
                  )
                  original_settings = mpl.rcParams.copy()
                  matplotlib.style.use(style)
                  try:
                      for yielded in func(*args, **kwargs):
                          yield yielded
                  finally:
                      _do_cleanup(
                          original_units_registry, original_settings
                      )
  
          else:
  
              @functools.wraps(func)
              def wrapped_callable(*args, **kwargs):
                  original_units_registry = (
                      matplotlib.units.registry.copy()
                  )
                  original_settings = mpl.rcParams.copy()
                  matplotlib.style.use(style)
                  try:
                      func(*args, **kwargs)
                  finally:
                      _do_cleanup(
                          original_units_registry, original_settings
                      )
  
          return wrapped_callable
  
      if isinstance(style, six.string_types):
          return make_cleanup
      else:
          result = make_cleanup(style)
          # Default of mpl_test_settings fixture and image_comparison too.
          style = "_classic_test"
          return result
  
imports: from __future__ import absolute_import, division, print_function
  import six
  import functools
  import inspect
  import os
  import sys
  import shutil
  import warnings
  import unittest
  import matplotlib
  import matplotlib.style
  import matplotlib.units
  import matplotlib.testing
  from matplotlib import cbook
  from matplotlib import ticker
  from matplotlib import pyplot
  from matplotlib import ft2font
  from matplotlib.testing.compare import comparable_formats, compare_images, make_test_filename
  from .None import _copy_metadata, is_called_from_pytest
  from .exceptions import ImageComparisonFailure
label_desc: Use image node_id 4 for calling a global function with example usage: cleanup(style) and returns: wrapped_callable, make_cleanup, result