PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/Lib/ctypes/test/test_macholib.py

http://unladen-swallow.googlecode.com/
Python | 62 lines | 44 code | 4 blank | 14 comment | 0 complexity | 4f4dea17e8fa8a8ae2a7bc62c752ae3c MD5 | raw file
 1import os
 2import sys
 3import unittest
 4
 5# Bob Ippolito:
 6"""
 7Ok.. the code to find the filename for __getattr__ should look
 8something like:
 9
10import os
11from macholib.dyld import dyld_find
12
13def find_lib(name):
14     possible = ['lib'+name+'.dylib', name+'.dylib',
15     name+'.framework/'+name]
16     for dylib in possible:
17         try:
18             return os.path.realpath(dyld_find(dylib))
19         except ValueError:
20             pass
21     raise ValueError, "%s not found" % (name,)
22
23It'll have output like this:
24
25 >>> find_lib('pthread')
26'/usr/lib/libSystem.B.dylib'
27 >>> find_lib('z')
28'/usr/lib/libz.1.dylib'
29 >>> find_lib('IOKit')
30'/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit'
31
32-bob
33
34"""
35
36from ctypes.macholib.dyld import dyld_find
37
38def find_lib(name):
39    possible = ['lib'+name+'.dylib', name+'.dylib', name+'.framework/'+name]
40    for dylib in possible:
41        try:
42            return os.path.realpath(dyld_find(dylib))
43        except ValueError:
44            pass
45    raise ValueError("%s not found" % (name,))
46
47class MachOTest(unittest.TestCase):
48    if sys.platform == "darwin":
49        def test_find(self):
50
51            self.failUnlessEqual(find_lib('pthread'),
52                                 '/usr/lib/libSystem.B.dylib')
53
54            result = find_lib('z')
55            self.failUnless(result.startswith('/usr/lib/libz.1'))
56            self.failUnless(result.endswith('.dylib'))
57
58            self.failUnlessEqual(find_lib('IOKit'),
59                                 '/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit')
60
61if __name__ == "__main__":
62    unittest.main()