示例#1
0
文件: tests.py 项目: petronius/cjsonx
 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)
示例#2
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEscapedFormfeed(self):
     s = cjsonx.encode("\f")
     self.assertEqual(r'"\f"', _removeWhitespace(s))
示例#3
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEscapedQuotationMark(self):
     s = cjsonx.encode(r'"')
     self.assertEqual(r'"\""', _removeWhitespace(s))
示例#4
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteLong(self):
     self.assertEqual("12345678901234567890", cjsonx.encode(12345678901234567890))
示例#5
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteArrayOfSymbolsFromTuple(self):
     self.assertEqual("[true,false,null]", _removeWhitespace(cjsonx.encode((True, False, None))))
示例#6
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteFloat(self):
     self.assertEqual("3.44556677", _removeWhitespace(cjsonx.encode(3.44556677)))
示例#7
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteFalse(self):
     self.assertEqual("false", _removeWhitespace(cjsonx.encode(False)))
示例#8
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteNegativeDecimalInt(self):
     s = cjsonx.encode(decimal.Decimal("-2"))
     self.assertEqual("D-2", _removeWhitespace(s))
示例#9
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteDateTimeWithUseconds(self):
     s = cjsonx.encode(datetime.datetime(2013, 1, 10, 4, 20, 11, 11))
     self.assertEqual('d"2013-01-10 04:20:11.000011"', s)
示例#10
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEscapedHexCharacter(self):
     s = cjsonx.encode(u'\u1001')
     self.assertEqual(r'"\u1001"', _removeWhitespace(s))
示例#11
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteDecimal(self):
     s = cjsonx.encode(decimal.Decimal("0.1"))
     self.assertEqual("D0.1", _removeWhitespace(s))
示例#12
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEscapedHorizontalTab(self):
     s = cjsonx.encode("\t")
     self.assertEqual(r'"\t"', _removeWhitespace(s))
示例#13
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEscapedCarriageReturn(self):
     s = cjsonx.encode("\r")
     self.assertEqual(r'"\r"', _removeWhitespace(s))
示例#14
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEscapedNewline(self):
     s = cjsonx.encode("\n")
     self.assertEqual(r'"\n"', _removeWhitespace(s))
示例#15
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteSmallArray(self):
     self.assertEqual('[1,2,3,4]', _removeWhitespace(cjsonx.encode([1, 2, 3, 4])))
示例#16
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteTimeWithUseconds(self):
     s = cjsonx.encode(datetime.time(4, 20, 11, 11))
     self.assertEqual('d"04:20:11.000011"', _removeWhitespace(s))
示例#17
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteSmallObject(self):
     s = cjsonx.encode({ "name" : "Patrick", "age": 44 })
     self.assertEqual('{"age":44,"name":"Patrick"}', _removeWhitespace(s))
示例#18
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteDate(self):
     s = cjsonx.encode(datetime.date(2013, 1, 10))
     self.assertEqual('d"2013-01-10"', _removeWhitespace(s))
示例#19
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteTrue(self):
     self.assertEqual("true", _removeWhitespace(cjsonx.encode(True)))
示例#20
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteNegativeTimedelta(self):
     s = cjsonx.encode(datetime.timedelta(-1, 800))
     self.assertEqual('d"-01:00:13:20"', _removeWhitespace(s))
示例#21
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteNull(self):
     self.assertEqual("null", _removeWhitespace(cjsonx.encode(None)))
示例#22
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteNegativeTimedeltaWithUseconds(self):
     s = cjsonx.encode(datetime.timedelta(-1, 800, 11))
     self.assertEqual('d"-01:00:13:20.000011"', _removeWhitespace(s))
示例#23
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteComplexArray(self):
     obj = [{"name":"Patrick","age":44,"Employed?":True,"Female?":False,"grandchildren":None},
            "used","abused","confused",
            1,2,[3,4,5]]
     self.assertEqual('[{"Employed?":true,"Female?":false,"age":44,"grandchildren":null,"name":"Patrick"},"used","abused","confused",1,2,[3,4,5]]',
                      _removeWhitespace(cjsonx.encode(obj)))
示例#24
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteWithMagicMethodReturnsObject(self):
     class O(object):
         def __jsonx__(self):
             return {'a': 1}
     s = cjsonx.encode(O())
     self.assertEqual('{"a":1}', _removeWhitespace(s))
示例#25
0
文件: tests.py 项目: petronius/cjsonx
 def testStringEncoding(self):
     s = cjsonx.encode([1, 2, 3])
     self.assertEqual(unicode("[1,2,3]", "utf-8"), _removeWhitespace(s))
示例#26
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteStringValue(self):
     s = cjsonx.encode({ "name" : "Patrick" })
     self.assertEqual('{"name":"Patrick"}', _removeWhitespace(s))
示例#27
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEmptyObject(self):
     s = cjsonx.encode({})
     self.assertEqual("{}", _removeWhitespace(s))
示例#28
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEmptyArray(self):
     self.assertEqual("[]", _removeWhitespace(cjsonx.encode([])))
示例#29
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteNonEscapedSolidus(self):
     s = cjsonx.encode(r'/')
     self.assertEqual(r'"/"', _removeWhitespace(s))
示例#30
0
文件: tests.py 项目: petronius/cjsonx
 def testWriteEscapedBackspace(self):
     s = cjsonx.encode("\b")
     self.assertEqual(r'"\b"', _removeWhitespace(s))