code: def test_framebuffer():
      # Test init with no args
      F = FrameBuffer()
      glir_cmds = F._glir.clear()
      assert len(glir_cmds) == 1
      glir_cmds[0][0] == "CREATE"
  
      # Activate / deactivate
      F.activate()
      glir_cmd = F._glir.clear()[-1]
      assert glir_cmd[0] == "FRAMEBUFFER"
      assert glir_cmd[2] is True
      #
      F.deactivate()
      glir_cmd = F._glir.clear()[-1]
      assert glir_cmd[0] == "FRAMEBUFFER"
      assert glir_cmd[2] is False
      #
      with F:
          pass
      glir_cmds = F._glir.clear()
      assert len(glir_cmds) == 2
      assert glir_cmds[0][0] == "FRAMEBUFFER"
      assert glir_cmds[1][0] == "FRAMEBUFFER"
      assert glir_cmds[0][2] is True and glir_cmds[1][2] is False
  
      # Init with args
      R = RenderBuffer((3, 3))
      F = FrameBuffer(R)
      assert F.color_buffer is R
      #
      R2 = RenderBuffer((3, 3))
      F.color_buffer = R2
      assert F.color_buffer is R2
  
      # Wrong buffers
      F = FrameBuffer()
      assert_raises(TypeError, FrameBuffer.color_buffer.fset, F, "FOO")
      assert_raises(TypeError, FrameBuffer.color_buffer.fset, F, [])
      assert_raises(TypeError, FrameBuffer.depth_buffer.fset, F, "FOO")
      assert_raises(
          TypeError, FrameBuffer.stencil_buffer.fset, F, "FOO"
      )
      color_buffer = RenderBuffer((9, 9), "color")
      assert_raises(
          ValueError, FrameBuffer.depth_buffer.fset, F, color_buffer
      )
      # But None is allowed!
      F.color_buffer = None
  
      # Shape
      R1 = RenderBuffer((3, 3))
      R2 = RenderBuffer((3, 3))
      R3 = RenderBuffer((3, 3))
      F = FrameBuffer(R1, R2, R3)
      assert F.shape == R1.shape
      assert R1.format == "color"
      assert R2.format == "depth"
      assert R3.format == "stencil"
      # Resize
      F.resize((10, 10))
      assert F.shape == (10, 10)
      assert F.shape == R1.shape
      assert F.shape == R2.shape
      assert F.shape == R3.shape
      assert R1.format == "color"
      assert R2.format == "depth"
      assert R3.format == "stencil"
      # Shape from any buffer
      F.color_buffer = None
      assert F.shape == (10, 10)
      F.depth_buffer = None
      assert F.shape == (10, 10)
      F.stencil_buffer = None
      assert_raises(RuntimeError, FrameBuffer.shape.fget, F)
  
      # Also with Texture luminance
      T = gloo.Texture2D((20, 30))
      R = RenderBuffer(T.shape)
      assert T.format == "luminance"
      F = FrameBuffer(T, R)
      assert F.shape == T.shape[:2]
      assert F.shape == R.shape
      assert T.format == "luminance"
      assert R.format == "depth"
      # Resize
      F.resize((10, 10))
      assert F.shape == (10, 10)
      assert T.shape == (10, 10, 1)
      assert F.shape == R.shape
      assert T.format == "luminance"
      assert R.format == "depth"
  
      # Also with Texture RGB
      T = gloo.Texture2D((20, 30, 3))
      R = RenderBuffer(T.shape)
      assert T.format == "rgb"
      F = FrameBuffer(T, R)
      assert F.shape == T.shape[:2]
      assert F.shape == R.shape
      assert T.format == "rgb"
      assert R.format == "depth"
      # Resize
      F.resize((10, 10))
      assert F.shape == (10, 10)
      assert T.shape == (10, 10, 3)
      assert F.shape == R.shape
      assert T.format == "rgb"
      assert R.format == "depth"
  
      # Also with Texture for depth
      T1 = gloo.Texture2D((20, 30, 3))
      T2 = gloo.Texture2D((20, 30, 1))
      assert T1.format == "rgb"
      assert T2.format == "luminance"
      F = FrameBuffer(T1, T2)
      assert F.shape == T1.shape[:2]
      assert F.shape == T2.shape[:2]
      assert T1.format == "rgb"
      assert T2.format == "luminance"
      # Resize
      F.resize((10, 10))
      assert F.shape == (10, 10)
      assert T1.shape == (10, 10, 3)
      assert T2.shape == (10, 10, 1)
      assert T1.format == "rgb"
      assert T2.format == "luminance"
  
      # Wrong shape in resize
      assert_raises(ValueError, F.resize, (9, 9, 1))
      assert_raises(ValueError, F.resize, (9,))
      assert_raises(ValueError, F.resize, "FOO")
  
imports: from vispy.testing import run_tests_if_main, assert_raises
  from vispy import gloo
  from vispy.gloo import FrameBuffer, RenderBuffer
label_desc: Use image node_id 2 for calling a global function with example usage: test_framebuffer() without return types