code: def test_color_array():
      """Basic tests for ColorArray class"""
      x = ColorArray(["r", "g", "b"])
      assert_array_equal(x.rgb, np.eye(3))
      # Test ColorArray.__getitem__.
      assert isinstance(x[0], ColorArray)
      assert isinstance(x[:], ColorArray)
      assert_array_equal(x.rgba[:], x[:].rgba)
      assert_array_equal(x.rgba[0], x[0].rgba.squeeze())
      assert_array_equal(x.rgba[1:3], x[1:3].rgba)
      assert_raises(ValueError, x.__getitem__, (0, 1))
      # Test ColorArray.__setitem__.
      x[0] = 0
      assert_array_equal(x.rgba[0, :], np.zeros(4))
      assert_array_equal(x.rgba, x[:].rgba)
      x[1] = 1
      assert_array_equal(x[1].rgba, np.ones((1, 4)))
      x[:] = 0.5
      assert_array_equal(x.rgba, 0.5 * np.ones((3, 4)))
      assert_raises(ValueError, x.__setitem__, (0, 1), 0)
  
      # test hsv color space colors
      x = ColorArray(
          color_space="hsv", color=[(0, 0, 1), (0, 0, 0.5), (0, 0, 0)]
      )
      assert_array_equal(x.rgba[0], [1, 1, 1, 1])
      assert_array_equal(x.rgba[1], [0.5, 0.5, 0.5, 1])
      assert_array_equal(x.rgba[2], [0, 0, 0, 1])
  
      x = ColorArray(color_space="hsv")
      assert_array_equal(x.rgba[0], [0, 0, 0, 1])
  
      x = ColorArray([Color((0, 0, 0)), Color((1, 1, 1))])
      assert len(x.rgb) == 2
      x = ColorArray([ColorArray((0, 0, 0)), ColorArray((1, 1, 1))])
      assert len(x.rgb) == 2
  
file_path: vispy/vispy/color/tests/test_color.py
imports: import numpy
  from numpy.testing import assert_array_equal, assert_allclose
  from vispy.color import Color, ColorArray, get_color_names, Colormap, get_color_dict, get_colormap, get_colormaps
  from vispy.visuals.shaders import Function
  from vispy.util import use_log_level
  from vispy.testing import run_tests_if_main, assert_equal, assert_raises, assert_true
label_desc: Use image node_id 2 for calling a global function with example usage: test_color_array() without return types