Exemplo n.º 1
0
        def testSimpleDicts(self):
            o = {}
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, dict))
            self.assertEquals(v, o)

            o = {u"hello": u"bar", 42: 1.5 }
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, dict))
            self.assertEquals(v, o)
Exemplo n.º 2
0
        def testSimpleTuples(self):
            o = ()
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, tuple))
            self.assertEquals(v, o)

            o = (u"hello", 42)
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, tuple))
            self.assertEquals(v, o)
Exemplo n.º 3
0
        def testSimpleLists(self):
            o = []
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, list))
            self.assertEquals(v, o)

            o = [u"hello", 42]
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, list))
            self.assertEquals(v, o)
Exemplo n.º 4
0
        def testNestedDicts(self):
            o = {
                    u"hello": { 1:2 },
                    u"world": u"foobar"
                }
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, dict))
            self.assertEquals(v, o)

            o = {}
            o[u'self'] = o
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, dict))
            self.assert_(v[u'self'] is v)
Exemplo n.º 5
0
        def testNestedInstance(self):
            o = a_classic_class()
            o.value = o

            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)

            self.assert_(isinstance(v, a_classic_class))
            self.assert_(v.value is v)
Exemplo n.º 6
0
        def testNestedSequences(self):
            o = [ 1, 2, 3, (5, (u'a', u'b'), 6), {1:2} ]
            o[-1] = o

            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, list))
            self.assert_(v[-1] is v)
            self.assertEquals(v[:-1], o[:-1])
Exemplo n.º 7
0
        def testRecusiveNesting(self):
            l = []
            d = {1:l}
            i = a_classic_class()
            i.attr = d
            l.append(i)

            buf = NSKeyedArchiver.archivedDataWithRootObject_(l)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)

            self.assertEquals(len(v), 1)
            self.assertEquals(dir(v[0]), dir(i))
            self.assertEquals(v[0].attr.keys(), [1])
            self.assert_(v[0].attr[1] is v)

            buf = NSKeyedArchiver.archivedDataWithRootObject_(d)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(v[1][0].attr is v)
Exemplo n.º 8
0
        def testTupleOfObjects(self):
            o = a_classic_class()
            t = (o, o, o)

            buf = NSKeyedArchiver.archivedDataWithRootObject_(t)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)

            self.assert_(isinstance(v, tuple))
            self.assert_(len(v) == 3)
            self.assert_(isinstance(v[0], a_classic_class))
            self.assert_(v[0] is v[1])
            self.assert_(v[0] is v[2])
Exemplo n.º 9
0
        def testBasicObjects(self):
            buf = NSKeyedArchiver.archivedDataWithRootObject_(a_function)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(v is a_function)

            buf = NSKeyedArchiver.archivedDataWithRootObject_(a_classic_class)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(v is a_classic_class)

            buf = NSKeyedArchiver.archivedDataWithRootObject_(a_newstyle_class)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(v is a_newstyle_class)

            o = a_classic_class()
            o.x = 42
            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, a_classic_class))
            self.assertEquals(o.x, 42)

            buf = NSKeyedArchiver.archivedDataWithRootObject_(u"hello")
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, unicode))

            buf = NSKeyedArchiver.archivedDataWithRootObject_("hello")
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, str))
            self.assertEquals(v, "hello")

            buf = NSKeyedArchiver.archivedDataWithRootObject_(sys.maxint * 4)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, long))
            self.assertEquals(v, sys.maxint * 4)

            buf = NSKeyedArchiver.archivedDataWithRootObject_(sys.maxint ** 4)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)
            self.assert_(isinstance(v, long))
            self.assertEquals(v, sys.maxint ** 4)
Exemplo n.º 10
0
        def dont_testNestedInstanceWithReduce(self):
            # Test recursive instantation with a __reduce__ method
            #
            # This test is disabled because pickle doesn't support
            # this (and we don't either)
            o = a_reducing_class()
            o.value = o

            import pickle
            b = pickle.dumps(o)
            o2 = picle.loads(b)
            print "+++", o2.value is o2

            buf = NSKeyedArchiver.archivedDataWithRootObject_(o)
            self.assert_(isinstance(buf, NSData))
            v = NSKeyedUnarchiver.unarchiveObjectWithData_(buf)

            self.assert_(isinstance(v, a_reducing_class))
            print type(v.value)
            print v.value
            print v
            self.assert_(v.value is v)
 def dumps(self, arg, proto=0, fast=0):
     # Ignore proto and fast
     return NSKeyedArchiver.archivedDataWithRootObject_(arg)
Exemplo n.º 12
0
 def dumps(self, arg, proto=0, fast=0):
     # Ignore proto and fast
     return NSKeyedArchiver.archivedDataWithRootObject_(arg)