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

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

#countcontent
1n/a"""
2n/aGeneric framework path manipulation
3n/a"""
4n/a
5n/aimport re
6n/a
7n/a__all__ = ['framework_info']
8n/a
9n/aSTRICT_FRAMEWORK_RE = re.compile(r"""(?x)
10n/a(?P<location>^.*)(?:^|/)
11n/a(?P<name>
12n/a (?P<shortname>\w+).framework/
13n/a (?:Versions/(?P<version>[^/]+)/)?
14n/a (?P=shortname)
15n/a (?:_(?P<suffix>[^_]+))?
16n/a)$
17n/a""")
18n/a
19n/adef framework_info(filename):
20n/a """
21n/a A framework name can take one of the following four forms:
22n/a Location/Name.framework/Versions/SomeVersion/Name_Suffix
23n/a Location/Name.framework/Versions/SomeVersion/Name
24n/a Location/Name.framework/Name_Suffix
25n/a Location/Name.framework/Name
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.framework/Versions/SomeVersion/Name_Suffix',
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_framework = STRICT_FRAMEWORK_RE.match(filename)
40n/a if not is_framework:
41n/a return None
42n/a return is_framework.groupdict()
43n/a
44n/adef test_framework_info():
45n/a def d(location=None, name=None, shortname=None, version=None, suffix=None):
46n/a return dict(
47n/a location=location,
48n/a name=name,
49n/a shortname=shortname,
50n/a version=version,
51n/a suffix=suffix
52n/a )
53n/a assert framework_info('completely/invalid') is None
54n/a assert framework_info('completely/invalid/_debug') is None
55n/a assert framework_info('P/F.framework') is None
56n/a assert framework_info('P/F.framework/_debug') is None
57n/a assert framework_info('P/F.framework/F') == d('P', 'F.framework/F', 'F')
58n/a assert framework_info('P/F.framework/F_debug') == d('P', 'F.framework/F_debug', 'F', suffix='debug')
59n/a assert framework_info('P/F.framework/Versions') is None
60n/a assert framework_info('P/F.framework/Versions/A') is None
61n/a assert framework_info('P/F.framework/Versions/A/F') == d('P', 'F.framework/Versions/A/F', 'F', 'A')
62n/a assert framework_info('P/F.framework/Versions/A/F_debug') == d('P', 'F.framework/Versions/A/F_debug', 'F', 'A', 'debug')
63n/a
64n/aif __name__ == '__main__':
65n/a test_framework_info()