Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13478)

Side by Side Diff: Lib/ctypes/test/test_find.py

Issue 21042: ctypes.util.find_library() should return full pathname instead of filename in linux
Patch Set: Created 3 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/library/ctypes.rst ('k') | Lib/ctypes/util.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 import os 2 import os
3 import sys 3 import sys
4 import test.support 4 import test.support
5 from ctypes import * 5 from ctypes import *
6 from ctypes.util import find_library 6 from ctypes.util import find_library
7 7
8 # On some systems, loading the OpenGL libraries needs the RTLD_GLOBAL mode. 8 # On some systems, loading the OpenGL libraries needs the RTLD_GLOBAL mode.
9 class Test_OpenGL_libs(unittest.TestCase): 9 class Test_OpenGL_libs(unittest.TestCase):
10 @classmethod 10 @classmethod
11 def setUpClass(cls): 11 def setUpClass(cls):
12 lib_gl = lib_glu = lib_gle = None 12 cls.lib_gl = cls.lib_glu = cls.lib_gle = None
13 if sys.platform == "win32": 13 if sys.platform == "win32":
14 lib_gl = find_library("OpenGL32") 14 cls.lib_gl = find_library("OpenGL32")
15 lib_glu = find_library("Glu32") 15 cls.lib_glu = find_library("Glu32")
16 elif sys.platform == "darwin": 16 elif sys.platform == "darwin":
17 lib_gl = lib_glu = find_library("OpenGL") 17 cls.lib_gl = cls.lib_glu = find_library("OpenGL")
18 else: 18 else:
19 lib_gl = find_library("GL") 19 cls.lib_gl = find_library("GL")
20 lib_glu = find_library("GLU") 20 cls.lib_glu = find_library("GLU")
21 lib_gle = find_library("gle") 21 cls.lib_gle = find_library("gle")
22 22
23 ## print, for debugging 23 ## print, for debugging
24 if test.support.verbose: 24 if test.support.verbose:
25 print("OpenGL libraries:") 25 print("OpenGL libraries:")
26 for item in (("GL", lib_gl), 26 for item in (("GL", cls.lib_gl),
27 ("GLU", lib_glu), 27 ("GLU", cls.lib_glu),
28 ("gle", lib_gle)): 28 ("gle", cls.lib_gle)):
29 print("\t", item) 29 print("\t", item)
30 30
31 cls.gl = cls.glu = cls.gle = None 31 cls.gl = cls.glu = cls.gle = None
32 if lib_gl: 32 if cls.lib_gl:
33 try: 33 try:
34 cls.gl = CDLL(lib_gl, mode=RTLD_GLOBAL) 34 cls.gl = CDLL(cls.lib_gl, mode=RTLD_GLOBAL)
35 except OSError: 35 except OSError:
36 pass 36 pass
37 if lib_glu: 37 if cls.lib_glu:
38 try: 38 try:
39 cls.glu = CDLL(lib_glu, RTLD_GLOBAL) 39 cls.glu = CDLL(cls.lib_glu, RTLD_GLOBAL)
40 except OSError: 40 except OSError:
41 pass 41 pass
42 if lib_gle: 42 if cls.lib_gle:
43 try: 43 try:
44 cls.gle = CDLL(lib_gle) 44 cls.gle = CDLL(cls.lib_gle)
45 except OSError: 45 except OSError:
46 pass 46 pass
47 47
48 @classmethod 48 @classmethod
49 def tearDownClass(cls): 49 def tearDownClass(cls):
50 cls.gl = cls.glu = cls.gle = None 50 cls.gl = cls.glu = cls.gle = None
51 51
52 def test_gl(self): 52 def test_gl(self):
53 if self.gl is None: 53 if self.gl is None:
54 self.skipTest('lib_gl not available') 54 self.skipTest('lib_gl not available')
55 self.gl.glClearIndex 55 self.gl.glClearIndex
56 56
57 def test_glu(self): 57 def test_glu(self):
58 if self.glu is None: 58 if self.glu is None:
59 self.skipTest('lib_glu not available') 59 self.skipTest('lib_glu not available')
60 self.glu.gluBeginCurve 60 self.glu.gluBeginCurve
61 61
62 def test_gle(self): 62 def test_gle(self):
63 if self.gle is None: 63 if self.gle is None:
64 self.skipTest('lib_gle not available') 64 self.skipTest('lib_gle not available')
65 self.gle.gleGetJoinStyle 65 self.gle.gleGetJoinStyle
66
67 def test_abspath(self):
68 if self.lib_gl:
69 self.assertTrue(os.path.isabs(self.lib_gl))
70 if self.lib_glu:
71 self.assertTrue(os.path.isabs(self.lib_glu))
72 if self.lib_gle:
73 self.assertTrue(os.path.isabs(self.lib_gle))
66 74
67 # On platforms where the default shared library suffix is '.so', 75 # On platforms where the default shared library suffix is '.so',
68 # at least some libraries can be loaded as attributes of the cdll 76 # at least some libraries can be loaded as attributes of the cdll
69 # object, since ctypes now tries loading the lib again 77 # object, since ctypes now tries loading the lib again
70 # with '.so' appended of the first try fails. 78 # with '.so' appended of the first try fails.
71 # 79 #
72 # Won't work for libc, unfortunately. OTOH, it isn't 80 # Won't work for libc, unfortunately. OTOH, it isn't
73 # needed for libc since this is already mapped into the current 81 # needed for libc since this is already mapped into the current
74 # process (?) 82 # process (?)
75 # 83 #
76 # On MAC OSX, it won't work either, because dlopen() needs a full path, 84 # On MAC OSX, it won't work either, because dlopen() needs a full path,
77 # and the default suffix is either none or '.dylib'. 85 # and the default suffix is either none or '.dylib'.
78 @unittest.skip('test disabled') 86 @unittest.skip('test disabled')
79 @unittest.skipUnless(os.name=="posix" and sys.platform != "darwin", 87 @unittest.skipUnless(os.name=="posix" and sys.platform != "darwin",
80 'test not suitable for this platform') 88 'test not suitable for this platform')
81 class LoadLibs(unittest.TestCase): 89 class LoadLibs(unittest.TestCase):
82 def test_libm(self): 90 def test_libm(self):
83 import math 91 import math
84 libm = cdll.libm 92 libm = cdll.libm
85 sqrt = libm.sqrt 93 sqrt = libm.sqrt
86 sqrt.argtypes = (c_double,) 94 sqrt.argtypes = (c_double,)
87 sqrt.restype = c_double 95 sqrt.restype = c_double
88 self.assertEqual(sqrt(2), math.sqrt(2)) 96 self.assertEqual(sqrt(2), math.sqrt(2))
89 97
90 if __name__ == "__main__": 98 if __name__ == "__main__":
91 unittest.main() 99 unittest.main()
OLDNEW
« no previous file with comments | « Doc/library/ctypes.rst ('k') | Lib/ctypes/util.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+