def backwards_compatible(self, val): print "new", self new_enc = newmummy.dumps(val) print "old", self old_enc = oldmummy.dumps(val) # they serialize to the same string self.assertEqual(new_enc, old_enc)
def test(serial, deserial, data): assert equalish(deserial(serial(data)), data) def format(flt, prec=3): s = str(round(flt, prec)) return padright(s, s.index(".") + 4, "0") def padright(s, upto, padchar=" "): return s + (padchar * (upto - len(s))) contenders = [ ('mummy', (lambda s: mummy.dumps(s), mummy.loads)), ('oldmummy', (lambda s: oldmummy.dumps(s), oldmummy.loads))] if wbin: contenders.append(('wirebin', (wbin.serialize, wbin.deserialize))) if msgpack: contenders.append(('msgpack', (msgpack.dumps, msgpack.loads))) if yajl: contenders.append(('py-yajl', (yajl.dumps, yajl.loads))) if cjson: contenders.append(('cjson', (cjson.encode, cjson.decode))) if bson: contenders.append(('bson', (bson.BSON.encode, lambda s: bson.BSON(s).decode()))) #contenders.append(('cPickle (protocol 2)', # (lambda x: cPickle.dumps(x, 2), cPickle.loads))) #contenders.append(('cPickle (protocol 1)', # (lambda x: cPickle.dumps(x, 1), cPickle.loads))) #contenders.append(('cPickle (protocol 0)', (cPickle.dumps, cPickle.loads)))