Ronald Oussoren avatar Ronald Oussoren committed abc8cb3

more test updates

Comments (0)

Files changed (3)

pyobjc-core/Lib/objc/_bridges.py

     OC_PythonDictionary.depythonifyTable().append(type)
 
 
-if sys.version_info[0] > 2: # pragma: no cover (py3k)
-    registerListType(type(range(1)))
-
-else:
-    registerListType(xrange)
+registerListType(xrange if sys.version_info[0] == 2 else range)
 
 registerListType(collections.Sequence)
 registerMappingType(collections.Mapping)

pyobjc-core/Modules/objc/test/testbndl.m

 {
 }
 
++(Class)classOfObject:(NSObject*)arg;
+
 /* "plain" calls */
 -(char)callInstanceCharFuncOf:(OC_TestClass1*)arg;
 -(unsigned char)callInstanceUnsignedCharFuncOf:(OC_TestClass1*)arg;
 
 @implementation OC_TestClass2 
 
++(Class)classOfObject:(NSObject*)arg
+{
+	return [arg class];
+}
+
 -(char)callInstanceCharFuncOf:(OC_TestClass1*)arg
 {
 	return [arg charFunc];

pyobjc-core/PyObjCTest/test_bridges.py

+from PyObjCTools.TestSupport import *
+from PyObjCTest.testbndl import OC_TestClass2
+import objc
+import collections
+import sys
+
+if sys.version_info[0] == 2:
+    from UserList import  UserList
+    from UserDict import  IterableUserDict
+
+else:
+    from collections import IterableUserDict, UserList
+
+NSMutableArray = objc.lookUpClass("NSMutableArray")
+NSMutableDictionary = objc.lookUpClass("NSMutableDictionary")
+
+def classOfProxy(value):
+    return OC_TestClass2.classOfObject_(value)
+
+
+class TestBridges (TestCase):
+    # NOTE: the two "register" functions from objc._bridges aren't
+    # tested explictly, but the tests in this class do verify that
+    # the default registrations (which are made through those two
+    # functions) work properly.
+
+    def test_xrange(self):
+        range_type = range if sys.version_info[0] == 3 else xrange
+
+        v = range_type(0, 10)
+        self.assertTrue(issubclass(classOfProxy(v), NSMutableArray))
+
+    def test_user_collectons(self):
+        # Note: Not "UserDict" because UserDict doesn't implement
+        # __iter__ and hence isn't a collections.Mapping, and doesn't
+        # implement enough API to implement the NSDictionary interface.
+        v = IterableUserDict()
+        self.assertTrue(issubclass(classOfProxy(v), NSMutableDictionary))
+
+        v = UserList()
+        self.assertTrue(issubclass(classOfProxy(v), NSMutableArray))
+
+    def test_abc(self):
+        class MySequence (collections.Sequence):
+            def __getitem__(self, idx):
+                raise IndexError(idx)
+
+            def __len__(self):
+                return 0
+
+        class MyDictionary (collections.Mapping):
+            def __getitem__(self, key):
+                raise KeyError(key)
+
+            def __len__(self):
+                return 0
+
+            def __iter__(self):
+                return
+                yield
+
+        v = MyDictionary()
+        self.assertTrue(issubclass(classOfProxy(v), NSMutableDictionary))
+
+        v = MySequence()
+        self.assertTrue(issubclass(classOfProxy(v), NSMutableArray))
+
+
+if __name__ == "__main__":
+    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.