def testSimple(self): TESTS = [u'a'], u'hello', 2 a = NSArray.arrayWithArray_([u'a']) EXPECTS = u'(a)', u'hello', u'2' EXPECTS = repr(a), u'hello', u'2' for obj,expect in zip(TESTS, EXPECTS): self.assertEquals(expect, PyObjC_TestClass4.fetchObjectDescription_(obj))
def testObserving2(self): observer = PyObjCTestObserver.alloc().init() o = PyObjCTestObserved1.alloc().init() o.addObserver_forKeyPath_options_context_( observer, "bar", (NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld), 0, ) a = NSArray.arrayWithArray_([o]) del o o = a[0] try: PyObjCTestObserved1.FOOBASE = "base2" o.setFoo_("yyy") self.assertEqual(o.foo(), "base2yyy") finally: o.removeObserver_forKeyPath_(observer, "bar") PyObjCTestObserved1.FOOBASE = "base" self.assertEqual(len(observer.observed), 0)
def test_list1(self): o1 = a_classic_class() o2 = a_newstyle_class() o2.lst = NSArray.arrayWithObject_(o1) l = NSArray.arrayWithArray_([o1, o2, [o1, o2]]) buf = self.dumps(l) self.assertIsInstance(buf, NSData) out = self.loads(buf) self.assertIsInstance(out, NSArray) self.assertEqual(len(out), 3) p1 = out[0] p2 = out[1] p3 = out[2] self.assertIsInstance(p1, a_classic_class) self.assertIsInstance(p2, a_newstyle_class) self.assertIsInstance(p3, list if self.isKeyed else NSArray) self.assertIs(p3[0], p1) self.assertIs(p3[1], p2) self.assertIsInstance(p2.lst , NSArray) self.assertIs(p2.lst[0], p1)
def test_list1(self): o1 = a_classic_class() o2 = a_newstyle_class() o2.lst = NSArray.arrayWithObject_(o1) l = NSArray.arrayWithArray_([o1, o2, [o1, o2]]) buf = self.dumps(l) self.assertIsInstance(buf, NSData) out = self.loads(buf) self.assertIsInstance(out, NSArray) self.assertEqual(len(out), 3) p1 = out[0] p2 = out[1] p3 = out[2] self.assertIsInstance(p1, a_classic_class) self.assertIsInstance(p2, a_newstyle_class) self.assertIsInstance(p3, list) self.assertIs(p3[0], p1) self.assertIs(p3[1], p2) self.assertIsInstance(p2.lst, NSArray) self.assertIs(p2.lst[0], p1)
def test_list1(self): o1 = a_classic_class() o2 = a_newstyle_class() o2.lst = NSArray.arrayWithObject_(o1) l = NSArray.arrayWithArray_([o1, o2, [o1, o2]]) buf = self.dumps(l) self.assert_(isinstance(buf, NSData)) out = self.loads(buf) self.assert_(isinstance(out, NSArray)) self.assertEquals(len(out), 3) p1 = out[0] p2 = out[1] p3 = out[2] self.assert_(isinstance(p1, a_classic_class)) self.assert_(isinstance(p2, a_newstyle_class)) self.assert_(isinstance(p3, list)) self.assert_(p3[0] is p1) self.assert_(p3[1] is p2) self.assert_(isinstance(p2.lst , NSArray)) self.assert_(p2.lst[0] is p1)
def test_weakref_to_objc(self): pool = NSAutoreleasePool.alloc().init() o = NSObject.alloc().init() a = NSArray.arrayWithObject_(o) r = objc.WeakRef(o) self.assertIs(r(), o) del o del pool pool = NSAutoreleasePool.alloc().init() self.assertIsInstance(r(), NSObject) del a del pool self.assertIs(r(), None)