Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
    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
        import sys
        import gc
        if sys.version_info[0] == 2:
            from StringIO import StringIO
        else:
            from io import StringIO

        with warnings.catch_warnings(record=True) as w:
            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)
Beispiel #4
0
    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)
Beispiel #5
0
    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
        import sys
        import gc

        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)
Beispiel #6
0
    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)
Beispiel #7
0
    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 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)
Beispiel #9
0
 def testNSObjectRespondsToCommonMethods(self):
     self.assertTrue(NSObject.pyobjc_classMethods.respondsToSelector_('alloc'))
     self.assertTrue(NSObject.instancesRespondToSelector_('init'))
     self.assertFalse(NSObject.instancesRespondToSelector_('frodel'))
Beispiel #10
0
    def testNSObjectPerforming(self):
        o = NSObject.performSelector_('new')
        self.assertIsInstance(o, NSObject)

        v = o.performSelector_('description')
        self.assertEqual(v, o.description())
Beispiel #11
0
 def testPureObjC(self):
     o = NSObject.new()
     self.assertRaises(TypeError, weakref.ref, o)
Beispiel #12
0
 def testPureObjC(self):
     o = NSObject.new()
     self.assertRaises(TypeError, weakref.ref, o)
Beispiel #13
0
 def setUp(self):
     self.NSObjectInstance = NSObject.alloc().init()
Beispiel #14
0
    def testNSObjectPerforming(self):
        o = NSObject.performSelector_('new')
        self.assertIsInstance(o, NSObject)

        v = o.performSelector_('description')
        self.assertEqual(v, o.description())