ยปCore Development>Code coverage>Lib/ctypes/test/test_macholib.py

Python code coverage for Lib/ctypes/test/test_macholib.py

#countcontent
1n/aimport os
2n/aimport sys
3n/aimport unittest
4n/a
5n/a# Bob Ippolito:
6n/a#
7n/a# Ok.. the code to find the filename for __getattr__ should look
8n/a# something like:
9n/a#
10n/a# import os
11n/a# from macholib.dyld import dyld_find
12n/a#
13n/a# def find_lib(name):
14n/a# possible = ['lib'+name+'.dylib', name+'.dylib',
15n/a# name+'.framework/'+name]
16n/a# for dylib in possible:
17n/a# try:
18n/a# return os.path.realpath(dyld_find(dylib))
19n/a# except ValueError:
20n/a# pass
21n/a# raise ValueError, "%s not found" % (name,)
22n/a#
23n/a# It'll have output like this:
24n/a#
25n/a# >>> find_lib('pthread')
26n/a# '/usr/lib/libSystem.B.dylib'
27n/a# >>> find_lib('z')
28n/a# '/usr/lib/libz.1.dylib'
29n/a# >>> find_lib('IOKit')
30n/a# '/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit'
31n/a#
32n/a# -bob
33n/a
34n/afrom ctypes.macholib.dyld import dyld_find
35n/a
36n/adef find_lib(name):
37n/a possible = ['lib'+name+'.dylib', name+'.dylib', name+'.framework/'+name]
38n/a for dylib in possible:
39n/a try:
40n/a return os.path.realpath(dyld_find(dylib))
41n/a except ValueError:
42n/a pass
43n/a raise ValueError("%s not found" % (name,))
44n/a
45n/aclass MachOTest(unittest.TestCase):
46n/a @unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test')
47n/a def test_find(self):
48n/a
49n/a self.assertEqual(find_lib('pthread'),
50n/a '/usr/lib/libSystem.B.dylib')
51n/a
52n/a result = find_lib('z')
53n/a # Issue #21093: dyld default search path includes $HOME/lib and
54n/a # /usr/local/lib before /usr/lib, which caused test failures if
55n/a # a local copy of libz exists in one of them. Now ignore the head
56n/a # of the path.
57n/a self.assertRegex(result, r".*/lib/libz\..*.*\.dylib")
58n/a
59n/a self.assertEqual(find_lib('IOKit'),
60n/a '/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit')
61n/a
62n/aif __name__ == "__main__":
63n/a unittest.main()