예제 #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))