def testDeallocUninit(self): import objc import warnings warnings.filterwarnings('ignore', category=objc.UninitializedDeallocWarning) try: for clsName in [ 'NSURL', 'NSObject', 'NSArray' ]: d = objc.lookUpClass(clsName).alloc() del d finally: del warnings.filters[0] # Check that we generate a warning for unitialized objects that # get deallocated import sys if sys.version_info[0] == 2: from StringIO import StringIO else: from io import StringIO warnings.filterwarnings('always', category=objc.UninitializedDeallocWarning) sys.stderr = buf = StringIO() try: d = NSObject.alloc() del d finally: del warnings.filters[0] sys.stderr = sys.__stderr__ # A warning is three lines: location info, source code, empty line self.assertEqual(len(buf.getvalue().split('\n')), 3)
def testCPicklePure(self): import cPickle as pickle o = NSObject.alloc().init() self.assertRaises((TypeError, ValueError), pickle.dumps, o, 0) self.assertRaises((TypeError, ValueError), pickle.dumps, o, 1) self.assertRaises((TypeError, ValueError), pickle.dumps, o, 2)
def testDeallocUninit(self): import objc import warnings warnings.filterwarnings("ignore", category=objc.UninitializedDeallocWarning) try: for clsName in ["NSURL", "NSObject", "NSArray"]: d = objc.lookUpClass(clsName).alloc() del d finally: del warnings.filters[0] # Check that we generate a warning for unitialized objects that # get deallocated import sys import StringIO warnings.filterwarnings("always", category=objc.UninitializedDeallocWarning) sys.stderr = io = StringIO.StringIO() try: d = NSObject.alloc() del d finally: del warnings.filters[0] sys.stderr = sys.__stderr__ # A warning is three lines: location info, source code, empty line self.assertEquals(len(io.getvalue().split("\n")), 3)
def testOneArgumentTooMany (self): class ClsIsNone (NSObject): @classmethod def f(cls): pass object = NSObject.alloc().init() self.assertRaises(TypeError, object.description, None) self.assertRaises(TypeError, object.description, "twelf") self.assertRaises(TypeError, NSObject.description, None) self.assertRaises(TypeError, ClsIsNone.f, None)
def testOneArgumentTooMany(self): class ClsIsNone(NSObject): @classmethod def f(cls): pass object = NSObject.alloc().init() self.assertRaises(TypeError, object.description, None) self.assertRaises(TypeError, object.description, "twelf") self.assertRaises(TypeError, NSObject.description, None) self.assertRaises(TypeError, ClsIsNone.f, None)
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)
def testDeallocUninit(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=objc.UninitializedDeallocWarning) for clsName in ["NSURL", "NSObject", "NSArray"]: d = objc.lookUpClass(clsName).alloc() del d # Check that we generate a warning for unitialized objects that # get deallocated with warnings.catch_warnings(record=True) as w: warnings.filterwarnings("always") d = NSObject.alloc() del d # Expliclty for garbage collection, without this # there are sporadic test failures when using # coverage.py gc.collect() self.assertTrue(len(w) == 1) self.assertEqual(w[0].category, objc.UninitializedDeallocWarning)
def setUp(self): self.NSObjectInstance = NSObject.alloc().init()