class testJSONThunker(unittest.TestCase): """ Direct tests of thunking standard python type """ def setUp(self): self.thunker = JSONThunker() def roundTrip(self, data): encoded = self.thunker.thunk(data) decoded = self.thunker.unthunk(encoded) self.assertEqual(data, decoded) def testStr(self): self.roundTrip('hello') def testList(self): self.roundTrip([123, 456]) def testDict(self): self.roundTrip({'abc': 123, 'def': 456}) self.roundTrip({'abc': 123, 456: 'def'}) def testSet(self): self.roundTrip(set([])) self.roundTrip(set([123, 'abc']))
class testThunking(unittest.TestCase): """ Direct tests of thunking standard python type """ def setUp(self): self.thunker = JSONThunker() def roundTrip(self, data): encoded = self.thunker.thunk(data) decoded = self.thunker.unthunk(encoded) self.assertEqual( data, decoded ) @runboth def testStr(self): self.roundTrip('hello') @runboth def testList(self): self.roundTrip([123, 456]) @runboth def testDict(self): self.roundTrip({'abc':123, 'def':456}) self.roundTrip({'abc':123, 456:'def'}) @runboth def testSet(self): self.roundTrip(set([])) self.roundTrip(set([123, 'abc']))
def decode(self, data): """ decode the data to python from json """ if data: decoder = JSONDecoder() thunker = JSONThunker() data = decoder.decode(data) unthunked = thunker.unthunk(data) return unthunked return {}
def decode(self, data): """ decode the data to python from json """ if data: decoder = JSONDecoder() thunker = JSONThunker() data = decoder.decode(data) unthunked = thunker.unthunk(data) return unthunked else: return {}
def decode(self, data): """ decode the data to python from json """ if data: decoder = JSONDecoder() thunker = JSONThunker() if sys.version_info[0] == 3: data = decodeBytesToUnicode(data) data = decoder.decode(data) unthunked = thunker.unthunk(data) return unthunked return {}
def jsonThunkerDecoder(self, data): if data: thunker = JSONThunker() return thunker.unthunk(JsonWrapper.loads(data)) else: return {}
def jsonThunkerDecoder(self, data): if data: thunker = JSONThunker() return thunker.unthunk(JsonWrapper.loads(data)) else: return {}