code: def TestingCanvas(
      bgcolor="black",
      size=(100, 100),
      dpi=None,
      decorate=None,
      **kwargs,
  ):
      """Avoid importing scene until necessary."""
      # On Windows decorations can force windows to be an incorrect size
      # (e.g., instead of 100x100 they will be 100x248), having no
      # decorations works around this
      from ..scene import SceneCanvas
  
      class TestingCanvas(SceneCanvas):
          def __init__(self, bgcolor, size, dpi, decorate, **kwargs):
              self._entered = False
              self._wanted_vp = None
              if decorate is None:
                  # deal with GLFW's problems
                  from vispy.app import use_app
  
                  app = use_app()
                  if _bad_glfw_decorate(app):
                      decorate = True
                  else:
                      decorate = False
              SceneCanvas.__init__(
                  self,
                  bgcolor=bgcolor,
                  size=size,
                  dpi=dpi,
                  decorate=decorate,
                  **kwargs,
              )
  
          def __enter__(self):
              SceneCanvas.__enter__(self)
              # sometimes our window can be larger than our requsted draw
              # area (e.g. on Windows), and this messes up our tests that
              # typically use very small windows. Here we "fix" it.
              scale = np.array(self.physical_size) / np.array(
                  self.size, float
              )
              scale = int(np.round(np.mean(scale)))
              self._wanted_vp = 0, 0, size[0] * scale, size[1] * scale
              self.context.set_state(clear_color=self._bgcolor)
              self.context.set_viewport(*self._wanted_vp)
              self._entered = True
              return self
  
          def draw_visual(self, visual, event=None):
              if not self._entered:
                  return
              SceneCanvas.draw_visual(self, visual, event)
              self.context.finish()
  
      return TestingCanvas(bgcolor, size, dpi, decorate, **kwargs)
  
imports: from __future__ import print_function
  import numpy
  import sys
  import os
  import inspect
  import gc
  import pytest
  import functools
  from packaging.version import Version
  from ..util.check_environment import has_backend
label_desc: Use image node_id 27 for calling a global function with example usage: TestingCanvas(bgcolor, size, dpi, decorate) and returns: TestingCanvas, self