Example #1
0
 def test_set_misplaced_data(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data)
     # with self.assertRaises(ValueError):
     #    T.set_data(np.ones((5, 5)), offset=(8, 8))
     self.assertRaises(ValueError, T.set_data,
                       np.ones((5, 5)), offset=(8, 8))
Example #2
0
    def test_reset_data_shape(self):
        shape1 = 10, 10
        shape3 = 10, 10, 3

        # Init data (explicit shape)
        data = np.zeros((10, 10, 1), dtype=np.uint8)
        T = Texture2D(data=data)
        assert T.shape == (10, 10, 1)
        assert T._format == gl.GL_LUMINANCE

        # Set data to rgb
        T.set_data(np.zeros(shape3, np.uint8))
        assert T.shape == (10, 10, 3)
        assert T._format == gl.GL_RGB


        # Set data to grayscale
        T.set_data(np.zeros(shape1, np.uint8))
        assert T.shape == (10, 10, 1)
        assert T._format == gl.GL_LUMINANCE

        # Set size to rgb
        T.resize(shape3)
        assert T.shape == (10, 10, 3)
        assert T._format == gl.GL_RGB

        # Set size to grayscale
        T.resize(shape1)
        assert T.shape == (10, 10, 1)
        assert T._format == gl.GL_LUMINANCE
Example #3
0
 def test_resize_view(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data)
     # with self.assertRaises(RuntimeError):
     #    T[...].resize((5, 5))
     Z = T[...]
     self.assertRaises(RuntimeError, Z.resize, (5, 5))
Example #4
0
 def test_set_oversized_data(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data)
     T.set_data(np.ones((20, 20), np.uint8))
     assert T.shape == (20, 20, 1)
     assert T._data.shape == (20, 20, 1)
     assert len(T._pending_data) == 1
Example #5
0
 def test_resize(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data)
     T.resize((5, 5))
     assert T.shape == (5, 5, 1)
     assert T._data.shape == (5, 5, 1)
     assert T._need_resize is True
     assert T._need_update is False
     assert len(T._pending_data) == 0
Example #6
0
    def test_reset_data_type(self):
        shape = 10, 10
        T = Texture2D(data=np.zeros(shape, dtype=np.uint8))
        assert T.dtype == np.uint8
        assert T._gtype == gl.GL_UNSIGNED_BYTE

        newdata = np.zeros(shape, dtype=np.float32)
        self.assertRaises(ValueError, T.set_data, newdata)

        newdata = np.zeros(shape, dtype=np.int32)
        self.assertRaises(ValueError, T.set_data, newdata)
Example #7
0
 def test_invalid_views(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data)
     Z = T[5:, 5:]
     T.resize((5, 5))
     assert Z._valid is False
Example #8
0
 def test_set_misshaped_data_2D(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data)
     # with self.assertRaises(ValueError):
     #    T.set_data(np.ones((10, 10)))
     self.assertRaises(ValueError, T.set_data, np.ones((10,)))
Example #9
0
 def test_resize_unresizeable(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data, resizeable=False)
     # with self.assertRaises(RuntimeError):
     #    T.resize((5, 5))
     self.assertRaises(RuntimeError, T.resize, (5, 5))
Example #10
0
 def test_resize_bad_shape(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data)
     # with self.assertRaises(ValueError):
     #    T.resize((5, 5, 5))
     self.assertRaises(ValueError, T.resize, (5, 5, 5))
Example #11
0
 def test_width_height(self):
     data = np.zeros((10, 20), dtype=np.uint8)
     T = Texture2D(data=data)
     assert T.width == 20
     assert T.height == 10
Example #12
0
 def test_init(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture2D(data=data)
     assert T._shape == (10, 10, 1)