Commits

Ronald Oussoren  committed 4b8aa1d

Improve testing for _pycoder

* Add call to +[NSUnarchiver decodeClassName:asClassName:] to make
it possible to decode archives created with py2 in py3

* Start creating an collection of NSKeyedArchiver and NSArchiver
archives and use that to test that newer versions of pyobjc
can still read archives created by older versions (and other
python releases)

Note that these tests don't make sure that the encoding
can still be read back by older releases.

  • Participants
  • Parent commits b272a4a

Comments (0)

Files changed (13)

File pyobjc-core/Lib/PyObjCTools/KeyValueCoding.py

         s = set()
         r = []
         for lst in obj:
-            for item in [ getKeyPath(item, path) for item in lst ]:
+            for item in (getKeyPath(item, path) for item in lst):
                 try:
                     if item in s or item in r:
                         continue
         path = '.'.join(segments)
         rval = set()
         for lst in obj:
-            for item in [ getKeyPath(item, path) for item in lst ]:
+            for item in (getKeyPath(item, path) for item in lst):
                 rval.add(item)
         return rval
 
         rval = []
         s = set()
         r = []
-        lst = [ getKeyPath(item, path) for item in obj ]
-        for item in lst:
+        for item in (getKeyPath(item, path) for item in obj):
             try:
                 if item in s or item in r:
                     continue
         path = '.'.join(segments)
         rval = []
         for lst in obj:
-            rval.extend([ getKeyPath(item, path) for item in lst ])
+            rval.extend(getKeyPath(item, path) for item in lst)
         return rval
 
 
         return [ getKeyPath(item, path) for item in obj]
 
 
-
-
 def getKey(obj, key):
     """
     Get the attribute referenced by 'key'. The key is used

File pyobjc-core/Lib/PyObjCTools/TestSupport.py

         if any(x is tp for x in _nscftype):
             self.fail(message or "%r is not a unique CFTypeRef type"%(tp,))
 
+        for cls in tp.__bases__:
+            if 'NSCFType' in cls.__name__:
+                return
+
+        self.fail(message or "%r is not a CFTypeRef type"%(tp,))
+
         # NOTE: Don't test if this is a subclass of one of the known
         #       CF roots, this tests is mostly used to ensure that the
         #       type is distinct from one of those roots.
             if hasattr(value, key):
                 self.fail(message or "%s is an attribute of %r"%(key, value))
 
-    def assertIsSubclass(self, value, type, message=None):
-        if not issubclass(value, type):
-            print(value, type)
-            self.fail(message or "%s is not a subclass of %r but %s"%(value, type, type(value)))
+    def assertIsSubclass(self, value, types, message=None):
+        if not issubclass(value, types):
+            self.fail(message or "%s is not a subclass of %r"%(value, types))
 
-    def assertIsNotSubclass(self, value, type, message=None):
-        if issubclass(value, type):
-            self.fail(message or "%s is a subclass of %r but %s"%(value, type, type(value)))
+    def assertIsNotSubclass(self, value, types, message=None):
+        if issubclass(value, types):
+            self.fail(message or "%s is a subclass of %r"%(value, types))
 
-    #if not hasattr(_unittest.TestCase, 'assertIsInstance'): # pragma: no cover
-    def assertIsInstance(self, value, types, message=None):
-        if not isinstance(value, types):
-            self.fail(message or "%s is not an instance of %r but %s"%(value, types, type(value)))
+    if not hasattr(_unittest.TestCase, 'assertIsInstance'): # pragma: no cover
+        def assertIsInstance(self, value, types, message=None):
+            if not isinstance(value, types):
+                self.fail(message or "%s is not an instance of %r but %s"%(value, types, type(value)))
 
     if not hasattr(_unittest.TestCase, 'assertIsNotInstance'): # pragma: no cover
         def assertIsNotInstance(self, value, types, message=None):

File pyobjc-core/Lib/objc/_pycoder.py

             return bltin_intern(value.encode('utf-8'))
         return bltin_intern(value)
 
+    def import_module(name):
+        __import__(name)
+        return sys.modules[name]
+
 else:   # pragma: no 2.x cover
     unicode = str
     long = int
             return bltin_intern(str(value))
         return bltin_intern(value)
 
+    def import_module(name):
+        if name == 'copy_reg':
+            name = 'copyreg'
+        __import__(name)
+        return sys.modules[name]
+
 
 NSArray = objc.lookUpClass("NSArray")
 NSMutableArray = objc.lookUpClass("NSMutableArray")
     else:
         coder.encodeValueOfObjCType_at_(objc._C_INT, kOP_FLOAT_STR)
         coder.encodeObject_(unicode(repr(obj)))
-    #coder.encodeDouble_forKey_(obj, kVALUE)
+
 encode_dispatch[float] = save_float
 
 def save_global(coder, obj, name=None):
         module = whichmodule(obj, name)
 
     try:
-        __import__ (module)
-        mod = sys.modules[module]
+        mod = import_module(module)
         klass= getattr(mod, name)
 
     except (ImportError, KeyError, AttributeError):
         raise ValueError("unregistered extension code %d" % code)
 
     module, name = key
-    __import__(module)
-    mod = sys.modules[module]
+    mod = import_module(module)
     klass = getattr(mod, name)
     copyreg._extension_cache[code] = klass
     return klass
 decode_dispatch[kOP_GLOBAL_EXT] = load_global_ext
 
+
 def load_global(coder, setValue):
     if coder.allowsKeyedCoding():
         module = coder.decodeObjectForKey_(kMODULE)
         module = coder.decodeObject()
         name = coder.decodeObject()
 
-    __import__(module)
-    mod = sys.modules[module]
+    mod = import_module(module)
     klass = getattr(mod, name)
     return klass
 

File pyobjc-core/Modules/objc/module.m

 #error "No Py_ARG_NSUInteger"
 #endif
 
+#if PY_MAJOR_VERSION == 3
+    /*
+     * Archives created with Python 2.x can contain instances of OC_PythonString,
+     * use OC_PythonUnicode to decode.
+     */
+    [NSUnarchiver decodeClassName:@"OC_PythonString" asClassName:@"OC_PythonUnicode"];
+#endif /* PY_MAJOR_VERSION == 3 */
+
     PyObjC_INITDONE();
 }

File pyobjc-core/PyObjCTest/archives/py2-oc2.3.keyed

Binary file added.

File pyobjc-core/PyObjCTest/archives/py2-oc2.3.plain

Binary file added.

File pyobjc-core/PyObjCTest/archives/py3-oc3.0.keyed

Binary file added.

File pyobjc-core/PyObjCTest/archives/py3-oc3.0.plain

Binary file added.

File pyobjc-core/PyObjCTest/test_archiving_interop.py

 NSArray = objc.lookUpClass('NSArray')
 NSArchiver = objc.lookUpClass('NSArchiver')
 NSKeyedArchiver = objc.lookUpClass('NSKeyedArchiver')
+NSUnarchiver = objc.lookUpClass('NSUnarchiver')
+NSKeyedUnarchiver = objc.lookUpClass('NSKeyedUnarchiver')
 NSSet = objc.lookUpClass('NSSet')
 
 class TestNSKeyedArchivingInterop (TestCase):
             converted = readPlistFromBytes(converted)
             self.assertEqual(converted, testval)
 
+
+class Class1:
+    pass
+
+class Class2 (object):
+    pass
+
+class TestLoadingOlderVersions (TestCase):
+    def do_verify(self, path):
+        import __main__
+
+        # Ensure that class definitions are present:
+        __main__.Class1 = Class1
+        __main__.Class2 = Class2
+
+        if path.endswith('keyed'):
+            archiver = NSKeyedUnarchiver
+        else:
+            archiver = NSUnarchiver
+
+        data = archiver.unarchiveObjectWithFile_(path)
+        self.assertIsInstance(data, Class2)
+        self.assertEqual(data.lst, [1,2,3])
+        self.assertEqual(data.string, "hello world")
+        self.assertIsInstance(data.obj, Class1)
+        o = data.obj
+        self.assertEqual(o.a, 42)
+        self.assertEqual(o.b, 2.5)
+
+    for fname in os.listdir(os.path.join(MYDIR, 'archives')):
+        def test(self, fname=fname):
+            self.do_verify(os.path.join(MYDIR, 'archives', fname))
+        locals()['test_%s'%(fname.replace('.', '_').replace('-', '_'))] = test
+        del test
+
+
 if __name__ == "__main__":
     main()

File pyobjc-core/PyObjCTest/test_keyvaluecoding.py

         self.assertRaises(KeyError, arrayOperators.unionOfArrays, transactions, 'date')
         self.assertRaises(KeyError, arrayOperators.distinctUnionOfArrays, transactions, 'date')
 
+    def test_unionOfArrays_variations(self):
+        lst = [[
+            { 'a': 1 },
+            { 'a': 2 },
+            { 'a': 1 },
+            { 'a': 3 },
+            { 'a': 2 },
+        ]]
+
+        arrayOperators = KeyValueCoding._ArrayOperators
+        self.assertEqual(arrayOperators.distinctUnionOfArrays(lst, 'a'), [1,2,3])
+
+        lst = [
+            [
+                { 'a': [1] },
+                { 'a': [2] },
+                { 'a': [1] },
+            ],
+            [
+                { 'a': 3 },
+                { 'a': [2] },
+            ],
+        ]
+
+        arrayOperators = KeyValueCoding._ArrayOperators
+        self.assertEqual(arrayOperators.distinctUnionOfArrays(lst, 'a'), [[1],[2],3])
+
+
     def testUnionOfSets(self):
         arrayOperators = KeyValueCoding._ArrayOperators
 

File pyobjc-core/PyObjCTest/test_lazy_import.py

                 ('CFAllocatorRef', b'^{__CFAllocator=}', 'CFAllocatorGetTypeID', None),
                 ('CFArrayRef', b'^{__CFArray=}', 'CFArrayGetTypeID', 'DoesNotExist,NSArray'),
                 ('CFAttributedStringRef', b'^{__CFAttributedString=}', 'CFAttributedStringGetTypeID', '__NSCFAttributedString,NSCFAttributedString'),
-                ('CFBagRef', b'^{__CFBag=}', 'CFBagGetTypeID', None),
+                ('CFBagRef', b'^{__CFBag=}', 'xCFBagGetTypeID', None),
                 ('CFNoType', b'^{__CFNoType', 'CFNoTypeGetTypeID', 'DoesNotExist'),
             ],
             'functions': {

File pyobjc-core/PyObjCTest/test_testsupport.py

         finally:
             sys.maxsize = orig
 
+    def testAssertIsSubclass(self):
+        self.assertIsSubclass(int, object)
+        self.assertIsSubclass(str, object)
+        self.assertIsSubclass(objc.objc_class, type)
+        self.assertRaises(self.failureException, self.assertIsSubclass, objc.objc_class, objc.objc_object)
+
+    def testAssertIsNotSubclass(self):
+        self.assertIsNotSubclass(object, int)
+        self.assertRaises(self.failureException, self.assertIsNotSubclass, objc.objc_object, object)
+
+    def testAssertIsIstance(self):
+        self.assertIsInstance(object(), object)
+        self.assertIsInstance(42, object)
+        self.assertIsInstance(42, (int, str))
+
+        self.assertRaises(self.failureException, self.assertIsInstance, 42, str)
+
 
     def test_assert_cftype(self):
-        self.assertRaises(AssertionError, self.assertIsCFType, long)
-        self.assertRaises(AssertionError, self.assertIsCFType, objc.lookUpClass('NSCFType'))
+        self.assertRaises(self.failureException, self.assertIsCFType, long)
+        self.assertRaises(self.failureException, self.assertIsCFType, objc.lookUpClass('NSCFType'))
 
         # 'assertIsCFType' primarily tests that a type is either tollfree bridged, or
         # has a distinct type that is different from the default NSCFType 'placeholder' type.
-        self.assertIsCFType(objc.lookUpClass('NSObject'))
-        #self.assertRaises(AssertionError, self.assertIsCFType, objc.lookUpClass('NSObject'))
+        #self.assertIsCFType(objc.lookUpClass('NSObject'))
+        self.assertRaises(self.failureException, self.assertIsCFType, objc.lookUpClass('NSObject'))
 
         class OC_OPAQUE_TEST_1 (objc.lookUpClass('NSCFType')): pass
         try:
             self.assertIsCFType(OC_OPAQUE_TEST_1)
-        except AssertionError:
+        except self.failureException:
             self.fail("CFType subclass not recognized as CFType")
 
 
 
     def test_assert_opaque(self):
-        self.assertRaises(AssertionError, self.assertIsOpaquePointer, long)
+        self.assertRaises(self.failureException, self.assertIsOpaquePointer, long)
 
         class N (object):
             @property
             def __pointer__(self):
                 pass
 
-        self.assertRaises(AssertionError, self.assertIsOpaquePointer, N)
+        self.assertRaises(self.failureException, self.assertIsOpaquePointer, N)
 
         class N (object):
             __typestr__  = b"^q"
 
-        self.assertRaises(AssertionError, self.assertIsOpaquePointer, N)
+        self.assertRaises(self.failureException, self.assertIsOpaquePointer, N)
 
         class N (object):
             __typestr__  = b"^q"
         try:
             self.assertIsOpaquePointer(N)
 
-        except AssertionError:
+        except self.failureException:
             self.fail("assertIsOpaque fails on opaque pointer type")
 
 
         self.assertResultIsNullTerminated(m)
 
         m = Method(None, {"c_array_delimited_by_null": False })
-        self.assertRaises(AssertionError, self.assertResultIsNullTerminated, m)
+        self.assertRaises(self.failureException, self.assertResultIsNullTerminated, m)
 
         m = Method(None, {})
-        self.assertRaises(AssertionError, self.assertResultIsNullTerminated, m)
+        self.assertRaises(self.failureException, self.assertResultIsNullTerminated, m)
 
     def test_assert_arg_nullterminated(self):
         m = Method(3, {"c_array_delimited_by_null": True }, selector=True)
         self.assertArgIsNullTerminated(m, 1)
-        self.assertRaises(AssertionError, self.assertArgIsNullTerminated, m, 0)
+        self.assertRaises(self.failureException, self.assertArgIsNullTerminated, m, 0)
 
         m = Method(3, {"c_array_delimited_by_null": False }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsNullTerminated, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsNullTerminated, m, 1)
 
         m = Method(3, {}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsNullTerminated, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsNullTerminated, m, 1)
 
         m = Method(3, {"c_array_delimited_by_null": True }, selector=False)
         self.assertArgIsNullTerminated(m, 3)
-        self.assertRaises(AssertionError, self.assertArgIsNullTerminated, m, 2)
+        self.assertRaises(self.failureException, self.assertArgIsNullTerminated, m, 2)
 
         m = Method(3, {"c_array_delimited_by_null": False }, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsNullTerminated, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsNullTerminated, m, 3)
 
         m = Method(3, {}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsNullTerminated, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsNullTerminated, m, 3)
 
     def test_function_nullterminated(self):
         m = Method(None, {}, selector=False)
         self.assertIsNullTerminated(m)
 
         m._meta['variadic'] = False
-        self.assertRaises(AssertionError, self.assertIsNullTerminated, m)
+        self.assertRaises(self.failureException, self.assertIsNullTerminated, m)
 
         m._meta['variadic'] = True
         m._meta['c_array_delimited_by_null'] = False
-        self.assertRaises(AssertionError, self.assertIsNullTerminated, m)
+        self.assertRaises(self.failureException, self.assertIsNullTerminated, m)
 
         del m._meta['variadic']
         m._meta['c_array_delimited_by_null'] = True
-        self.assertRaises(AssertionError, self.assertIsNullTerminated, m)
+        self.assertRaises(self.failureException, self.assertIsNullTerminated, m)
 
         m = Method(None, {}, selector=True)
         m._meta.update({
         self.assertIsNullTerminated(m)
 
         m._meta['variadic'] = False
-        self.assertRaises(AssertionError, self.assertIsNullTerminated, m)
+        self.assertRaises(self.failureException, self.assertIsNullTerminated, m)
 
         m._meta['variadic'] = True
         m._meta['c_array_delimited_by_null'] = False
-        self.assertRaises(AssertionError, self.assertIsNullTerminated, m)
+        self.assertRaises(self.failureException, self.assertIsNullTerminated, m)
 
         del m._meta['variadic']
         m._meta['c_array_delimited_by_null'] = True
-        self.assertRaises(AssertionError, self.assertIsNullTerminated, m)
+        self.assertRaises(self.failureException, self.assertIsNullTerminated, m)
 
     def test_arg_varialbe_size(self):
         m = Method(3, { 'c_array_of_variable_length': True }, selector=True)
         self.assertArgIsVariableSize(m, 1)
-        self.assertRaises(AssertionError, self.assertArgIsVariableSize, m, 0)
+        self.assertRaises(self.failureException, self.assertArgIsVariableSize, m, 0)
 
         m = Method(3, { 'c_array_of_variable_length': False }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsVariableSize, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsVariableSize, m, 1)
 
         m = Method(3, { 'c_array_of_variable_length': True }, selector=False)
         self.assertArgIsVariableSize(m, 3)
-        self.assertRaises(AssertionError, self.assertArgIsVariableSize, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsVariableSize, m, 1)
 
         m = Method(3, { 'c_array_of_variable_length': False }, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsVariableSize, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsVariableSize, m, 3)
 
     def test_result_varialbe_size(self):
         m = Method(None, { 'c_array_of_variable_length': True }, selector=True)
         self.assertResultIsVariableSize(m, 1)
 
         m = Method(None, { 'c_array_of_variable_length': False }, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsVariableSize, m, 1)
+        self.assertRaises(self.failureException, self.assertResultIsVariableSize, m, 1)
 
         m = Method(None, { }, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsVariableSize, m, 1)
+        self.assertRaises(self.failureException, self.assertResultIsVariableSize, m, 1)
 
     def test_argsize_in_result(self):
         m = Method(3, { 'c_array_length_in_result': True }, selector=True)
         self.assertArgSizeInResult(m, 1)
-        self.assertRaises(AssertionError, self.assertArgSizeInResult, m, 0)
+        self.assertRaises(self.failureException, self.assertArgSizeInResult, m, 0)
 
         m = Method(3, { 'c_array_length_in_result': False }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgSizeInResult, m, 1)
+        self.assertRaises(self.failureException, self.assertArgSizeInResult, m, 1)
 
         m = Method(3, {}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgSizeInResult, m, 1)
+        self.assertRaises(self.failureException, self.assertArgSizeInResult, m, 1)
 
         m = Method(3, { 'c_array_length_in_result': True }, selector=False)
         self.assertArgSizeInResult(m, 3)
-        self.assertRaises(AssertionError, self.assertArgSizeInResult, m, 2)
+        self.assertRaises(self.failureException, self.assertArgSizeInResult, m, 2)
 
         m = Method(3, { 'c_array_length_in_result': False }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgSizeInResult, m, 3)
+        self.assertRaises(self.failureException, self.assertArgSizeInResult, m, 3)
 
         m = Method(3, {}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgSizeInResult, m, 3)
+        self.assertRaises(self.failureException, self.assertArgSizeInResult, m, 3)
 
     def test_arg_printf(self):
         m = Method(3, { 'printf_format': True }, selector=True)
         m._meta['variadic'] = True
         self.assertArgIsPrintf(m, 1)
-        self.assertRaises(AssertionError, self.assertArgIsPrintf, m, 0)
+        self.assertRaises(self.failureException, self.assertArgIsPrintf, m, 0)
 
         m._meta['variadic'] = False
-        self.assertRaises(AssertionError, self.assertArgIsPrintf, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsPrintf, m, 1)
 
         m._meta['variadic'] = True
         m._meta['arguments'][3]['printf_format'] = False
-        self.assertRaises(AssertionError, self.assertArgIsPrintf, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsPrintf, m, 1)
 
         m._meta['variadic'] = True
-        del m._meta['arguments'][3]['printf_format'] 
-        self.assertRaises(AssertionError, self.assertArgIsPrintf, m, 1)
+        del m._meta['arguments'][3]['printf_format']
+        self.assertRaises(self.failureException, self.assertArgIsPrintf, m, 1)
 
 
         m = Method(3, { 'printf_format': True }, selector=False)
         m._meta['variadic'] = True
         self.assertArgIsPrintf(m, 3)
-        self.assertRaises(AssertionError, self.assertArgIsPrintf, m, 2)
+        self.assertRaises(self.failureException, self.assertArgIsPrintf, m, 2)
 
         m._meta['variadic'] = False
-        self.assertRaises(AssertionError, self.assertArgIsPrintf, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsPrintf, m, 3)
 
         m._meta['variadic'] = True
         m._meta['arguments'][3]['printf_format'] = False
-        self.assertRaises(AssertionError, self.assertArgIsPrintf, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsPrintf, m, 3)
 
         m._meta['variadic'] = True
-        del m._meta['arguments'][3]['printf_format'] 
-        self.assertRaises(AssertionError, self.assertArgIsPrintf, m, 3)
+        del m._meta['arguments'][3]['printf_format']
+        self.assertRaises(self.failureException, self.assertArgIsPrintf, m, 3)
 
 
     def test_arg_cfretained(self):
         m = Method(3, {'already_cfretained': True}, selector=True)
         self.assertArgIsCFRetained(m, 1)
-        self.assertRaises(AssertionError, self.assertArgIsCFRetained, m, 0)
+        self.assertRaises(self.failureException, self.assertArgIsCFRetained, m, 0)
 
         m = Method(3, {'already_cfretained': False}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsCFRetained, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsCFRetained, m, 1)
 
         m = Method(3, {}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsCFRetained, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsCFRetained, m, 1)
 
         m = Method(3, {'already_cfretained': True}, selector=False)
         self.assertArgIsCFRetained(m, 3)
-        self.assertRaises(AssertionError, self.assertArgIsCFRetained, m, 2)
+        self.assertRaises(self.failureException, self.assertArgIsCFRetained, m, 2)
 
         m = Method(3, {'already_cfretained': False}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsCFRetained, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsCFRetained, m, 3)
 
         m = Method(3, {}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsCFRetained, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsCFRetained, m, 3)
 
     def test_arg_not_cfretained(self):
         m = Method(3, {'already_cfretained': True}, selector=True)
         self.assertArgIsNotCFRetained(m, 0)
-        self.assertRaises(AssertionError, self.assertArgIsNotCFRetained, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsNotCFRetained, m, 1)
 
         m = Method(3, {'already_cfretained': False}, selector=True)
         self.assertArgIsNotCFRetained(m, 1)
         self.assertResultIsCFRetained(m)
 
         m = Method(None, {'already_cfretained': False })
-        self.assertRaises(AssertionError, self.assertResultIsCFRetained, m)
+        self.assertRaises(self.failureException, self.assertResultIsCFRetained, m)
 
         m = Method(None, {})
-        self.assertRaises(AssertionError, self.assertResultIsCFRetained, m)
+        self.assertRaises(self.failureException, self.assertResultIsCFRetained, m)
 
     def test_result_not_cfretained(self):
         m = Method(None, {'already_cfretained': True })
-        self.assertRaises(AssertionError, self.assertResultIsNotCFRetained, m)
+        self.assertRaises(self.failureException, self.assertResultIsNotCFRetained, m)
 
         m = Method(None, {'already_cfretained': False })
         self.assertResultIsNotCFRetained(m)
     def test_arg_type(self):
         m = Method(3, {'type': objc._C_DBL }, selector=True)
         self.assertArgHasType(m, 1, objc._C_DBL)
-        self.assertRaises(AssertionError, self.assertArgHasType, m, 2, objc._C_ID)
-        self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+        self.assertRaises(self.failureException, self.assertArgHasType, m, 2, objc._C_ID)
+        self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
         m = Method(3, {}, selector=True)
         self.assertArgHasType(m, 1, objc._C_ID)
             m = Method(3, {'type': objc._C_LNG }, selector=True)
             self.assertArgHasType(m, 1, objc._C_LNG)
             self.assertArgHasType(m, 1, objc._C_LNG_LNG)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
             m = Method(3, {'type': objc._C_ULNG }, selector=True)
             self.assertArgHasType(m, 1, objc._C_ULNG)
             self.assertArgHasType(m, 1, objc._C_ULNG_LNG)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
             m = Method(3, {'type': objc._C_LNG_LNG }, selector=True)
             self.assertArgHasType(m, 1, objc._C_LNG)
             self.assertArgHasType(m, 1, objc._C_LNG_LNG)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
             m = Method(3, {'type': objc._C_ULNG_LNG }, selector=True)
             self.assertArgHasType(m, 1, objc._C_ULNG)
             self.assertArgHasType(m, 1, objc._C_ULNG_LNG)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
         else:
             m = Method(3, {'type': objc._C_LNG }, selector=True)
             self.assertArgHasType(m, 1, objc._C_LNG)
             self.assertArgHasType(m, 1, objc._C_INT)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
             m = Method(3, {'type': objc._C_ULNG }, selector=True)
             self.assertArgHasType(m, 1, objc._C_ULNG)
             self.assertArgHasType(m, 1, objc._C_UINT)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
             m = Method(3, {'type': objc._C_INT }, selector=True)
             self.assertArgHasType(m, 1, objc._C_LNG)
             self.assertArgHasType(m, 1, objc._C_INT)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
             m = Method(3, {'type': objc._C_UINT }, selector=True)
             self.assertArgHasType(m, 1, objc._C_UINT)
             self.assertArgHasType(m, 1, objc._C_UINT)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 1, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 1, objc._C_ID)
 
         m = Method(3, {'type': objc._C_DBL }, selector=False)
         self.assertArgHasType(m, 3, objc._C_DBL)
-        self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
-        self.assertRaises(AssertionError, self.assertArgHasType, m, 2, objc._C_ID)
+        self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
+        self.assertRaises(self.failureException, self.assertArgHasType, m, 2, objc._C_ID)
 
         m = Method(3, {}, selector=False)
         self.assertArgHasType(m, 3, objc._C_ID)
             m = Method(3, {'type': objc._C_LNG }, selector=False)
             self.assertArgHasType(m, 3, objc._C_LNG)
             self.assertArgHasType(m, 3, objc._C_LNG_LNG)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
 
             m = Method(3, {'type': objc._C_ULNG }, selector=False)
             self.assertArgHasType(m, 3, objc._C_ULNG)
             self.assertArgHasType(m, 3, objc._C_ULNG_LNG)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
 
             m = Method(3, {'type': objc._C_LNG_LNG }, selector=False)
             self.assertArgHasType(m, 3, objc._C_LNG)
             self.assertArgHasType(m, 3, objc._C_LNG_LNG)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
 
             m = Method(3, {'type': objc._C_ULNG_LNG }, selector=False)
             self.assertArgHasType(m, 3, objc._C_ULNG)
             self.assertArgHasType(m, 3, objc._C_ULNG_LNG)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
 
         else:
             m = Method(3, {'type': objc._C_LNG }, selector=False)
             self.assertArgHasType(m, 3, objc._C_LNG)
             self.assertArgHasType(m, 3, objc._C_INT)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
 
             m = Method(3, {'type': objc._C_ULNG }, selector=False)
             self.assertArgHasType(m, 3, objc._C_ULNG)
             self.assertArgHasType(m, 3, objc._C_UINT)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
 
             m = Method(3, {'type': objc._C_INT }, selector=False)
             self.assertArgHasType(m, 3, objc._C_LNG)
             self.assertArgHasType(m, 3, objc._C_INT)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
 
             m = Method(3, {'type': objc._C_UINT }, selector=False)
             self.assertArgHasType(m, 3, objc._C_UINT)
             self.assertArgHasType(m, 3, objc._C_UINT)
-            self.assertRaises(AssertionError, self.assertArgHasType, m, 3, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertArgHasType, m, 3, objc._C_ID)
 
 
     def test_result_type(self):
         m = Method(None, {})
         self.assertResultHasType(m, objc._C_VOID)
-        self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+        self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
         m = Method(None, { 'type': objc._C_DBL})
         self.assertResultHasType(m, objc._C_DBL)
-        self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+        self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
         if sys.maxsize > 2**32:
             m = Method(None, {'type': objc._C_LNG }, selector=False)
             self.assertResultHasType(m, objc._C_LNG)
             self.assertResultHasType(m, objc._C_LNG_LNG)
-            self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
             m = Method(None, {'type': objc._C_ULNG }, selector=False)
             self.assertResultHasType(m, objc._C_ULNG)
             self.assertResultHasType(m, objc._C_ULNG_LNG)
-            self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
             m = Method(None, {'type': objc._C_LNG_LNG }, selector=False)
             self.assertResultHasType(m, objc._C_LNG)
             self.assertResultHasType(m, objc._C_LNG_LNG)
-            self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
             m = Method(None, {'type': objc._C_ULNG_LNG }, selector=False)
             self.assertResultHasType(m, objc._C_ULNG)
             self.assertResultHasType(m, objc._C_ULNG_LNG)
-            self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
         else:
             m = Method(None, {'type': objc._C_LNG }, selector=False)
             self.assertResultHasType(m, objc._C_LNG)
             self.assertResultHasType(m, objc._C_INT)
-            self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
             m = Method(None, {'type': objc._C_ULNG }, selector=False)
             self.assertResultHasType(m, objc._C_ULNG)
             self.assertResultHasType(m, objc._C_UINT)
-            self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
             m = Method(None, {'type': objc._C_INT }, selector=False)
             self.assertResultHasType(m, objc._C_LNG)
             self.assertResultHasType(m, objc._C_INT)
-            self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
             m = Method(None, {'type': objc._C_UINT }, selector=False)
             self.assertResultHasType(m, objc._C_UINT)
             self.assertResultHasType(m, objc._C_UINT)
-            self.assertRaises(AssertionError, self.assertResultHasType, m, objc._C_ID)
+            self.assertRaises(self.failureException, self.assertResultHasType, m, objc._C_ID)
 
 
     def test_arg_fixed_size(self):
         m = Method(3, { 'c_array_of_fixed_length': 42 }, selector=True)
         self.assertArgIsFixedSize(m, 1, 42)
-        self.assertRaises(AssertionError, self.assertArgIsFixedSize, m, 0, 42)
-        self.assertRaises(AssertionError, self.assertArgIsFixedSize, m, 1, 3)
+        self.assertRaises(self.failureException, self.assertArgIsFixedSize, m, 0, 42)
+        self.assertRaises(self.failureException, self.assertArgIsFixedSize, m, 1, 3)
 
         m = Method(3, { }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsFixedSize, m, 1, 3)
+        self.assertRaises(self.failureException, self.assertArgIsFixedSize, m, 1, 3)
 
         m = Method(3, { 'c_array_of_fixed_length': 42 }, selector=False)
         self.assertArgIsFixedSize(m, 3, 42)
-        self.assertRaises(AssertionError, self.assertArgIsFixedSize, m, 2, 42)
-        self.assertRaises(AssertionError, self.assertArgIsFixedSize, m, 3, 3)
+        self.assertRaises(self.failureException, self.assertArgIsFixedSize, m, 2, 42)
+        self.assertRaises(self.failureException, self.assertArgIsFixedSize, m, 3, 3)
 
         m = Method(3, { }, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsFixedSize, m, 3, 3)
+        self.assertRaises(self.failureException, self.assertArgIsFixedSize, m, 3, 3)
 
     def test_result_fixed_size(self):
         m = Method(None, { 'c_array_of_fixed_length': 42 })
         self.assertResultIsFixedSize(m, 42)
-        self.assertRaises(AssertionError, self.assertResultIsFixedSize, m, 3)
+        self.assertRaises(self.failureException, self.assertResultIsFixedSize, m, 3)
 
         m = Method(None, { }, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsFixedSize, m, 3)
+        self.assertRaises(self.failureException, self.assertResultIsFixedSize, m, 3)
 
 
     def test_arg_size_in_arg(self):
         m = Method(3, {'c_array_length_in_arg': 4 }, selector=True)
         self.assertArgSizeInArg(m, 1, 2)
-        self.assertRaises(AssertionError, self.assertArgSizeInArg, m, 1, 3)
-        self.assertRaises(AssertionError, self.assertArgSizeInArg, m, 0, 3)
+        self.assertRaises(self.failureException, self.assertArgSizeInArg, m, 1, 3)
+        self.assertRaises(self.failureException, self.assertArgSizeInArg, m, 0, 3)
 
         m = Method(3, {'c_array_length_in_arg': (2, 4) }, selector=True)
         self.assertArgSizeInArg(m, 1, (0, 2))
-        self.assertRaises(AssertionError, self.assertArgSizeInArg, m, 1, (0, 3))
-        self.assertRaises(AssertionError, self.assertArgSizeInArg, m, 0, (1, 2))
+        self.assertRaises(self.failureException, self.assertArgSizeInArg, m, 1, (0, 3))
+        self.assertRaises(self.failureException, self.assertArgSizeInArg, m, 0, (1, 2))
 
 
 
         m = Method(3, {'c_array_length_in_arg': 4 }, selector=False)
         self.assertArgSizeInArg(m, 3, 4)
-        self.assertRaises(AssertionError, self.assertArgSizeInArg, m, 1, 3)
-        self.assertRaises(AssertionError, self.assertArgSizeInArg, m, 0, 3)
+        self.assertRaises(self.failureException, self.assertArgSizeInArg, m, 1, 3)
+        self.assertRaises(self.failureException, self.assertArgSizeInArg, m, 0, 3)
 
         m = Method(3, {'c_array_length_in_arg': (2, 4) }, selector=False)
         self.assertArgSizeInArg(m, 3, (2, 4))
-        self.assertRaises(AssertionError, self.assertArgSizeInArg, m, 1, (2, 3))
-        self.assertRaises(AssertionError, self.assertArgSizeInArg, m, 0, (2, 3))
+        self.assertRaises(self.failureException, self.assertArgSizeInArg, m, 1, (2, 3))
+        self.assertRaises(self.failureException, self.assertArgSizeInArg, m, 0, (2, 3))
 
     def test_result_ize_in_arg(self):
         m = Method(None, {'c_array_length_in_arg': 4 }, selector=True)
         self.assertResultSizeInArg(m, 2)
-        self.assertRaises(AssertionError, self.assertResultSizeInArg, m, 3)
-        self.assertRaises(AssertionError, self.assertResultSizeInArg, m, 3)
+        self.assertRaises(self.failureException, self.assertResultSizeInArg, m, 3)
+        self.assertRaises(self.failureException, self.assertResultSizeInArg, m, 3)
 
         m = Method(None, {'c_array_length_in_arg': 4 }, selector=False)
         self.assertResultSizeInArg(m, 4)
-        self.assertRaises(AssertionError, self.assertResultSizeInArg, m, 3)
+        self.assertRaises(self.failureException, self.assertResultSizeInArg, m, 3)
 
 
 
     def test_arg_retained(self):
         m = Method(3, {'already_retained': True}, selector=True)
         self.assertArgIsRetained(m, 1)
-        self.assertRaises(AssertionError, self.assertArgIsRetained, m, 0)
+        self.assertRaises(self.failureException, self.assertArgIsRetained, m, 0)
 
         m = Method(3, {'already_retained': False}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsRetained, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsRetained, m, 1)
 
         m = Method(3, {}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsRetained, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsRetained, m, 1)
 
         m = Method(3, {'already_retained': True}, selector=False)
         self.assertArgIsRetained(m, 3)
-        self.assertRaises(AssertionError, self.assertArgIsRetained, m, 2)
+        self.assertRaises(self.failureException, self.assertArgIsRetained, m, 2)
 
         m = Method(3, {'already_retained': False}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsRetained, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsRetained, m, 3)
 
         m = Method(3, {}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsRetained, m, 3)
+        self.assertRaises(self.failureException, self.assertArgIsRetained, m, 3)
 
     def test_arg_not_retained(self):
         m = Method(3, {'already_retained': True}, selector=True)
         self.assertArgIsNotRetained(m, 0)
-        self.assertRaises(AssertionError, self.assertArgIsNotRetained, m, 1)
+        self.assertRaises(self.failureException, self.assertArgIsNotRetained, m, 1)
 
         m = Method(3, {'already_retained': False}, selector=True)
         self.assertArgIsNotRetained(m, 1)
         self.assertResultIsRetained(m)
 
         m = Method(None, {'already_retained': False })
-        self.assertRaises(AssertionError, self.assertResultIsRetained, m)
+        self.assertRaises(self.failureException, self.assertResultIsRetained, m)
 
         m = Method(None, {})
-        self.assertRaises(AssertionError, self.assertResultIsRetained, m)
+        self.assertRaises(self.failureException, self.assertResultIsRetained, m)
 
     def test_result_not_retained(self):
         m = Method(None, {'already_retained': True })
-        self.assertRaises(AssertionError, self.assertResultIsNotRetained, m)
+        self.assertRaises(self.failureException, self.assertResultIsNotRetained, m)
 
         m = Method(None, {'already_retained': False })
         self.assertResultIsNotRetained(m)
         m = Method(3, { "type": b"n^@" })
         try:
             self.assertArgIsIn(m, 3)
-        except AssertionError:
+        except self.failureException:
             raise
             self.fail("test failure for input argument")
 
         m = Method(3, { "type": b"n^@" }, selector=True)
         try:
             self.assertArgIsIn(m, 1)
-        except AssertionError:
+        except self.failureException:
             self.fail("test failure for input argument")
 
         m = Method(3, { "type": b"^@" })
         try:
             self.assertArgIsIn(m, 3)
-        except AssertionError:
+        except self.failureException:
             pass
         else:
             self.fail("test pass for not-input argument")
         m = Method(3, { "type": b"^@" }, selector=True)
         try:
             self.assertArgIsIn(m, 1)
-        except AssertionError:
+        except self.failureException:
             pass
 
         else:
         m = Method(3, { "type": b"o^@" })
         try:
             self.assertArgIsOut(m, 3)
-        except AssertionError:
+        except self.failureException:
             raise
             self.fail("test failure for input argument")
 
         m = Method(3, { "type": b"o^@" }, selector=True)
         try:
             self.assertArgIsOut(m, 1)
-        except AssertionError:
+        except self.failureException:
             self.fail("test failure for input argument")
 
         m = Method(3, { "type": b"^@" })
         try:
             self.assertArgIsOut(m, 3)
-        except AssertionError:
+        except self.failureException:
             pass
         else:
             self.fail("test pass for not-input argument")
         m = Method(3, { "type": b"^@" }, selector=True)
         try:
             self.assertArgIsOut(m, 1)
-        except AssertionError:
+        except self.failureException:
             pass
 
         else:
         m = Method(3, { "type": b"N^@" })
         try:
             self.assertArgIsInOut(m, 3)
-        except AssertionError:
+        except self.failureException:
             raise
             self.fail("test failure for input argument")
 
         m = Method(3, { "type": b"N^@" }, selector=True)
         try:
             self.assertArgIsInOut(m, 1)
-        except AssertionError:
+        except self.failureException:
             self.fail("test failure for input argument")
 
         m = Method(3, { "type": b"^@" })
         try:
             self.assertArgIsInOut(m, 3)
-        except AssertionError:
+        except self.failureException:
             pass
         else:
             self.fail("test pass for not-input argument")
         m = Method(3, { "type": b"^@" }, selector=True)
         try:
             self.assertArgIsInOut(m, 1)
-        except AssertionError:
+        except self.failureException:
             pass
 
         else:
         m = Method(3, { "type": objc._C_NSBOOL })
         try:
             self.assertArgIsBOOL(m, 3)
-        except AssertionError:
+        except self.failureException:
             raise
             self.fail("unexpected test failure")
 
         m = Method(3, { "type": objc._C_NSBOOL }, selector=True)
         try:
             self.assertArgIsBOOL(m, 1)
-        except AssertionError:
+        except self.failureException:
             self.fail("unexpected test failure")
 
         m = Method(3, { "type": b"@" })
         try:
             self.assertArgIsBOOL(m, 3)
-        except AssertionError:
+        except self.failureException:
             pass
         else:
             self.fail("unexpected test pass")
         m = Method(3, { "type": b"@" }, selector=True)
         try:
             self.assertArgIsBOOL(m, 1)
-        except AssertionError:
+        except self.failureException:
             pass
 
         else:
         m = Method(3, { 'type': objc._C_SEL, 'sel_of_type': b'v@:@' }, selector=True)
         self.assertArgIsSEL(m, 1, b'v@:@')
 
-        self.assertRaises(AssertionError, self.assertArgIsSEL, m, 2, b'v@:@')
-        self.assertRaises(AssertionError, self.assertArgIsSEL, m, 1, b'v@:')
+        self.assertRaises(self.failureException, self.assertArgIsSEL, m, 2, b'v@:@')
+        self.assertRaises(self.failureException, self.assertArgIsSEL, m, 1, b'v@:')
 
         m = Method(3, { 'type': objc._C_SEL }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsSEL, m, 1, b'v@:')
+        self.assertRaises(self.failureException, self.assertArgIsSEL, m, 1, b'v@:')
 
         m = Method(3, { 'type': objc._C_ID, 'sel_of_type': b'v@:@' }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsSEL, m, 1, b'v@:@')
+        self.assertRaises(self.failureException, self.assertArgIsSEL, m, 1, b'v@:@')
 
 
         m = Method(3, { 'type': objc._C_SEL, 'sel_of_type': b'v@:@' }, selector=False)
         self.assertArgIsSEL(m, 3, b'v@:@')
 
-        self.assertRaises(AssertionError, self.assertArgIsSEL, m, 2, b'v@:@')
-        self.assertRaises(AssertionError, self.assertArgIsSEL, m, 3, b'v@:')
+        self.assertRaises(self.failureException, self.assertArgIsSEL, m, 2, b'v@:@')
+        self.assertRaises(self.failureException, self.assertArgIsSEL, m, 3, b'v@:')
 
         m = Method(3, { 'type': objc._C_SEL }, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsSEL, m, 3, b'v@:')
+        self.assertRaises(self.failureException, self.assertArgIsSEL, m, 3, b'v@:')
 
         m = Method(3, { 'type': objc._C_ID, 'sel_of_type': b'v@:@' }, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsSEL, m, 3, b'v@:@')
+        self.assertRaises(self.failureException, self.assertArgIsSEL, m, 3, b'v@:@')
 
     def test_arg_is_function(self):
         m = Method(3, { 'type': b'^?', 'callable': {
                 ]
             }}, selector=True)
         self.assertArgIsFunction(m, 1, b'i@d', False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 0, 'v', False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 1, 'i@b', False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 1, 'i@d', True)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 0, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 1, 'i@b', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 1, 'i@d', True)
         m = Method(3, { 'type': b'^?', 'callable': {
                 'retval': { 'type': objc._C_INT },
                 'arguments': [
             },
             'callable_retained': True }, selector=True)
         self.assertArgIsFunction(m, 1, b'i@d', True)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 1, b'i@d', False)
 
         m = Method(3, { 'type': b'?', 'callable': {}}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 1, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 1, 'v', False)
 
         m = Method(3, { 'type': b'^?', }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 1, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 1, 'v', False)
         m = Method(3, { 'type': b'^?', 'callable': {}}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 1, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 1, 'v', False)
         m = Method(3, { 'type': b'^?', 'callable': { 'retval': {'type': objc._C_VOID } }}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 1, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 1, 'v', False)
 
 
 
                 ]
             }}, selector=False)
         self.assertArgIsFunction(m, 3, b'i@d', False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 2, 'v', False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 3, 'i@b', False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 3, 'i@d', True)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 2, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 3, 'i@b', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 3, 'i@d', True)
         m = Method(3, { 'type': b'^?', 'callable': {
                 'retval': { 'type': objc._C_INT },
                 'arguments': [
         self.assertArgIsFunction(m, 3, b'i@d', True)
 
         m = Method(3, { 'type': b'?', 'callable': {}}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 3, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 3, 'v', False)
 
         m = Method(3, { 'type': b'^?', }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 3, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 3, 'v', False)
         m = Method(3, { 'type': b'^?', 'callable': {}}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 3, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 3, 'v', False)
         m = Method(3, { 'type': b'^?', 'callable': { 'retval': {'type': objc._C_VOID } }}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsFunction, m, 3, 'v', False)
+        self.assertRaises(self.failureException, self.assertArgIsFunction, m, 3, 'v', False)
 
     def test_result_is_function(self):
         m = Method(None, { 'type': b'^?', 'callable': {
                 ]
             }}, selector=True)
         self.assertResultIsFunction(m, b'i@d')
-        self.assertRaises(AssertionError, self.assertResultIsFunction, m, 'i@b')
+        self.assertRaises(self.failureException, self.assertResultIsFunction, m, 'i@b')
 
         m = Method(1, {})
-        self.assertRaises(AssertionError, self.assertResultIsFunction, m, 'i@b')
+        self.assertRaises(self.failureException, self.assertResultIsFunction, m, 'i@b')
 
         m = Method(None, { 'type': b'?', 'callable': {}}, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsFunction, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsFunction, m, 'v')
 
         m = Method(None, { 'type': b'^?', }, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsFunction, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsFunction, m, 'v')
         m = Method(None, { 'type': b'^?', 'callable': {}}, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsFunction, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsFunction, m, 'v')
         m = Method(None, { 'type': b'^?', 'callable': { 'retval': {'type': objc._C_VOID } }}, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsFunction, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsFunction, m, 'v')
 
 
 
                 ]
             }}, selector=True)
         self.assertArgIsBlock(m, 1, b'i@d')
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 0, 'v')
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 1, 'i@b')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 0, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 1, 'i@b')
 
         m = Method(3, { 'type': b'@?', 'callable': {
                 'retval': { 'type': objc._C_INT },
                 ]
             },
             'callable_retained': True }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 1, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 1, 'v')
 
         m = Method(3, { 'type': b'?', 'callable': {}}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 1, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 1, 'v')
 
         m = Method(3, { 'type': b'@?', }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 1, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 1, 'v')
         m = Method(3, { 'type': b'@?', 'callable': {}}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 1, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 1, 'v')
         m = Method(3, { 'type': b'@?', 'callable': { 'retval': {'type': objc._C_VOID } }}, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 1, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 1, 'v')
 
 
 
                 ]
             }}, selector=False)
         self.assertArgIsBlock(m, 3, b'i@d')
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 2, 'v')
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 3, 'i@b')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 2, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 3, 'i@b')
 
         m = Method(3, { 'type': b'@?', 'callable': {
                 'retval': { 'type': objc._C_INT },
                 ]
             },
             'callable_retained': True }, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 3, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 3, 'v')
 
         m = Method(3, { 'type': b'?', 'callable': {}}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 3, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 3, 'v')
 
         m = Method(3, { 'type': b'@?', }, selector=True)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 3, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 3, 'v')
         m = Method(3, { 'type': b'@?', 'callable': {}}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 3, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 3, 'v')
         m = Method(3, { 'type': b'@?', 'callable': { 'retval': {'type': objc._C_VOID } }}, selector=False)
-        self.assertRaises(AssertionError, self.assertArgIsBlock, m, 3, 'v')
+        self.assertRaises(self.failureException, self.assertArgIsBlock, m, 3, 'v')
 
 
     def test_result_is_block(self):
                 ]
             }}, selector=True)
         self.assertResultIsBlock(m, b'i@d')
-        self.assertRaises(AssertionError, self.assertResultIsBlock, m, 'i@b')
+        self.assertRaises(self.failureException, self.assertResultIsBlock, m, 'i@b')
 
         m = Method(None, { 'type': b'@?', 'callable': {
                 'retval': { 'type': objc._C_INT },
                 ]
             },
             'callable_retained': True }, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsBlock, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsBlock, m, 'v')
 
         m = Method(3, {})
-        self.assertRaises(AssertionError, self.assertResultIsBlock, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsBlock, m, 'v')
 
         m = Method(None, { 'type': b'?', 'callable': {}}, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsBlock, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsBlock, m, 'v')
 
         m = Method(None, { 'type': b'@?', }, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsBlock, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsBlock, m, 'v')
         m = Method(None, { 'type': b'@?', 'callable': {}}, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsBlock, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsBlock, m, 'v')
         m = Method(None, { 'type': b'@?', 'callable': { 'retval': {'type': objc._C_VOID } }}, selector=True)
-        self.assertRaises(AssertionError, self.assertResultIsBlock, m, 'v')
+        self.assertRaises(self.failureException, self.assertResultIsBlock, m, 'v')
 
     def test_result_bool(self):
         m = Method(None, { "type": objc._C_NSBOOL })
         try:
             self.assertResultIsBOOL(m)
-        except AssertionError:
+        except self.failureException:
             raise
             self.fail("unexpected test failure")
 
         m = Method(None, { "type": objc._C_NSBOOL }, selector=True)
         try:
             self.assertResultIsBOOL(m)
-        except AssertionError:
+        except self.failureException:
             self.fail("unexpected test failure")
 
         m = Method(None, { "type": b"@" })
         try:
             self.assertResultIsBOOL(m)
-        except AssertionError:
+        except self.failureException:
             pass
         else:
             self.fail("unexpected test pass")
         m = Method(None, { "type": b"@" }, selector=True)
         try:
             self.assertResultIsBOOL(m)
-        except AssertionError:
+        except self.failureException:
             pass
 
         else:
         orig_use    = TestSupport._usepool
         orig_class = TestSupport._poolclass
         orig_run   = TestSupport._unittest.TestCase.run
-        
+
         allocs = [0]
         NSObject = objc.lookUpClass('NSObject')
         class PoolClass (object):
 
 
         TestSupport._unittest.TestCase.run = lambda self: None
-                
+
         try:
             TestSupport._poolclass = PoolClass
 

File pyobjc-core/Tools/gen_archive.py

+#!/usr/bin/env python
+import sys
+import objc
+
+from Foundation import NSArchiver, NSKeyedArchiver
+
+class Class1:
+    pass
+
+class Class2 (object):
+    pass
+
+
+def gen_archive(fname, archiver):
+    o1 = Class1()
+    o2 = Class2()
+
+    o1.a = 42
+    o1.b = 2.5
+
+    o2.obj = o1
+    o2.lst = [1,2,3]
+    o2.string = "hello world"
+
+    archiver.archiveRootObject_toFile_(o2, fname)
+
+
+def main():
+    fname = 'py%s-oc%s.%s'%(
+            sys.version_info[:1] +
+            tuple(objc.__version__.replace('a', '.').replace('b', '.').split('.')[:2]))
+
+    gen_archive(fname + '.plain', NSArchiver)
+    gen_archive(fname + '.keyed', NSKeyedArchiver)
+
+if __name__ == "__main__":
+    main()