code: def assertImageApproved(image, standardFile, message=None, **kwargs):
      """Check that an image test result matches a pre-approved standard.
  
      If the result does not match, then the user can optionally invoke a GUI
      to compare the images and decide whether to fail the test or save the new
      image as the standard.
  
      Run the test with the environment variable PYQTGRAPH_AUDIT=1 to bring up
      the auditing GUI.
  
      Parameters
      ----------
      image : (h, w, 4) ndarray
      standardFile : str
          The name of the approved test image to check against. This file name
          is relative to the root of the pyqtgraph test-data repository and will
          be automatically fetched.
      message : str
          A string description of the image. It is recommended to describe
          specific features that an auditor should look for when deciding whether
          to fail a test.
  
      Extra keyword arguments are used to set the thresholds for automatic image
      comparison (see ``assertImageMatch()``).
      """
      if isinstance(image, QtWidgets.QWidget):
          # just to be sure the widget size is correct (new window may be resized):
          QtWidgets.QApplication.processEvents()
  
          graphstate = scenegraphState(image, standardFile)
          image = getImageFromWidget(image)
  
      if message is None:
          code = inspect.currentframe().f_back.f_code
          message = "%s::%s" % (code.co_filename, code.co_name)
  
      # Make sure we have a test data repo available
      dataPath = getTestDataDirectory()
  
      # Read the standard image if it exists
      stdFileName = os.path.join(dataPath, standardFile + ".png")
      if not os.path.isfile(stdFileName):
          stdImage = None
      else:
          qimg = QtGui.QImage(stdFileName)
          qimg = qimg.convertToFormat(
              QtGui.QImage.Format.Format_RGBA8888
          )
          stdImage = fn.ndarray_from_qimage(qimg).copy()
          del qimg
  
      # If the test image does not match, then we go to audit if requested.
      try:
          if stdImage is None:
              raise Exception("No reference image saved for this test.")
          if image.shape[2] != stdImage.shape[2]:
              raise Exception(
                  "Test result has different channel count than standard image"
                  "(%d vs %d)" % (image.shape[2], stdImage.shape[2])
              )
          if image.shape != stdImage.shape:
              # Allow im1 to be an integer multiple larger than im2 to account
              # for high-resolution displays
              ims1 = np.array(image.shape).astype(float)
              ims2 = np.array(stdImage.shape).astype(float)
              sr = ims1 / ims2 if ims1[0] > ims2[0] else ims2 / ims1
              if (
                  sr[0] != sr[1]
                  or not np.allclose(sr, np.round(sr))
                  or sr[0] < 1
              ):
                  raise TypeError(
                      "Test result shape %s is not an integer factor"
                      " different than standard image shape %s."
                      % (ims1, ims2)
                  )
              sr = np.round(sr).astype(int)
              image = fn.downsample(image, sr[0], axis=(0, 1)).astype(
                  image.dtype
              )
  
          assertImageMatch(image, stdImage, **kwargs)
  
          if bool(os.getenv("PYQTGRAPH_PRINT_TEST_STATE", False)):
              print(graphstate)
  
          if os.getenv("PYQTGRAPH_AUDIT_ALL") == "1":
              raise Exception(
                  "Image test passed, but auditing due to PYQTGRAPH_AUDIT_ALL evnironment variable."
              )
      except Exception:
          if (
              os.getenv("PYQTGRAPH_AUDIT") == "1"
              or os.getenv("PYQTGRAPH_AUDIT_ALL") == "1"
          ):
              sys.excepthook(*sys.exc_info())
              getTester().test(image, stdImage, message)
              stdPath = os.path.dirname(stdFileName)
              print('Saving new standard image to "%s"' % stdFileName)
              if not os.path.isdir(stdPath):
                  os.makedirs(stdPath)
              qimg = fn.ndarray_to_qimage(
                  image, QtGui.QImage.Format.Format_RGBA8888
              )
              qimg.save(stdFileName)
              del qimg
          else:
              if stdImage is None:
                  raise Exception(
                      "Test standard %s does not exist. Set "
                      "PYQTGRAPH_AUDIT=1 to add this image."
                      % stdFileName
                  )
              if os.getenv("CI") is not None:
                  standardFile = os.path.join(
                      os.getenv("SCREENSHOT_DIR", "screenshots"),
                      standardFile,
                  )
                  saveFailedTest(image, stdImage, standardFile)
              print(graphstate)
              raise
  
imports: import inspect
  import os
  import sys
  import time
  from pathlib import Path
  import numpy
  from pyqtgraph import GraphicsLayoutWidget, ImageItem, TextItem
  from pyqtgraph import functions
  from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
label_desc: Use image node_id 3 for calling a global function with example usage: assertImageApproved(image, standardFile, message) without return types