File: test_find.py

package info (click to toggle)
python2.7 2.7.9-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 73,812 kB
  • sloc: python: 440,005; ansic: 438,254; sh: 17,372; asm: 14,304; makefile: 4,744; objc: 761; exp: 499; cpp: 128; xml: 73
file content (83 lines) | stat: -rw-r--r-- 2,560 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import unittest
import os
import sys
from ctypes import *
from ctypes.util import find_library
from ctypes.test import is_resource_enabled

if sys.platform == "win32":
    lib_gl = find_library("OpenGL32")
    lib_glu = find_library("Glu32")
    lib_gle = None
elif sys.platform == "darwin":
    lib_gl = lib_glu = find_library("OpenGL")
    lib_gle = None
else:
    lib_gl = find_library("GL")
    lib_glu = find_library("GLU")
    lib_gle = find_library("gle")

## print, for debugging
if is_resource_enabled("printing"):
    if lib_gl or lib_glu or lib_gle:
        print "OpenGL libraries:"
        for item in (("GL", lib_gl),
                     ("GLU", lib_glu),
                     ("gle", lib_gle)):
            print "\t", item


# On some systems, loading the OpenGL libraries needs the RTLD_GLOBAL mode.
class Test_OpenGL_libs(unittest.TestCase):
    def setUp(self):
        self.gl = self.glu = self.gle = None
        if lib_gl:
            self.gl = CDLL(lib_gl, mode=RTLD_GLOBAL)
        if lib_glu:
            self.glu = CDLL(lib_glu, RTLD_GLOBAL)
        if lib_gle:
            try:
                self.gle = CDLL(lib_gle)
            except OSError:
                pass

    @unittest.skipUnless(lib_gl, 'lib_gl not available')
    def test_gl(self):
        if self.gl:
            self.gl.glClearIndex

    @unittest.skipUnless(lib_glu, 'lib_glu not available')
    def test_glu(self):
        if self.glu:
            self.glu.gluBeginCurve

    @unittest.skipUnless(lib_gle, 'lib_gle not available')
    def test_gle(self):
        if self.gle:
            self.gle.gleGetJoinStyle

# On platforms where the default shared library suffix is '.so',
# at least some libraries can be loaded as attributes of the cdll
# object, since ctypes now tries loading the lib again
# with '.so' appended of the first try fails.
#
# Won't work for libc, unfortunately.  OTOH, it isn't
# needed for libc since this is already mapped into the current
# process (?)
#
# On MAC OSX, it won't work either, because dlopen() needs a full path,
# and the default suffix is either none or '.dylib'.
@unittest.skip('test disabled')
@unittest.skipUnless(os.name=="posix" and sys.platform != "darwin",
                     'test not suitable for this platform')
class LoadLibs(unittest.TestCase):
    def test_libm(self):
        import math
        libm = cdll.libm
        sqrt = libm.sqrt
        sqrt.argtypes = (c_double,)
        sqrt.restype = c_double
        self.assertEqual(sqrt(2), math.sqrt(2))

if __name__ == "__main__":
    unittest.main()