Skip to content

Commit

Permalink
Fix a number of test failures on macOS 10.13
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldoussoren committed Mar 3, 2022
1 parent 5d9adbb commit 148ef8f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
9 changes: 9 additions & 0 deletions pyobjc-core/PyObjCTest/dump-nsarchive-securecoding.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
#import <Foundation/Foundation.h>
#include <stdio.h>

#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)
{
Expand Down
11 changes: 9 additions & 2 deletions pyobjc-core/PyObjCTest/test_archive_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
os_level_key,
os_release,
pyobjc_options,
cast_ulonglong,
)

import copyreg
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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.
Expand Down
20 changes: 15 additions & 5 deletions pyobjc-core/PyObjCTest/test_archiving_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down
19 changes: 16 additions & 3 deletions pyobjc-core/PyObjCTest/test_archiving_secure_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down

0 comments on commit 148ef8f

Please sign in to comment.