Example #1
0
 def test_simple_serializer(self):
     ser = Serializer()
     obj = {'t1':'test', }
     data = ser.serialize(obj)
     self.assertEqual(data[0], '0')
     
     obj1 = ser.deserialize(data)
     
     self.assertTrue(isinstance(obj1, dict))
     self.assertEqual(obj1.keys(), ['t1', ])
     self.assertEqual(obj1['t1'], 'test')
     self.assertNotEqual(id(obj1), id(obj))
     
     obj2 = {'t12':'test2', }
     data = ser.serialize(obj2)
     obj3 = ser.deserialize(data)
     
     self.assertEqual(obj2, obj3)
Example #2
0
 def test_compress_serializer(self):
     ser = Serializer()
     obj = {'t1':'test' * 1024 , }
     data = ser.serialize(obj)
     
     self.assertEqual(data[0], '1')
     self.assertEqual(len(data), 74)
     
     obj1 = ser.deserialize(data)
     self.assertEqual(obj, obj1)
Example #3
0
 def test_rpc_stub(self):
     service = RPCStub('', RemoteClass(), )
     ser = Serializer()
     args = 'args'
     
     method = 'rpc_func'
     params = ser.serialize(((args, ), {}))
     
     data = service(method, params)
     
     (ret, e) = ser.deserialize(data)
     
     self.assertEqual(ret, "xxx:%s" % args)
     self.assertEqual(e, None)
Example #4
0
 def test_serializer_with_namespaces(self):
     ns = lambda x:1
     ns.MockClass = MockClass2
     
     ser = Serializer([ns, ])
     obj = MockClass('test')
     obj.test = 'testvalue1'
     data = ser.serialize(obj)
     
     obj1 = ser.deserialize(data)
     
     self.assertEqual(type(obj1), MockClass2)
     self.assertEqual(obj1.test, 'testvalue1')
     self.assertEqual(obj1.value, 'test')