14
0

Accepting request 880827 from home:bnavigator:branches:devel:languages:python

- Don't build the numpy formathandler for python36.
  NumPy is optional and not available for python36 on Tumbleweed.
- Add test files test_arraydatatypeaccel.py and test_numpyaccel.py

OBS-URL: https://build.opensuse.org/request/show/880827
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-opengl-accelerate?expand=0&rev=16
This commit is contained in:
2021-03-24 11:29:43 +00:00
committed by Git OBS Bridge
parent 7cad447b1a
commit 3cc675ad6e
4 changed files with 221 additions and 3 deletions

View File

@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Mar 23 20:48:03 UTC 2021 - Ben Greiner <code@bnavigator.de>
- Don't build the numpy formathandler for python36.
NumPy is optional and not available for python36 on Tumbleweed.
- Add test files test_arraydatatypeaccel.py and test_numpyaccel.py
-------------------------------------------------------------------
Fri Jul 17 21:57:47 UTC 2020 - Markus Ebner <info@ebner-markus.de>

View File

@@ -1,7 +1,7 @@
#
# spec file for package python-opengl-accelerate
#
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -27,14 +27,19 @@ License: BSD-3-Clause
Group: Development/Libraries/Python
URL: http://pyopengl.sourceforge.net
Source0: https://files.pythonhosted.org/packages/source/P/%{tarname}/%{tarname}-%{_version}.tar.gz
# test files: GitHub repo has no tags, use commit hash
Source1: https://github.com/mcfletch/pyopengl/raw/6ec398da44/accelerate/tests/test_arraydatatypeaccel.py
Source2: https://github.com/mcfletch/pyopengl/raw/6ec398da44/accelerate/tests/test_numpyaccel.py
BuildRequires: %{python_module Cython}
BuildRequires: %{python_module devel}
BuildRequires: %{python_module numpy-devel}
BuildRequires: %{python_module opengl >= %{version}}
BuildRequires: %{python_module pytest}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Requires: python-numpy
BuildRequires: %{python_module numpy-devel if (%python-base without python36-base)}
Recommends: python-numpy
Requires: python-opengl >= %{version}
Provides: python-PyOpenGL_accelerate = %{version}-%{release}
%python_subpackages
%description
@@ -57,6 +62,9 @@ export CFLAGS="%{optflags} -DGLX_GLXEXT_LEGACY"
%python_install
%python_expand %fdupes %{buildroot}%{$python_sitearch}
%check
%pytest_arch %{SOURCE1} %{SOURCE2}
%files %{python_files}
%license license.txt
%doc README.txt

107
test_arraydatatypeaccel.py Normal file
View File

@@ -0,0 +1,107 @@
import unittest, ctypes
from OpenGL.arrays import arraydatatype as adt
from OpenGL.arrays import vbo
from OpenGL import GL
from OpenGL._bytes import integer_types
try:
import numpy
except ImportError:
numpy = None
class _BaseTest( object ):
def setUp( self ):
self.handler = adt.ArrayDatatype
assert self.handler.isAccelerated
def test_from_param( self ):
p = self.handler.from_param( self.array )
assert isinstance( p, ctypes.c_void_p )
def test_dataPointer( self ):
p = self.handler.dataPointer( self.array )
assert isinstance( p, integer_types)
def test_arraySize( self ):
p = self.handler.arraySize( self.array )
assert p == 6, p
def test_arrayByteCount( self ):
p = self.handler.arrayByteCount( self.array )
assert p == 24, p
def test_asArray( self ):
p = self.handler.asArray( self.array )
assert p is self.array
def test_unitSize( self ):
p = self.handler.unitSize( self.array )
assert p == 3, p
def test_dimensions( self ):
p = self.handler.dimensions( self.array )
assert p == (2,3), p
def test_arrayToGLType( self ):
p = self.handler.arrayToGLType( self.array )
assert p == GL.GL_FLOAT
if numpy:
# Skip if modifies the functions, which are *shared* between the
# classes...
#@pytest.mark.skipif( not numpy, reason="Numpy not available")
class TestNumpy( _BaseTest, unittest.TestCase ):
def setUp( self ):
self.array = numpy.array( [[1,2,3],[4,5,6]],'f')
super(TestNumpy,self).setUp()
def test_dataPointer( self ):
p = self.handler.dataPointer( self.array )
assert isinstance( p, integer_types)
assert p == self.array.ctypes.data
def test_zeros( self ):
p = self.handler.zeros( (2,3,4), 'f' )
assert p.shape == (2,3,4)
assert p.dtype == numpy.float32
def test_asArrayConvert( self ):
p = self.handler.asArray( self.array, GL.GL_DOUBLE )
assert p is not self.array
assert p.dtype == numpy.float64
p = self.handler.asArray( self.array, 'd' )
assert p is not self.array
assert p.dtype == numpy.float64
def test_zeros_typed( self ):
z = self.handler.zeros( (2,3,4), GL.GL_FLOAT)
assert z.shape == (2,3,4)
assert z.dtype == numpy.float32
def test_downconvert( self ):
p = self.handler.asArray( numpy.array( [1,2,3],'d'), GL.GL_FLOAT )
assert p.dtype == numpy.float32
def test_zeros_small( self ):
z = self.handler.zeros( 0, GL.GL_BYTE )
assert z.dtype == numpy.byte, z
class TestVBO( _BaseTest, unittest.TestCase ):
def setUp( self ):
if numpy:
self.array = vbo.VBO(numpy.array( [[1,2,3],[4,5,6]],'f'))
else:
self.array = vbo.VBO(adt.GLfloatArray.asArray([[1,2,3],[4,5,6]]))
super(TestVBO,self).setUp()
class TestVBOOffset( _BaseTest, unittest.TestCase ):
def setUp( self ):
if numpy:
self.array = vbo.VBO(numpy.array( [[1,2,3],[4,5,6]],'f')) + 12
else:
self.array = vbo.VBO(adt.GLfloatArray.asArray([[1,2,3],[4,5,6]])) + 12
super(TestVBOOffset,self).setUp()
class TestNones( unittest.TestCase ):
def setUp( self ):
self.array = None
self.handler = adt.ArrayDatatype
assert self.handler.isAccelerated
def test_from_param( self ):
p = self.handler.from_param( self.array )
assert p is None, p
def test_dataPointer( self ):
p = self.handler.dataPointer( self.array )
assert p is None
def test_asArray( self ):
p = self.handler.asArray( self.array )
assert p is self.array
def test_dimensions( self ):
p = self.handler.dimensions( self.array )
assert p == (0,), p

96
test_numpyaccel.py Normal file
View File

@@ -0,0 +1,96 @@
import unittest, ctypes
try:
import numpy
from OpenGL_accelerate import numpy_formathandler as npf
except ImportError:
numpy = None
npf = None
try:
from OpenGL_accelerate import buffers_formathandler as bpf
except ImportError:
bpf = None
from OpenGL import error
from OpenGL import GL
from OpenGL._bytes import integer_types
from OpenGL._configflags import ERROR_ON_COPY
import pytest
pytestmark = pytest.mark.skipif(not numpy, reason="No numpy installed in order to run tests")
class _AccelArray( object ):
handler_class = None
def setUp( self ):
self.array = numpy.array( [[1,2,3],[4,5,6]],'f')
self.handler = self.handler_class()
def test_from_param( self ):
p = self.handler.from_param( self.handler.asArray(self.array ))
assert isinstance( p, ctypes.c_void_p )
def test_dataPointer( self ):
p = self.handler.dataPointer( self.array )
assert isinstance( p, integer_types)
assert p == self.array.ctypes.data
def test_arraySize( self ):
p = self.handler.arraySize( self.array )
assert p == 6, p
def test_arrayByteCount( self ):
p = self.handler.arrayByteCount( self.array )
assert p == 24, p
def test_unitSize( self ):
p = self.handler.unitSize( self.array )
assert p == 3, p
def test_dimensions( self ):
p = self.handler.dimensions( self.array )
assert p == (2,3), p
def test_arrayToGLType( self ):
p = self.handler.arrayToGLType( self.array )
assert p == GL.GL_FLOAT
@pytest.mark.skipif(not npf,reason="No numpy native format handler available")
class TestNumpyNative(_AccelArray,unittest.TestCase):
handler_class = getattr(npf,'NumpyHandler',None)
def setUp(self):
super(TestNumpyNative,self).setUp()
self.eoc_handler = self.handler_class( True )
def test_asArray( self ):
p = self.handler.asArray( self.array )
assert p is self.array
def test_downconvert( self ):
p = self.handler.asArray( numpy.array( [1,2,3],'d'), GL.GL_FLOAT )
assert p.dtype == numpy.float32
def test_zeros_constant( self ):
z = self.handler.zeros( (2,3,4), GL.GL_FLOAT)
assert z.shape == (2,3,4)
assert z.dtype == numpy.float32
def test_zeros( self ):
p = self.handler.zeros( (2,3,4), 'f' )
assert p.shape == (2,3,4)
assert p.dtype == numpy.float32
def test_asArrayCopy( self ):
a2 = self.array[:,0]
assert not a2.flags.contiguous
self.assertRaises(
error.CopyError,
self.eoc_handler.asArray,
a2
)
def test_asArrayConvert( self ):
self.failUnlessRaises(
error.CopyError,
self.eoc_handler.asArray,
self.array, GL.GL_DOUBLE
)
def test_asArrayConvert( self ):
p = self.handler.asArray( self.array, GL.GL_DOUBLE )
assert p is not self.array
assert p.dtype == numpy.float64
p = self.handler.asArray( self.array, 'd' )
assert p is not self.array
assert p.dtype == numpy.float64
@pytest.mark.skipif(not npf,reason="No numpy native format handler available")
class TestBufferAPI(_AccelArray,unittest.TestCase):
handler_class = getattr(bpf,'MemoryviewHandler',None)