diff options
author | Oleg Iarygin <oleg@arhadthedev.net> | 2022-04-18 07:27:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-18 07:27:09 (GMT) |
commit | 804ea2da97af68366cdeceb30d3987f6d9f3e797 (patch) | |
tree | 7c70a27a78cec7d245ac4afdc3c8f06da1c18f66 /Lib/ctypes | |
parent | 4c3b283e83459cf7224bbf353300099eba7a2c1c (diff) | |
download | cpython-804ea2da97af68366cdeceb30d3987f6d9f3e797.zip cpython-804ea2da97af68366cdeceb30d3987f6d9f3e797.tar.gz cpython-804ea2da97af68366cdeceb30d3987f6d9f3e797.tar.bz2 |
gh-91265: Make old ctypes.macholib tests runned by `python -m test` (gh-32094)
* Move tests from ctypes.macholib.dy* to ctypes.test
Diffstat (limited to 'Lib/ctypes')
-rw-r--r-- | Lib/ctypes/macholib/dyld.py | 8 | ||||
-rw-r--r-- | Lib/ctypes/macholib/dylib.py | 21 | ||||
-rw-r--r-- | Lib/ctypes/macholib/framework.py | 23 | ||||
-rw-r--r-- | Lib/ctypes/test/test_macholib.py | 44 |
4 files changed, 44 insertions, 52 deletions
diff --git a/Lib/ctypes/macholib/dyld.py b/Lib/ctypes/macholib/dyld.py index 1c3f8fd..583c47d 100644 --- a/Lib/ctypes/macholib/dyld.py +++ b/Lib/ctypes/macholib/dyld.py @@ -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() diff --git a/Lib/ctypes/macholib/dylib.py b/Lib/ctypes/macholib/dylib.py index aa10750..0ad4cba 100644 --- a/Lib/ctypes/macholib/dylib.py +++ b/Lib/ctypes/macholib/dylib.py @@ -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() diff --git a/Lib/ctypes/macholib/framework.py b/Lib/ctypes/macholib/framework.py index ad6ed55..495679f 100644 --- a/Lib/ctypes/macholib/framework.py +++ b/Lib/ctypes/macholib/framework.py @@ -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() diff --git a/Lib/ctypes/test/test_macholib.py b/Lib/ctypes/test/test_macholib.py index a1bac26..bc75f1a 100644 --- a/Lib/ctypes/test/test_macholib.py +++ b/Lib/ctypes/test/test_macholib.py @@ -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() |