def test_set_whole_data(self): data = np.zeros(100) B = Buffer(data=data) B._glir.clear() B.set_data(data=data) glir_cmds = B._glir.clear() assert len(glir_cmds) == 2 assert glir_cmds[0][0] == 'SIZE' assert glir_cmds[1][0] == 'DATA' # And sub data B.set_subdata(data[:50], 20) glir_cmds = B._glir.clear() assert len(glir_cmds) == 1 assert glir_cmds[0][0] == 'DATA' assert glir_cmds[0][2] == 20 # offset # And sub data B.set_subdata(data) glir_cmds = B._glir.clear() assert glir_cmds[-1][0] == 'DATA' # Wrong ways to set subdata self.assertRaises(ValueError, B.set_subdata, data[:50], -1) # neg self.assertRaises(ValueError, B.set_subdata, data, 10) # no fit
def test_set_whole_data(self): data = np.zeros(100) B = Buffer(data=data) B._context.glir.clear() B.set_data(data=data) glir_cmds = B._context.glir.clear() assert len(glir_cmds) == 2 assert glir_cmds[0][0] == 'SIZE' assert glir_cmds[1][0] == 'DATA' # And sub data B.set_subdata(data[:50], 20) glir_cmds = B._context.glir.clear() assert len(glir_cmds) == 1 assert glir_cmds[0][0] == 'DATA' assert glir_cmds[0][2] == 20 # offset # And sub data B.set_subdata(data) glir_cmds = B._context.glir.clear() assert glir_cmds[-1][0] == 'DATA' # Wrong ways to set subdata self.assertRaises(ValueError, B.set_subdata, data[:50], -1) # neg self.assertRaises(ValueError, B.set_subdata, data, 10) # no fit
def test_buffer_resize(self): data = np.zeros(10) B = Buffer(data=data) data = np.zeros(20) B._need_resize = False B.set_data(data) assert B.nbytes == data.nbytes assert B._need_resize is True
def test_setting_size(self): data = np.zeros(100, np.float32) buffer = Buffer(target=gl.GL_ARRAY_BUFFER) buffer.set_data(data) self.assertEqual(buffer.nbytes, data.nbytes) buffer.set_data( np.zeros(200, np.float32)) self.assertEqual(buffer.nbytes, 200*4) buffer.set_nbytes(10) self.assertEqual(buffer.nbytes, 10) buffer.set_nbytes(20) self.assertEqual(buffer.nbytes, 20)
def test_pending_data(self): data = np.zeros(100, np.float32) buffer = Buffer(target=gl.GL_ARRAY_BUFFER) self.assertEqual(len(buffer._pending_data), 0) buffer = Buffer(data=data, target=gl.GL_ARRAY_BUFFER) self.assertEqual(len(buffer._pending_data), 1) buffer.set_data(data) self.assertEqual(len(buffer._pending_data), 1) buffer.set_subdata(0, data[:50]) self.assertEqual(len(buffer._pending_data), 2) buffer.set_data(data) self.assertEqual(len(buffer._pending_data), 1)
def test_wrong_data(self): buffer = Buffer(target=gl.GL_ARRAY_BUFFER) # String with self.assertRaises(ValueError): buffer.set_data('foo') # Bytes some_bytes = 'foo'.encode('utf-8') with self.assertRaises(ValueError): buffer.set_data(some_bytes) # Now with subdata data = np.zeros(100, np.float32) buffer.set_data(data) # String with self.assertRaises(ValueError): buffer.set_subdata(0, 'foo') with self.assertRaises(ValueError): buffer.set_subdata('foo', data) # Bytes some_bytes = 'foo'.encode('utf-8') with self.assertRaises(ValueError): buffer.set_subdata(0, some_bytes) with self.assertRaises(ValueError): buffer.set_subdata(some_bytes, data)
def test_data_copy(self): data = np.zeros(100) B = Buffer(data=data) B.set_data(data=data[:50], offset=0, copy=True) assert B._pending_data[-1][0].base is not data
def test_data_storage(self): data = np.zeros(100) B = Buffer(data=data) B.set_data(data=data[:50], offset=0, copy=False) assert B._pending_data[-1][0].base is data
def test_set_whole_data(self): data = np.zeros(100) B = Buffer(data=data) B.set_data(data=data) assert len(B._pending_data) == 1
def test_data_copy(self): data = np.zeros(100) B = Buffer(data=data) B.set_data(data=data[:50], copy=True) assert B._pending_data[-1][0].base is not data
def test_data_storage(self): data = np.zeros(100) B = Buffer(data=data) B.set_data(data=data[:50], copy=False) assert B._pending_data[-1][0].base is data
def test_buffer_resize(self): data = np.zeros(10) B = Buffer(data=data) data = np.zeros(20) B.set_data(data) assert B.nbytes == data.nbytes
def test_data_storage(self): data = np.zeros(100) B = Buffer(data=data) B.set_data(data=data[:50], copy=False) glir_cmd = B._glir.clear()[-1] assert glir_cmd[-1].base is data
def test_data_storage(self): data = np.zeros(100) B = Buffer(data=data) B.set_data(data=data[:50], copy=False) glir_cmd = B._context.glir.clear()[-1] assert glir_cmd[-1].base is data