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

* Move tests from ctypes.macholib.dy* to ctypes.test
This commit is contained in:
Oleg Iarygin 2022-04-18 10:27:09 +03:00 committed by GitHub
parent 4c3b283e83
commit 804ea2da97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 52 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -32,6 +32,8 @@ import unittest
# -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]
@ -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
@ -62,5 +75,36 @@ class MachOTest(unittest.TestCase):
('/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()

View File

@ -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.