Beispiel #1
0
 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)
Beispiel #2
0
    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)
Beispiel #3
0
    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)
Beispiel #4
0
 def testReadEmptyObjectAtEndOfArray(self):
     self.assertEqual(["a","b","c",{}],
                      cjsonx.decode('["a","b","c",{}]'))
Beispiel #5
0
 def testReadEmptyObjectMidArray(self):
     self.assertEqual(["a","b",{},"c"],
                      cjsonx.decode('["a","b",{},"c"]'))
Beispiel #6
0
 def testReadEmptyArray(self):
     obj = cjsonx.decode('[]')
     self.assertEqual([], obj)
Beispiel #7
0
 def testReadNegativeFloatValue(self):
     obj = cjsonx.decode(' { "key" : -44.5 } ')
     self.assertEqual({ "key" : -44.5 }, obj)
Beispiel #8
0
 def testReadEscapedQuotationMark(self):
     obj = cjsonx.decode(r'"\""')
     self.assertEqual(r'"', obj)
Beispiel #9
0
 def testReadEscapedBackspace(self):
     obj = cjsonx.decode(r'"\b"')
     self.assertEqual("\b", obj)
Beispiel #10
0
    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)
Beispiel #11
0
 def testObjectWithNonEmptyList(self):
     obj = cjsonx.decode('{"test": [3, 4, 5] }')
     self.assertEqual({"test":[3, 4, 5]}, obj)
Beispiel #12
0
 def testReadNull(self):
     self.assertEqual(None, cjsonx.decode("null"))
Beispiel #13
0
 def testReadArrayOfSymbols(self):
     self.assertEqual([True, False, None], cjsonx.decode(" [ true, false,null] "))
Beispiel #14
0
 def testReadFalse(self):
     self.assertEqual(False, cjsonx.decode("false"))
Beispiel #15
0
 def testReadTrue(self):
     self.assertEqual(True, cjsonx.decode("true"))
Beispiel #16
0
 def testReadSmallArray(self):
     obj = cjsonx.decode(' [ "a" , "b", "c" ] ')
     self.assertEqual(["a", "b", "c"], obj)
Beispiel #17
0
 def testReadClosingObjectBracket(self):
     self.assertEqual({"a":[1,2,3]}, cjsonx.decode('{"a":[1,2,3]}'))
Beispiel #18
0
 def doReadBadNumber(self):
     cjsonx.decode('-44.4.4')
Beispiel #19
0
 def testEmptyObjectInList(self):
     obj = cjsonx.decode('[{}]')
     self.assertEqual([{}], obj)
Beispiel #20
0
 def doReadIncompleteArray(self):
     cjsonx.decode('[')
Beispiel #21
0
 def testReadStringValue(self):
     obj = cjsonx.decode('{ "name" : "Patrick" }')
     self.assertEqual({ "name" : "Patrick" }, obj)
Beispiel #22
0
 def testReadEscapedNewline(self):
     obj = cjsonx.decode(r'"\n"')
     self.assertEqual("\n", obj)
Beispiel #23
0
 def testReadEscapedReverseSolidus(self):
     obj = cjsonx.decode(r'"\\"')
     self.assertEqual("\\", obj)
Beispiel #24
0
 def testReadEscapedHorizontalTab(self):
     obj = cjsonx.decode(r'"\t"')
     self.assertEqual("\t", obj)
Beispiel #25
0
 def testReadEscapedFormfeed(self):
     obj = cjsonx.decode(r'"\f"')
     self.assertEqual("\f", obj)
Beispiel #26
0
 def testReadSmallObject(self):
     obj = cjsonx.decode('{ "name" : "Patrick", "age":44} ')
     self.assertEqual({ "age" : 44, "name" : "Patrick" }, obj)        
Beispiel #27
0
 def testReadEscapedCarriageReturn(self):
     obj = cjsonx.decode(r'"\r"')
     self.assertEqual("\r", obj)
Beispiel #28
0
 def testReadEmptyObject(self):
     obj = cjsonx.decode("{}")
     self.assertEqual({}, obj)
Beispiel #29
0
 def testReadEscapedHexCharacter(self):
     obj = cjsonx.decode(r'"\u000A"')
     self.assertEqual("\n", obj)
     obj = cjsonx.decode(r'"\u1001"')
     self.assertEqual(u'\u1001', obj)
Beispiel #30
0
 def testReadFloatValue(self):
     obj = cjsonx.decode('{ "age" : 44.5 }')
     self.assertEqual({ "age" : 44.5 }, obj)