Ronald Oussoren avatar Ronald Oussoren committed 76a42ac

Add tests for objc.context

Comments (0)

Files changed (5)

pyobjc-core/Doc/lib/module-objc.rst

 PyObjC provides a :data:`context` object that can be used to allocate
 unique integers and map those to objects.
 
-(NOTE: The markup below here is probably incorrect)
-
 .. function:: context.register(value)
 
    Add a value to the context registry.
 
    :param value: An arbitrary object
    :return: A unique integer that's suitable to be used as a context pointer
+            (the handle).
 
 .. function:: context.unregister(value):
 
 
    :param value: An object in the context registry
 
-.. function:: context.get
+.. function:: context.get(handle)
 
    Retrieve an object from the registry given the return value from
    :func:`context.register`.

pyobjc-core/Lib/objc/__init__.py

 from objc._bridges import *
 from objc._compat import *
 from objc._pythonify import *
-from objc._functions import *
 from objc._locking import *
 from objc._context import *
 from objc._properties import *

pyobjc-core/Lib/objc/_descriptors.py

 This module defines the core interfaces of the Python<->Objective-C bridge.
 """
 
-__all__ = ['IBOutlet', 'IBAction', 'accessor', 'Accessor', 'typedAccessor', 'callbackFor', 'selectorFor', 'synthesize', 'namedselector', 'typedSelector', 'namedSelector', 'instancemethod' ]
+__all__ = ['IBOutlet', 'IBAction', 'accessor', 'Accessor', 'typedAccessor', 'callbackFor', 'selectorFor', 'synthesize', 'namedselector', 'typedSelector', 'namedSelector', 'instancemethod', 'signature' ]
 
 from objc._objc import ivar, selector, _makeClosure, selector, _C_SEL, _C_ID, _C_NSUInteger, _C_NSBOOL
 import sys, textwrap
     exec(getter, globals(), classDict)
 
     classDict[ivarName] = ivar(type=type)
+
+
+def signature(signature, **kw):
+    """
+    A Python method decorator that allows easy specification
+    of Objective-C selectors.
+
+    Usage::
+        
+        @objc.signature('i@:if')
+        def methodWithX_andY_(self, x, y):
+            return 0
+    """
+    warnings.warn("Usage objc.typedSelector instead of objc.signature", DeprecationWarning)
+    kw['signature'] = signature
+    def makeSignature(func):
+        return selector(func, **kw)
+    return makeSignature

pyobjc-core/NEWS.txt

   and is fully documented. The old name is temporarily available as
   an alias.
 
+- Move (deprected) decorator "signature" from objc._functions to objc._descriptors,
+  and remove the former module.
+
+  .. note:: 
+     The names op submodules of objc are implementation details, don't import
+     them directly.
+
 - Improved documentation
 
 

pyobjc-core/PyObjCTest/test_context.py

+from PyObjCTools.TestSupport import *
+
+import objc
+
+try:
+    long
+except NameError:
+    long = int
+
+class TestContext (TestCase):
+    def test_context(self):
+        self.assertEqual(objc.context._registry, {})
+
+        v = object()
+
+        h = objc.context.register(v)
+        self.assertIsInstance(h, (int, long))
+        self.assertIn(h, objc.context._registry)
+        self.assertIs(objc.context._registry[h], v)
+
+        self.assertIs(objc.context.get(h), v)
+
+        objc.context.unregister(object())
+        self.assertIn(h, objc.context._registry)
+        self.assertIs(objc.context._registry[h], v)
+
+        objc.context.unregister(v)
+        self.assertNotIn(h, objc.context._registry)
+
+        self.assertRaises(KeyError, objc.context.get, h)
+
+
+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.