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 testWriteEscapedFormfeed(self): s = cjsonx.encode("\f") self.assertEqual(r'"\f"', _removeWhitespace(s))
def testWriteEscapedQuotationMark(self): s = cjsonx.encode(r'"') self.assertEqual(r'"\""', _removeWhitespace(s))
def testWriteLong(self): self.assertEqual("12345678901234567890", cjsonx.encode(12345678901234567890))
def testWriteArrayOfSymbolsFromTuple(self): self.assertEqual("[true,false,null]", _removeWhitespace(cjsonx.encode((True, False, None))))
def testWriteFloat(self): self.assertEqual("3.44556677", _removeWhitespace(cjsonx.encode(3.44556677)))
def testWriteFalse(self): self.assertEqual("false", _removeWhitespace(cjsonx.encode(False)))
def testWriteNegativeDecimalInt(self): s = cjsonx.encode(decimal.Decimal("-2")) self.assertEqual("D-2", _removeWhitespace(s))
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)
def testWriteEscapedHexCharacter(self): s = cjsonx.encode(u'\u1001') self.assertEqual(r'"\u1001"', _removeWhitespace(s))
def testWriteDecimal(self): s = cjsonx.encode(decimal.Decimal("0.1")) self.assertEqual("D0.1", _removeWhitespace(s))
def testWriteEscapedHorizontalTab(self): s = cjsonx.encode("\t") self.assertEqual(r'"\t"', _removeWhitespace(s))
def testWriteEscapedCarriageReturn(self): s = cjsonx.encode("\r") self.assertEqual(r'"\r"', _removeWhitespace(s))
def testWriteEscapedNewline(self): s = cjsonx.encode("\n") self.assertEqual(r'"\n"', _removeWhitespace(s))
def testWriteSmallArray(self): self.assertEqual('[1,2,3,4]', _removeWhitespace(cjsonx.encode([1, 2, 3, 4])))
def testWriteTimeWithUseconds(self): s = cjsonx.encode(datetime.time(4, 20, 11, 11)) self.assertEqual('d"04:20:11.000011"', _removeWhitespace(s))
def testWriteSmallObject(self): s = cjsonx.encode({ "name" : "Patrick", "age": 44 }) self.assertEqual('{"age":44,"name":"Patrick"}', _removeWhitespace(s))
def testWriteDate(self): s = cjsonx.encode(datetime.date(2013, 1, 10)) self.assertEqual('d"2013-01-10"', _removeWhitespace(s))
def testWriteTrue(self): self.assertEqual("true", _removeWhitespace(cjsonx.encode(True)))
def testWriteNegativeTimedelta(self): s = cjsonx.encode(datetime.timedelta(-1, 800)) self.assertEqual('d"-01:00:13:20"', _removeWhitespace(s))
def testWriteNull(self): self.assertEqual("null", _removeWhitespace(cjsonx.encode(None)))
def testWriteNegativeTimedeltaWithUseconds(self): s = cjsonx.encode(datetime.timedelta(-1, 800, 11)) self.assertEqual('d"-01:00:13:20.000011"', _removeWhitespace(s))
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)))
def testWriteWithMagicMethodReturnsObject(self): class O(object): def __jsonx__(self): return {'a': 1} s = cjsonx.encode(O()) self.assertEqual('{"a":1}', _removeWhitespace(s))
def testStringEncoding(self): s = cjsonx.encode([1, 2, 3]) self.assertEqual(unicode("[1,2,3]", "utf-8"), _removeWhitespace(s))
def testWriteStringValue(self): s = cjsonx.encode({ "name" : "Patrick" }) self.assertEqual('{"name":"Patrick"}', _removeWhitespace(s))
def testWriteEmptyObject(self): s = cjsonx.encode({}) self.assertEqual("{}", _removeWhitespace(s))
def testWriteEmptyArray(self): self.assertEqual("[]", _removeWhitespace(cjsonx.encode([])))
def testWriteNonEscapedSolidus(self): s = cjsonx.encode(r'/') self.assertEqual(r'"/"', _removeWhitespace(s))
def testWriteEscapedBackspace(self): s = cjsonx.encode("\b") self.assertEqual(r'"\b"', _removeWhitespace(s))