code: def test_texture_3D():
      # Note: put many tests related to (re)sizing here, because Texture
      # is not really aware of shape.
  
      # Shape extension
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
      assert T._shape == (10, 10, 10, 1)
      assert "Texture3D" in repr(T)
      assert T.glsl_type == ("uniform", "sampler3D")
  
      # Width & height
      # ---------------------------------
      data = np.zeros((10, 20, 30), dtype=np.uint8)
      T = Texture3D(data=data)
      assert T.width == 30
      assert T.height == 20
      assert T.depth == 10
  
      # Resize
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
      T.resize((5, 5, 5))
      assert T.shape == (5, 5, 5, 1)
      glir_cmd = T._glir.clear()[-1]
      assert glir_cmd[0] == "SIZE"
      assert glir_cmd[2] == (5, 5, 5, 1)
  
      # Resize with bad shape
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
      # with self.assertRaises(ValueError):
      #    T.resize((5, 5, 5, 5))
      assert_raises(ValueError, T.resize, (5, 5, 5, 5))
  
      # Resize not resizable
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data, resizable=False)
      # with self.assertRaises(RuntimeError):
      #    T.resize((5, 5, 5))
      assert_raises(RuntimeError, T.resize, (5, 5, 5))
  
      # Set oversized data (-> resize)
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
      T.set_data(np.ones((20, 20, 20), np.uint8))
      assert T.shape == (20, 20, 20, 1)
  
      # Set undersized data
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
      T.set_data(np.ones((5, 5, 5), np.uint8))
      assert T.shape == (5, 5, 5, 1)
  
      # Set misplaced data
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
      # with self.assertRaises(ValueError):
      #    T.set_data(np.ones((5, 5, 5)), offset=(8, 8, 8))
      assert_raises(
          ValueError, T.set_data, np.ones((5, 5, 5)), offset=(8, 8, 8)
      )
  
      # Set misshaped data
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
      # with self.assertRaises(ValueError):
      #    T.set_data(np.ones((10, 10, 10)))
      assert_raises(ValueError, T.set_data, np.ones((10,)))
  
      # Set whole data (clear pending data)
      # ---------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
      T.set_data(np.ones((10, 10, 10), np.uint8))
      assert T.shape == (10, 10, 10, 1)
      glir_cmd = T._glir.clear()[-1]
      assert glir_cmd[0] == "DATA"
  
      # Test set data with different shape
      # ---------------------------------
      shape1 = 10, 10, 10
      shape3 = 10, 10, 10, 3
  
      # Init data (explicit shape)
      data = np.zeros((10, 10, 10, 1), dtype=np.uint8)
      T = Texture3D(data=data)
      assert T.shape == (10, 10, 10, 1)
      assert T._format == "luminance"
  
      # Set data to rgb
      T.set_data(np.zeros(shape3, np.uint8))
      assert T.shape == (10, 10, 10, 3)
      assert T._format == "rgb"
  
      # Set data to grayscale
      T.set_data(np.zeros(shape1, np.uint8))
      assert T.shape == (10, 10, 10, 1)
      assert T._format == "luminance"
  
      # Set size to rgb
      T.resize(shape3)
      assert T.shape == (10, 10, 10, 3)
      assert T._format == "rgb"
  
      # Set size to grayscale
      T.resize(shape1)
      assert T.shape == (10, 10, 10, 1)
      assert T._format == "luminance"
  
      # Test set data with different shape and type
      # -------------------------------------------
      data = np.zeros((10, 10, 10), dtype=np.uint8)
      T = Texture3D(data=data)
  
      data = np.zeros((10, 11, 11), dtype=np.float32)
      T.set_data(data)
  
      data = np.zeros((12, 12, 10), dtype=np.int32)
      T.set_data(data)
  
imports: import unittest
  import numpy
  import pytest
  from vispy.gloo import Texture1D, Texture2D, Texture3D, TextureAtlas
  from vispy.testing import requires_pyopengl, run_tests_if_main, assert_raises
label_desc: Use image node_id 2 for calling a global function with example usage: test_texture_3D() without return types