Beispiel #1
0
 def test_setitem_wrong(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture(data=data)
     # with self.assertRaises(ValueError):
     #    T[::2, ::2] = 1
     s = slice(None, None, 2)
     self.assertRaises(ValueError, T.__setitem__, (s, s), 1)
Beispiel #2
0
    def test_setitem_single(self):

        data = np.zeros((10, 10), dtype=np.uint8)
        T = Texture(data=data)
        T[0, 0] = 1
        assert len(T._pending_data) == 2
        assert data[0, 0] == 1, 1
Beispiel #3
0
    def test_setitem_partial(self):

        data = np.zeros((10, 10), dtype=np.uint8)
        T = Texture(data=data)
        T[5:, 5:] = 1
        assert len(T._pending_data) == 2
        assert np.allclose(data[5:, 5:], np.ones((5, 5)))
Beispiel #4
0
    def test_setitem_all_no_store(self):

        data = np.zeros((10, 10), dtype=np.uint8)
        T = Texture(data=data, store=False)
        T[...] = np.ones((10, 10), np.uint8)
        assert len(T._pending_data) == 1
        assert np.allclose(data, np.zeros((10, 10)))
Beispiel #5
0
    def test_getitem_setitem(self):

        data = np.zeros((10, 10), dtype=np.uint8)
        T = Texture(data=data)
        Z = T[5:, 5:]
        Z[...] = 1
        assert len(Z._pending_data) == 0
        assert len(T._pending_data) == 2
        assert np.allclose(data[5:, 5:], np.ones((5, 5)))
Beispiel #6
0
    def test_getitem_non_contiguous(self):

        data = np.zeros((10, 10), dtype=np.uint8)
        T = Texture(data=data)
        # with self.assertRaises(ValueError):
        #    Z = T[::2, ::2]
        #    print(Z)
        s = slice(None, None, 2)
        self.assertRaises(ValueError, T.__getitem__, (s, s))
Beispiel #7
0
    def test_getitem_single(self):

        data = np.zeros((10, 10, 10), dtype=np.uint8)
        T = Texture(data=data)
        Z = T[0, 0, 0]
        assert Z._base is T
        assert Z._data.base is T._data
        assert Z._shape == (1, 1, 1)
        assert Z._resizeable is False
        assert len(Z._pending_data) == 0
Beispiel #8
0
 def test_init_dtype(self):
     T = Texture(dtype=np.uint8)
     assert T._shape == ()
     assert T._dtype == np.uint8
     assert T._offset == ()
     assert T._store is True
     assert T._copy is False
     assert T._need_resize is False
     assert T._need_update is False
     assert T._data is not None
     assert len(T._pending_data) == 0
Beispiel #9
0
    def test_getitem_partial(self):

        data = np.zeros((10, 10), dtype=np.uint8)
        T = Texture(data=data)
        Z = T[2:5, 2:5]
        assert Z._base is T
        assert Z._data.base is T._data
        assert Z._shape == (3, 3)
        assert Z._offset == (2, 2)
        assert Z._resizeable is False
        assert len(Z._pending_data) == 0
Beispiel #10
0
 def test_init_data_dtype(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture(data=data, dtype=np.uint16)
     assert T._shape == (10, 10)
     assert T._dtype == np.uint16
     assert T._offset == (0, 0)
     assert T._store is True
     assert T._copy is False
     assert T._need_resize is True
     assert T._need_update is True
     assert T._data is not data
     assert len(T._pending_data) == 1
Beispiel #11
0
 def test_init_non_contiguous_data(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture(data=data[::2, ::2])
     assert T._shape == (5, 5)
     assert T._dtype == np.uint8
     assert T._offset == (0, 0)
     assert T._store is True
     assert T._copy is True
     assert T._need_resize is True
     assert T._need_update is True
     assert T._data is not data
     assert len(T._pending_data) == 1
Beispiel #12
0
 def test_init_data_store(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture(data=data, store=True)
     assert T._data is data
Beispiel #13
0
 def test_init_data_store_copy(self):
     data = np.zeros((10, 10), dtype=np.uint8)
     T = Texture(data=data.copy(), store=True)
     assert T._data is not data
     assert T._data is not None