From 46deb7786f8ea0c19df99417d08638cdc019ff23 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 24 Mar 2022 12:41:34 +0300 Subject: [PATCH 1/4] Move tests from ctypes.macholib.dy* to ctypes.test --- Lib/ctypes/macholib/dyld.py | 8 ------ Lib/ctypes/macholib/dylib.py | 21 ---------------- Lib/ctypes/macholib/framework.py | 23 ----------------- Lib/ctypes/test/test_macholib.py | 42 ++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 52 deletions(-) diff --git a/Lib/ctypes/macholib/dyld.py b/Lib/ctypes/macholib/dyld.py index 1c3f8fd38b0665..583c47daff3ad8 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 aa107507bd4a9a..0ad4cba8da3521 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 ad6ed554ba0c22..495679fff19d41 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 a1bac26a7df058..4950b120116914 100644 --- a/Lib/ctypes/test/test_macholib.py +++ b/Lib/ctypes/test/test_macholib.py @@ -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] @@ -45,6 +47,11 @@ def find_lib(name): 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 +69,40 @@ def test_find(self): ('/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit', '/System/Library/Frameworks/IOKit.framework/IOKit')) + def d(location=None, name=None, shortname=None, version=None, suffix=None): + return {'location': location, 'name': name, 'shortname': shortname, + 'version': version, 'suffix': suffix} + + @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(ramework_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() From d82fb85b514be7fa843ea4b8ad2a3cb14aae07d5 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 24 Mar 2022 13:46:28 +0300 Subject: [PATCH 2/4] Add NEWS --- .../NEWS.d/next/Tests/2022-03-24-13-35-01.bpo-47109.FjKQCE.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2022-03-24-13-35-01.bpo-47109.FjKQCE.rst diff --git a/Misc/NEWS.d/next/Tests/2022-03-24-13-35-01.bpo-47109.FjKQCE.rst b/Misc/NEWS.d/next/Tests/2022-03-24-13-35-01.bpo-47109.FjKQCE.rst new file mode 100644 index 00000000000000..d0a402f3a225d9 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-03-24-13-35-01.bpo-47109.FjKQCE.rst @@ -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. From a2f0811de032a756d07fee93f27d420c6305b3b6 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 24 Mar 2022 13:55:31 +0300 Subject: [PATCH 3/4] Fix compilation errors --- Lib/ctypes/test/test_macholib.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/ctypes/test/test_macholib.py b/Lib/ctypes/test/test_macholib.py index 4950b120116914..4c5ee7cbe34b10 100644 --- a/Lib/ctypes/test/test_macholib.py +++ b/Lib/ctypes/test/test_macholib.py @@ -44,6 +44,12 @@ 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): @@ -69,10 +75,6 @@ def test_find(self): ('/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit', '/System/Library/Frameworks/IOKit.framework/IOKit')) - def d(location=None, name=None, shortname=None, version=None, suffix=None): - return {'location': location, 'name': name, 'shortname': shortname, - 'version': version, 'suffix': suffix} - @unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test') def test_info(self): self.assertIsNone(dylib_info('completely/invalid')) @@ -90,7 +92,7 @@ def test_info(self): @unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test') def test_framework_info(self): self.assertIsNone(framework_info('completely/invalid')) - self.assertIsNone(ramework_info('completely/invalid/_debug')) + 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'), From cf7159cfa37b9f10417672b947c7e2f6339ca0e5 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 24 Mar 2022 14:43:10 +0300 Subject: [PATCH 4/4] Fix overindented function --- Lib/ctypes/test/test_macholib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/ctypes/test/test_macholib.py b/Lib/ctypes/test/test_macholib.py index 4c5ee7cbe34b10..bc75f1a05a8c37 100644 --- a/Lib/ctypes/test/test_macholib.py +++ b/Lib/ctypes/test/test_macholib.py @@ -46,8 +46,8 @@ def find_lib(name): def d(location=None, name=None, shortname=None, version=None, suffix=None): - return {'location': location, 'name': name, 'shortname': shortname, - 'version': version, 'suffix': suffix} + return {'location': location, 'name': name, 'shortname': shortname, + 'version': version, 'suffix': suffix} class MachOTest(unittest.TestCase):