def test_instance_specials(self): # Harder cases to get right: selectors with an embedded underscore # (which means the default translation from Python to ObjC names # won't work) o = PyObjC_MethodLookup1.alloc().init() self.assertEqual(o.OC_description(), "method description") self.assertEqual(o.OC_description.selector, b'OC_description') self.assertEqual(o.pyobjc__instanceCount(), 42) self.assertEqual(o.pyobjc__instanceCount.selector, b'pyobjc__instanceCount') self.assertEqual(o.pyobjc_setObject_forKey_(1, 2), [1, 2]) self.assertEqual(o.pyobjc_setObject_forKey_.selector, b'pyobjc_setObject:forKey:')
def test_instance_method_caching(self): o = PyObjC_MethodLookup1.alloc().init() self.assertNotIn("instance", PyObjC_MethodLookup1.__dict__) self.assertIsInstance(o.instance, objc.selector) self.assertIn("instance", PyObjC_MethodLookup1.__dict__) self.assertIsInstance(o.instance, objc.selector) # Check that the version from __dict__ is actually used: orig = PyObjC_MethodLookup1.__dict__["instance"].signature try: PyObjC_MethodLookup1.__dict__["instance"].signature = b"d@:" self.assertEqual(o.instance.signature, b"d@:") finally: PyObjC_MethodLookup1.__dict__["instance"].signature = orig
def test_instance_method_caching(self): o = PyObjC_MethodLookup1.alloc().init() self.assertNotIn('instance', PyObjC_MethodLookup1.__dict__) self.assertIsInstance(o.instance, objc.selector) self.assertIn('instance', PyObjC_MethodLookup1.__dict__) self.assertIsInstance(o.instance, objc.selector) # Check that the version from __dict__ is actually used: orig = PyObjC_MethodLookup1.__dict__['instance'].signature try: PyObjC_MethodLookup1.__dict__['instance'].signature = b"d@:" self.assertEqual(o.instance.signature, b"d@:") finally: PyObjC_MethodLookup1.__dict__['instance'].signature = orig
def test_instance_specials(self): # Harder cases to get right: selectors with an embedded underscore # (which means the default translation from Python to ObjC names # won't work) o = PyObjC_MethodLookup1.alloc().init() self.assertEqual(o.OC_description(), "method description") self.assertEqual(o.OC_description.selector, b"OC_description") self.assertEqual(o.pyobjc__instanceCount(), 42) self.assertEqual(o.pyobjc__instanceCount.selector, b"pyobjc__instanceCount") self.assertEqual(o.pyobjc_setObject_forKey_(1, 2), [1, 2]) self.assertEqual(o.pyobjc_setObject_forKey_.selector, b"pyobjc_setObject:forKey:")
def test_instance_dir(self): o = PyObjC_MethodLookup1.alloc().init() self.assertNotIn("instance2", PyObjC_MethodLookup1.__dict__) self.assertIn("instance2", dir(o)) self.assertIn("instance2", dir(PyObjC_MethodLookup1)) self.assertNotIn("instance2", dir(type(PyObjC_MethodLookup1)))
def test_instance_dir(self): o = PyObjC_MethodLookup1.alloc().init() self.assertNotIn('instance2', PyObjC_MethodLookup1.__dict__) self.assertIn('instance2', dir(o)) self.assertIn('instance2', dir(PyObjC_MethodLookup1)) self.assertNotIn('instance2', dir(type(PyObjC_MethodLookup1)))