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

Delta Between Two Patch Sets: Lib/ctypes/test/test_find.py

Issue 21042: ctypes.util.find_library() should return full pathname instead of filename in linux
Left Patch Set: Created 3 years, 4 months ago
Right Patch Set: Created 3 years, 4 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/ctypes.rst ('k') | Lib/ctypes/util.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 66
67 def test_abspath(self): 67 def test_abspath(self):
68 lib_gl = lib_glu = lib_gle = None 68 if self.lib_gl:
Martin Panter 2016/02/22 00:45:15 I would change setUpClass() to save all these in c
69 if sys.platform == "win32": 69 self.assertTrue(os.path.isabs(self.lib_gl))
70 lib_gl = find_library("OpenGL32") 70 if self.lib_glu:
71 lib_glu = find_library("Glu32") 71 self.assertTrue(os.path.isabs(self.lib_glu))
72 elif sys.platform == "darwin": 72 if self.lib_gle:
73 lib_gl = lib_glu = find_library("OpenGL") 73 self.assertTrue(os.path.isabs(self.lib_gle))
74 else:
75 lib_gl = find_library("GL")
76 lib_glu = find_library("GLU")
77 lib_gle = find_library("gle")
78
79 if lib_gl:
80 self.assertTrue(os.path.isabs(lib_gl))
81 if lib_glu:
82 self.assertTrue(os.path.isabs(lib_glu))
83 if lib_gle:
84 self.assertTrue(os.path.isabs(lib_gle))
85 74
86 # On platforms where the default shared library suffix is '.so', 75 # On platforms where the default shared library suffix is '.so',
87 # 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
88 # object, since ctypes now tries loading the lib again 77 # object, since ctypes now tries loading the lib again
89 # with '.so' appended of the first try fails. 78 # with '.so' appended of the first try fails.
90 # 79 #
91 # Won't work for libc, unfortunately. OTOH, it isn't 80 # Won't work for libc, unfortunately. OTOH, it isn't
92 # needed for libc since this is already mapped into the current 81 # needed for libc since this is already mapped into the current
93 # process (?) 82 # process (?)
94 # 83 #
95 # 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,
96 # and the default suffix is either none or '.dylib'. 85 # and the default suffix is either none or '.dylib'.
97 @unittest.skip('test disabled') 86 @unittest.skip('test disabled')
98 @unittest.skipUnless(os.name=="posix" and sys.platform != "darwin", 87 @unittest.skipUnless(os.name=="posix" and sys.platform != "darwin",
99 'test not suitable for this platform') 88 'test not suitable for this platform')
100 class LoadLibs(unittest.TestCase): 89 class LoadLibs(unittest.TestCase):
101 def test_libm(self): 90 def test_libm(self):
102 import math 91 import math
103 libm = cdll.libm 92 libm = cdll.libm
104 sqrt = libm.sqrt 93 sqrt = libm.sqrt
105 sqrt.argtypes = (c_double,) 94 sqrt.argtypes = (c_double,)
106 sqrt.restype = c_double 95 sqrt.restype = c_double
107 self.assertEqual(sqrt(2), math.sqrt(2)) 96 self.assertEqual(sqrt(2), math.sqrt(2))
108 97
109 if __name__ == "__main__": 98 if __name__ == "__main__":
110 unittest.main() 99 unittest.main()
LEFTRIGHT

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