ยปCore Development>Code coverage>Lib/ctypes/macholib/dylib.py

Python code coverage for Lib/ctypes/macholib/dylib.py

#countcontent
1n/a"""
2n/aGeneric dylib path manipulation
3n/a"""
4n/a
5n/aimport re
6n/a
7n/a__all__ = ['dylib_info']
8n/a
9n/aDYLIB_RE = re.compile(r"""(?x)
10n/a(?P<location>^.*)(?:^|/)
11n/a(?P<name>
12n/a (?P<shortname>\w+?)
13n/a (?:\.(?P<version>[^._]+))?
14n/a (?:_(?P<suffix>[^._]+))?
15n/a \.dylib$
16n/a)
17n/a""")
18n/a
19n/adef dylib_info(filename):
20n/a """
21n/a A dylib name can take one of the following four forms:
22n/a Location/Name.SomeVersion_Suffix.dylib
23n/a Location/Name.SomeVersion.dylib
24n/a Location/Name_Suffix.dylib
25n/a Location/Name.dylib
26n/a
27n/a returns None if not found or a mapping equivalent to:
28n/a dict(
29n/a location='Location',
30n/a name='Name.SomeVersion_Suffix.dylib',
31n/a shortname='Name',
32n/a version='SomeVersion',
33n/a suffix='Suffix',
34n/a )
35n/a
36n/a Note that SomeVersion and Suffix are optional and may be None
37n/a if not present.
38n/a """
39n/a is_dylib = DYLIB_RE.match(filename)
40n/a if not is_dylib:
41n/a return None
42n/a return is_dylib.groupdict()
43n/a
44n/a
45n/adef test_dylib_info():
46n/a def d(location=None, name=None, shortname=None, version=None, suffix=None):
47n/a return dict(
48n/a location=location,
49n/a name=name,
50n/a shortname=shortname,
51n/a version=version,
52n/a suffix=suffix
53n/a )
54n/a assert dylib_info('completely/invalid') is None
55n/a assert dylib_info('completely/invalide_debug') is None
56n/a assert dylib_info('P/Foo.dylib') == d('P', 'Foo.dylib', 'Foo')
57n/a assert dylib_info('P/Foo_debug.dylib') == d('P', 'Foo_debug.dylib', 'Foo', suffix='debug')
58n/a assert dylib_info('P/Foo.A.dylib') == d('P', 'Foo.A.dylib', 'Foo', 'A')
59n/a assert dylib_info('P/Foo_debug.A.dylib') == d('P', 'Foo_debug.A.dylib', 'Foo_debug', 'A')
60n/a assert dylib_info('P/Foo.A_debug.dylib') == d('P', 'Foo.A_debug.dylib', 'Foo', 'A', 'debug')
61n/a
62n/aif __name__ == '__main__':
63n/a test_dylib_info()