Exemplo n.º 1
0
 def test_MemoryView_ndim_strides(self):
     source = "Example buffer"
     view = sdlextarray.MemoryView(source, 1, (len(source), ))
     assert view.ndim == 1
     assert view.strides == (len(source), )
     view = sdlextarray.MemoryView(source, 1, (2, 7))
     assert view.ndim == 2
     assert view.strides == (2, 7)
     view = sdlextarray.MemoryView(source, 1, (7, 2))
     assert view.ndim == 2
     assert view.strides == (7, 2)
     view = sdlextarray.MemoryView(source, 1, (2, 2, 2))
     assert view.ndim == 3
     assert view.strides == (2, 2, 2)
Exemplo n.º 2
0
 def test_MemoryView_ndim_strides(self):
     source = "Example buffer"
     view = sdlextarray.MemoryView(source, 1, (len(source), ))
     self.assertEqual(view.ndim, 1)
     self.assertEqual(view.strides, (len(source), ))
     view = sdlextarray.MemoryView(source, 1, (2, 7))
     self.assertEqual(view.ndim, 2)
     self.assertEqual(view.strides, (2, 7))
     view = sdlextarray.MemoryView(source, 1, (7, 2))
     self.assertEqual(view.ndim, 2)
     self.assertEqual(view.strides, (7, 2))
     view = sdlextarray.MemoryView(source, 1, (2, 2, 2))
     self.assertEqual(view.ndim, 3)
     self.assertEqual(view.strides, (2, 2, 2))
Exemplo n.º 3
0
    def test_MemoryView(self):
        self.assertRaises(TypeError, sdlextarray.MemoryView, 5, 1, (1, ))
        self.assertRaises(TypeError, sdlextarray.MemoryView, None, 1, (1, ))

        source = "Example buffer"
        view = sdlextarray.MemoryView(source, 1, (len(source), ))
        for index, val in enumerate(view):
            self.assertEqual(val, source[index])

        view = sdlextarray.MemoryView(source, 1, (2, 7))
        word1 = view[0]  # "Example"
        word2 = view[1]  # " buffer"
        self.assertEqual(len(view), 2)
        self.assertEqual(len(word1), 7)
        self.assertEqual(len(word2), 7)
        for index, val in enumerate(word1):
            self.assertEqual(val, source[index])
        for index, val in enumerate(word2):
            self.assertEqual(val, source[index + 7])
Exemplo n.º 4
0
    def test_MemoryView(self):
        with pytest.raises(TypeError):
            sdlextarray.MemoryView(5, 1, (1, ))
        with pytest.raises(TypeError):
            sdlextarray.MemoryView(None, 1, (1, ))

        source = "Example buffer"
        view = sdlextarray.MemoryView(source, 1, (len(source), ))
        for index, val in enumerate(view):
            assert val == source[index]

        view = sdlextarray.MemoryView(source, 1, (2, 7))
        word1 = view[0]  # "Example"
        word2 = view[1]  # " buffer"
        assert len(view) == 2
        assert len(word1) == 7
        assert len(word2) == 7
        for index, val in enumerate(word1):
            assert val == source[index]
        for index, val in enumerate(word2):
            assert val == source[index + 7]
Exemplo n.º 5
0
 def test_MemoryView_source(self):
     source = "Example buffer"
     view = sdlextarray.MemoryView(source, 1, (len(source), ))
     assert view.source == source
Exemplo n.º 6
0
 def test_MemoryView_size(self):
     source = "Example buffer"
     view = sdlextarray.MemoryView(source, 1, (len(source), ))
     assert view.size == len(source)
     view = sdlextarray.MemoryView(source, 7, (1, 7))
     assert view.size == len(source)
Exemplo n.º 7
0
 def test_MemoryView_size(self):
     source = "Example buffer"
     view = sdlextarray.MemoryView(source, 1, (len(source), ))
     self.assertEqual(view.size, len(source))
     view = sdlextarray.MemoryView(source, 7, (1, 7))
     self.assertEqual(view.size, len(source))