From 148ef8f7e7ced6dc18ceee618778b8b2b7ba92e5 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Thu, 3 Mar 2022 23:10:05 +0100 Subject: [PATCH] Fix a number of test failures on macOS 10.13 --- .../PyObjCTest/dump-nsarchive-securecoding.m | 9 +++++++++ pyobjc-core/PyObjCTest/test_archive_python.py | 11 ++++++++-- .../PyObjCTest/test_archiving_interop.py | 20 ++++++++++++++----- .../test_archiving_secure_interop.py | 19 +++++++++++++++--- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/pyobjc-core/PyObjCTest/dump-nsarchive-securecoding.m b/pyobjc-core/PyObjCTest/dump-nsarchive-securecoding.m index ee85384da5..35553ee921 100644 --- a/pyobjc-core/PyObjCTest/dump-nsarchive-securecoding.m +++ b/pyobjc-core/PyObjCTest/dump-nsarchive-securecoding.m @@ -7,6 +7,15 @@ #import #include +#if PyObjC_BUILD_RELEASE < 1014 +@interface +NSKeyedUnarchiver (PyObjCCompat) ++ (id)unarchivedObjectOfClasses:(NSSet*)classes + fromData:(NSData*)data + error:(NSError**)error; +@end +#endif + int main(int argc, char** argv) { diff --git a/pyobjc-core/PyObjCTest/test_archive_python.py b/pyobjc-core/PyObjCTest/test_archive_python.py index 74ed83c785..ba90a1740e 100644 --- a/pyobjc-core/PyObjCTest/test_archive_python.py +++ b/pyobjc-core/PyObjCTest/test_archive_python.py @@ -32,6 +32,7 @@ os_level_key, os_release, pyobjc_options, + cast_ulonglong, ) import copyreg @@ -159,7 +160,7 @@ def __setstate__(self, state): # # This workaround makes is possible to run # the test suite. - assert isinstance(k, objc.pyobjc_unicode) + assert isinstance(k, (str, objc.pyobjc_unicode)) setattr(self, str(k), v) @@ -1209,7 +1210,13 @@ def test_long(self): with self.subTest(x=x): buf = self.dumps(x) v = self.loads(buf) - self.assertEqual(v, x) + if (val == 2**63 + 1) and os_level_key( + os_release() + ) < os_level_key("10.14"): + # Bug in NSNumber... + self.assertEqual(cast_ulonglong(v), cast_ulonglong(x)) + else: + self.assertEqual(v, x) # Overriden tests for extension codes, the test code checks # the actual byte stream. diff --git a/pyobjc-core/PyObjCTest/test_archiving_interop.py b/pyobjc-core/PyObjCTest/test_archiving_interop.py index 67df9845ad..acafd68868 100644 --- a/pyobjc-core/PyObjCTest/test_archiving_interop.py +++ b/pyobjc-core/PyObjCTest/test_archiving_interop.py @@ -13,7 +13,7 @@ from plistlib import loads import objc -from PyObjCTools.TestSupport import TestCase +from PyObjCTools.TestSupport import TestCase, os_release, os_level_key, cast_ulonglong MYDIR = os.path.dirname(os.path.abspath(__file__)) @@ -112,14 +112,19 @@ def test_interop_float(self): self.assertEqual(converted, [testval]) def test_interop_int(self): - # for testval in (-42, 0, 42, -(2 ** 62), 2 ** 62, 2**63+10): - for testval in (2**63 + 10,): + for testval in (-42, 0, 42, -(2**62), 2**62, 2**63 + 10): with self.subTest(testval): v = NSArray.arrayWithObject_(testval) data = NSKeyedArchiver.archivedDataWithRootObject_(v) out = NSKeyedUnarchiver.unarchiveObjectWithData_(data) - self.assertEqual(out[0], testval) + if testval > 2**63 and os_level_key(os_release()) < os_level_key( + "10.14" + ): + # Bug in NSNumber + self.assertEqual(cast_ulonglong(out[0]), testval) + else: + self.assertEqual(out[0], testval) with tempfile.NamedTemporaryFile() as fp: fp.write(data.bytes()) @@ -130,7 +135,12 @@ def test_interop_int(self): ) converted = loads(converted) - self.assertEqual(converted, [testval]) + if testval > 2**63 and os_level_key(os_release()) < os_level_key( + "10.14" + ): + self.assertEqual(cast_ulonglong(converted[0]), testval) + else: + self.assertEqual(converted[0], testval) with self.subTest("overflow"): testval = 2**64 diff --git a/pyobjc-core/PyObjCTest/test_archiving_secure_interop.py b/pyobjc-core/PyObjCTest/test_archiving_secure_interop.py index f68c137780..7c511bed06 100644 --- a/pyobjc-core/PyObjCTest/test_archiving_secure_interop.py +++ b/pyobjc-core/PyObjCTest/test_archiving_secure_interop.py @@ -14,7 +14,7 @@ import datetime import objc -from PyObjCTools.TestSupport import TestCase, os_release, os_level_key +from PyObjCTools.TestSupport import TestCase, os_release, os_level_key, cast_ulonglong from plistlib import loads @@ -182,7 +182,14 @@ def test_interop_int(self): self.fail(f"Cannot create archive: {error}") out = NSKeyedUnarchiver.unarchiveObjectWithData_(data) - self.assertEqual(out[0], testval) + if testval > 2**63 and os_level_key(os_release()) < os_level_key( + "10.14" + ): + # Bug in NSNumber + self.assertEqual(cast_ulonglong(out[0]), testval) + + else: + self.assertEqual(out[0], testval) with tempfile.NamedTemporaryFile() as fp: fp.write(data.bytes()) @@ -191,7 +198,13 @@ def test_interop_int(self): converted = subprocess.check_output([self.progpath, fp.name]) converted = loads(converted) - self.assertEqual(converted, [testval]) + if testval > 2**63 and os_level_key(os_release()) < os_level_key( + "10.14" + ): + # Bug in NSNumber + self.assertEqual(cast_ulonglong(converted[0]), testval) + else: + self.assertEqual(converted[0], testval) with self.subTest("overflow"): testval = 2**64