def testReadWriteCopies(self): orig_obj = {'a':' " '} json_str = cjsonx.encode(orig_obj) copy_obj = cjsonx.decode(json_str) self.assertEqual(orig_obj, copy_obj) self.assertEqual(True, orig_obj == copy_obj) self.assertEqual(False, orig_obj is copy_obj)
def testReadLongArray(self): src = '''[ "used", "abused", "confused", true, false, null, 1, 2, [3, 4, 5]] ''' obj = cjsonx.decode(src) self.assertEqual(["used","abused","confused", True, False, None, 1,2,[3,4,5]], obj)
def testReadComplexArray(self): src = ''' [ { "name": "Patrick", "age" : 44, "Employed?" : true, "Female?" : false, "grandchildren":null }, "used", "abused", "confused", 1, 2, [3, 4, 5] ] ''' obj = cjsonx.decode(src) self.assertEqual([{"name":"Patrick","age":44,"Employed?":True,"Female?":False,"grandchildren":None}, "used","abused","confused", 1,2,[3,4,5]], obj)
def testReadEmptyObjectAtEndOfArray(self): self.assertEqual(["a","b","c",{}], cjsonx.decode('["a","b","c",{}]'))
def testReadEmptyObjectMidArray(self): self.assertEqual(["a","b",{},"c"], cjsonx.decode('["a","b",{},"c"]'))
def testReadEmptyArray(self): obj = cjsonx.decode('[]') self.assertEqual([], obj)
def testReadNegativeFloatValue(self): obj = cjsonx.decode(' { "key" : -44.5 } ') self.assertEqual({ "key" : -44.5 }, obj)
def testReadEscapedQuotationMark(self): obj = cjsonx.decode(r'"\""') self.assertEqual(r'"', obj)
def testReadEscapedBackspace(self): obj = cjsonx.decode(r'"\b"') self.assertEqual("\b", obj)
def testReadComplexObject(self): src = ''' { "name": "Patrick", "age" : 44, "Employed?" : true, "Female?" : false, "grandchildren":null } ''' obj = cjsonx.decode(src) self.assertEqual({"name":"Patrick","age":44,"Employed?":True,"Female?":False,"grandchildren":None}, obj)
def testObjectWithNonEmptyList(self): obj = cjsonx.decode('{"test": [3, 4, 5] }') self.assertEqual({"test":[3, 4, 5]}, obj)
def testReadNull(self): self.assertEqual(None, cjsonx.decode("null"))
def testReadArrayOfSymbols(self): self.assertEqual([True, False, None], cjsonx.decode(" [ true, false,null] "))
def testReadFalse(self): self.assertEqual(False, cjsonx.decode("false"))
def testReadTrue(self): self.assertEqual(True, cjsonx.decode("true"))
def testReadSmallArray(self): obj = cjsonx.decode(' [ "a" , "b", "c" ] ') self.assertEqual(["a", "b", "c"], obj)
def testReadClosingObjectBracket(self): self.assertEqual({"a":[1,2,3]}, cjsonx.decode('{"a":[1,2,3]}'))
def doReadBadNumber(self): cjsonx.decode('-44.4.4')
def testEmptyObjectInList(self): obj = cjsonx.decode('[{}]') self.assertEqual([{}], obj)
def doReadIncompleteArray(self): cjsonx.decode('[')
def testReadStringValue(self): obj = cjsonx.decode('{ "name" : "Patrick" }') self.assertEqual({ "name" : "Patrick" }, obj)
def testReadEscapedNewline(self): obj = cjsonx.decode(r'"\n"') self.assertEqual("\n", obj)
def testReadEscapedReverseSolidus(self): obj = cjsonx.decode(r'"\\"') self.assertEqual("\\", obj)
def testReadEscapedHorizontalTab(self): obj = cjsonx.decode(r'"\t"') self.assertEqual("\t", obj)
def testReadEscapedFormfeed(self): obj = cjsonx.decode(r'"\f"') self.assertEqual("\f", obj)
def testReadSmallObject(self): obj = cjsonx.decode('{ "name" : "Patrick", "age":44} ') self.assertEqual({ "age" : 44, "name" : "Patrick" }, obj)
def testReadEscapedCarriageReturn(self): obj = cjsonx.decode(r'"\r"') self.assertEqual("\r", obj)
def testReadEmptyObject(self): obj = cjsonx.decode("{}") self.assertEqual({}, obj)
def testReadEscapedHexCharacter(self): obj = cjsonx.decode(r'"\u000A"') self.assertEqual("\n", obj) obj = cjsonx.decode(r'"\u1001"') self.assertEqual(u'\u1001', obj)
def testReadFloatValue(self): obj = cjsonx.decode('{ "age" : 44.5 }') self.assertEqual({ "age" : 44.5 }, obj)