Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-91265: Make old ctypes.macholib tests runned by python -m test #32094

Merged
merged 5 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Lib/ctypes/macholib/dyld.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,3 @@ def framework_find(fn, executable_path=None, env=None):
raise error
finally:
error = None

def test_dyld_find():
env = {}
assert dyld_find('libSystem.dylib') == '/usr/lib/libSystem.dylib'
assert dyld_find('System.framework/System') == '/System/Library/Frameworks/System.framework/System'

if __name__ == '__main__':
test_dyld_find()
21 changes: 0 additions & 21 deletions Lib/ctypes/macholib/dylib.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,3 @@ def dylib_info(filename):
if not is_dylib:
return None
return is_dylib.groupdict()


def test_dylib_info():
def d(location=None, name=None, shortname=None, version=None, suffix=None):
return dict(
location=location,
name=name,
shortname=shortname,
version=version,
suffix=suffix
)
assert dylib_info('completely/invalid') is None
assert dylib_info('completely/invalide_debug') is None
assert dylib_info('P/Foo.dylib') == d('P', 'Foo.dylib', 'Foo')
assert dylib_info('P/Foo_debug.dylib') == d('P', 'Foo_debug.dylib', 'Foo', suffix='debug')
assert dylib_info('P/Foo.A.dylib') == d('P', 'Foo.A.dylib', 'Foo', 'A')
assert dylib_info('P/Foo_debug.A.dylib') == d('P', 'Foo_debug.A.dylib', 'Foo_debug', 'A')
assert dylib_info('P/Foo.A_debug.dylib') == d('P', 'Foo.A_debug.dylib', 'Foo', 'A', 'debug')

if __name__ == '__main__':
test_dylib_info()
23 changes: 0 additions & 23 deletions Lib/ctypes/macholib/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,3 @@ def framework_info(filename):
if not is_framework:
return None
return is_framework.groupdict()

def test_framework_info():
def d(location=None, name=None, shortname=None, version=None, suffix=None):
return dict(
location=location,
name=name,
shortname=shortname,
version=version,
suffix=suffix
)
assert framework_info('completely/invalid') is None
assert framework_info('completely/invalid/_debug') is None
assert framework_info('P/F.framework') is None
assert framework_info('P/F.framework/_debug') is None
assert framework_info('P/F.framework/F') == d('P', 'F.framework/F', 'F')
assert framework_info('P/F.framework/F_debug') == d('P', 'F.framework/F_debug', 'F', suffix='debug')
assert framework_info('P/F.framework/Versions') is None
assert framework_info('P/F.framework/Versions/A') is None
assert framework_info('P/F.framework/Versions/A/F') == d('P', 'F.framework/Versions/A/F', 'F', 'A')
assert framework_info('P/F.framework/Versions/A/F_debug') == d('P', 'F.framework/Versions/A/F_debug', 'F', 'A', 'debug')

if __name__ == '__main__':
test_framework_info()
44 changes: 44 additions & 0 deletions Lib/ctypes/test/test_macholib.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# -bob

from ctypes.macholib.dyld import dyld_find
from ctypes.macholib.dylib import dylib_info
from ctypes.macholib.framework import framework_info

def find_lib(name):
possible = ['lib'+name+'.dylib', name+'.dylib', name+'.framework/'+name]
Expand All @@ -42,9 +44,20 @@ def find_lib(name):
pass
raise ValueError("%s not found" % (name,))


def d(location=None, name=None, shortname=None, version=None, suffix=None):
return {'location': location, 'name': name, 'shortname': shortname,
'version': version, 'suffix': suffix}


class MachOTest(unittest.TestCase):
@unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test')
def test_find(self):
self.assertEqual(dyld_find('libSystem.dylib'),
'/usr/lib/libSystem.dylib')
self.assertEqual(dyld_find('System.framework/System'),
'/System/Library/Frameworks/System.framework/System')

# On Mac OS 11, system dylibs are only present in the shared cache,
# so symlinks like libpthread.dylib -> libSystem.B.dylib will not
# be resolved by dyld_find
Expand All @@ -62,5 +75,36 @@ def test_find(self):
('/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit',
'/System/Library/Frameworks/IOKit.framework/IOKit'))

@unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test')
def test_info(self):
self.assertIsNone(dylib_info('completely/invalid'))
self.assertIsNone(dylib_info('completely/invalide_debug'))
self.assertEqual(dylib_info('P/Foo.dylib'), d('P', 'Foo.dylib', 'Foo'))
self.assertEqual(dylib_info('P/Foo_debug.dylib'),
d('P', 'Foo_debug.dylib', 'Foo', suffix='debug'))
self.assertEqual(dylib_info('P/Foo.A.dylib'),
d('P', 'Foo.A.dylib', 'Foo', 'A'))
self.assertEqual(dylib_info('P/Foo_debug.A.dylib'),
d('P', 'Foo_debug.A.dylib', 'Foo_debug', 'A'))
self.assertEqual(dylib_info('P/Foo.A_debug.dylib'),
d('P', 'Foo.A_debug.dylib', 'Foo', 'A', 'debug'))

@unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test')
def test_framework_info(self):
self.assertIsNone(framework_info('completely/invalid'))
self.assertIsNone(framework_info('completely/invalid/_debug'))
self.assertIsNone(framework_info('P/F.framework'))
self.assertIsNone(framework_info('P/F.framework/_debug'))
self.assertEqual(framework_info('P/F.framework/F'),
d('P', 'F.framework/F', 'F'))
self.assertEqual(framework_info('P/F.framework/F_debug'),
d('P', 'F.framework/F_debug', 'F', suffix='debug'))
self.assertIsNone(framework_info('P/F.framework/Versions'))
self.assertIsNone(framework_info('P/F.framework/Versions/A'))
self.assertEqual(framework_info('P/F.framework/Versions/A/F'),
d('P', 'F.framework/Versions/A/F', 'F', 'A'))
self.assertEqual(framework_info('P/F.framework/Versions/A/F_debug'),
d('P', 'F.framework/Versions/A/F_debug', 'F', 'A', 'debug'))

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Test for :mod:`ctypes.macholib.dyld`, :mod:`ctypes.macholib.dylib`, and
:mod:`ctypes.macholib.framework` are brought from manual pre-:mod:`unittest`
times to :mod:`ctypes.test` location and structure. Patch by Oleg Iarygin.