code: def test_context_taking():
      """Test GLContext ownership and taking"""
  
      def get_canvas(c):
          return c.shared.ref
  
      cb = DummyCanvasBackend()
      c = GLContext()
  
      # Context is not taken and cannot get backend_canvas
      assert c.shared.name is None
      assert_raises(RuntimeError, get_canvas, c)
      assert_in("None backend", repr(c.shared))
  
      # Take it
      c.shared.add_ref("test-foo", cb)
      assert c.shared.ref is cb
      assert_in("test-foo backend", repr(c.shared))
  
      # Now we can take it again
      c.shared.add_ref("test-foo", cb)
      assert len(c.shared._refs) == 2
      # assert_raises(RuntimeError, c.take, 'test', cb)
  
      # Canvas backend can delete (we use a weak ref)
      cb = DummyCanvasBackend()  # overwrite old object
      gc.collect()
  
      # No more refs
      assert_raises(RuntimeError, get_canvas, c)
  
file_path: vispy/vispy/gloo/tests/test_context.py
imports: import gc
  from vispy.testing import assert_in, run_tests_if_main, assert_raises, assert_equal, assert_not_equal
  from vispy import gloo
  from vispy.gloo import GLContext, get_default_config
label_desc: Use image node_id 2 for calling a global function with example usage: test_context_taking() and returns: c