tests.py
Go to the documentation of this file.
00001 
00002 try:
00003     import unittest2 as unittest
00004 except ImportError:
00005     import unittest
00006 from unittest import TestCase
00007 
00008 import ujson
00009 try:
00010     import json
00011 except ImportError:
00012     import simplejson as json
00013 import math
00014 import platform
00015 import sys
00016 import time
00017 import datetime
00018 import calendar
00019 import StringIO
00020 import re
00021 from functools import partial
00022 
00023 PY3 = (sys.version_info[0] >= 3)
00024 
00025 def _python_ver(skip_major, skip_minor=None):
00026     major, minor = sys.version_info[:2]
00027     return major == skip_major and (skip_minor is None or minor == skip_minor)
00028 
00029 json_unicode = (json.dumps if sys.version_info[0] >= 3
00030                 else partial(json.dumps, encoding="utf-8"))
00031 
00032 class UltraJSONTests(TestCase):
00033     def test_encodeDictWithUnicodeKeys(self):
00034         input = { u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1" }
00035         output = ujson.encode(input)
00036 
00037         input = { u"بن": u"value1", u"بن": u"value1", u"بن": u"value1", u"بن": u"value1", u"بن": u"value1", u"بن": u"value1", u"بن": u"value1" }
00038         output = ujson.encode(input)
00039 
00040         pass
00041 
00042     def test_encodeDoubleConversion(self):
00043         input = math.pi
00044         output = ujson.encode(input)
00045         self.assertEquals(round(input, 5), round(json.loads(output), 5))
00046         self.assertEquals(round(input, 5), round(ujson.decode(output), 5))
00047         
00048     def test_encodeWithDecimal(self):
00049         input = 1.0
00050         output = ujson.encode(input)
00051         self.assertEquals(output, "1.0")
00052 
00053     def test_encodeDoubleNegConversion(self):
00054         input = -math.pi
00055         output = ujson.encode(input)
00056         self.assertEquals(round(input, 5), round(json.loads(output), 5))
00057         self.assertEquals(round(input, 5), round(ujson.decode(output), 5))
00058 
00059     def test_encodeArrayOfNestedArrays(self):
00060         input = [[[[]]]] * 20
00061         output = ujson.encode(input)
00062         self.assertEquals(input, json.loads(output))
00063         #self.assertEquals(output, json.dumps(input))
00064         self.assertEquals(input, ujson.decode(output))
00065 
00066     def test_encodeArrayOfDoubles(self):
00067         input = [ 31337.31337, 31337.31337, 31337.31337, 31337.31337] * 10
00068         output = ujson.encode(input)
00069         self.assertEquals(input, json.loads(output))
00070         #self.assertEquals(output, json.dumps(input))
00071         self.assertEquals(input, ujson.decode(output))
00072 
00073     def test_doublePrecisionTest(self):
00074         input = 30.012345678901234
00075         output = ujson.encode(input, double_precision = 15)
00076         self.assertEquals(input, json.loads(output))
00077         self.assertEquals(input, ujson.decode(output))
00078 
00079         output = ujson.encode(input, double_precision = 9)
00080         self.assertEquals(round(input, 9), json.loads(output))
00081         self.assertEquals(round(input, 9), ujson.decode(output))
00082 
00083         output = ujson.encode(input, double_precision = 3)
00084         self.assertEquals(round(input, 3), json.loads(output))
00085         self.assertEquals(round(input, 3), ujson.decode(output))
00086 
00087         output = ujson.encode(input)
00088         self.assertEquals(round(input, 5), json.loads(output))
00089         self.assertEquals(round(input, 5), ujson.decode(output))
00090 
00091     def test_invalidDoublePrecision(self):
00092         input = 30.12345678901234567890
00093         output = ujson.encode(input, double_precision = 20)
00094         # should snap to the max, which is 15
00095         self.assertEquals(round(input, 15), json.loads(output))
00096         self.assertEquals(round(input, 15), ujson.decode(output))
00097 
00098         output = ujson.encode(input, double_precision = -1)
00099         # also should snap to the max, which is 15
00100         self.assertEquals(round(input, 15), json.loads(output))
00101         self.assertEquals(round(input, 15), ujson.decode(output))
00102 
00103         # will throw typeError
00104         self.assertRaises(TypeError, ujson.encode, input, double_precision = '9')
00105         # will throw typeError
00106         self.assertRaises(TypeError, ujson.encode, input, double_precision = None)
00107 
00108 
00109     def test_encodeStringConversion(self):
00110         input = "A string \\ / \b \f \n \r \t"
00111         output = ujson.encode(input)
00112         self.assertEquals(input, json.loads(output))
00113         self.assertEquals(output, '"A string \\\\ \\/ \\b \\f \\n \\r \\t"')
00114         self.assertEquals(input, ujson.decode(output))
00115         pass
00116 
00117     def test_decodeUnicodeConversion(self):
00118         pass
00119 
00120     def test_encodeUnicodeConversion1(self):
00121         input = "Räksmörgås اسامة بن محمد بن عوض بن لادن"
00122         enc = ujson.encode(input)
00123         dec = ujson.decode(enc)
00124         self.assertEquals(enc, json_unicode(input))
00125         self.assertEquals(dec, json.loads(enc))
00126         
00127     def test_encodeControlEscaping(self):
00128         input = "\x19"
00129         enc = ujson.encode(input)
00130         dec = ujson.decode(enc)
00131         self.assertEquals(input, dec)
00132         self.assertEquals(enc, json_unicode(input))
00133 
00134 
00135     def test_encodeUnicodeConversion2(self):
00136         input = "\xe6\x97\xa5\xd1\x88"
00137         enc = ujson.encode(input)
00138         dec = ujson.decode(enc)
00139         self.assertEquals(enc, json_unicode(input))
00140         self.assertEquals(dec, json.loads(enc))
00141 
00142     def test_encodeUnicodeSurrogatePair(self):
00143         input = "\xf0\x90\x8d\x86"
00144         enc = ujson.encode(input)
00145         dec = ujson.decode(enc)
00146 
00147         self.assertEquals(enc, json_unicode(input))
00148         self.assertEquals(dec, json.loads(enc))
00149 
00150     def test_encodeUnicode4BytesUTF8(self):
00151         input = "\xf0\x91\x80\xb0TRAILINGNORMAL"
00152         enc = ujson.encode(input)
00153         dec = ujson.decode(enc)
00154 
00155         self.assertEquals(enc, json_unicode(input))
00156         self.assertEquals(dec, json.loads(enc))
00157             
00158     def test_encodeUnicode4BytesUTF8Highest(self):
00159         input = "\xf3\xbf\xbf\xbfTRAILINGNORMAL"
00160         enc = ujson.encode(input)
00161 
00162         dec = ujson.decode(enc)
00163 
00164         self.assertEquals(enc, json_unicode(input))
00165         self.assertEquals(dec, json.loads(enc))
00166 
00167         
00168     def test_encodeArrayInArray(self):
00169         input = [[[[]]]]
00170         output = ujson.encode(input)
00171 
00172         self.assertEquals(input, json.loads(output))
00173         self.assertEquals(output, json.dumps(input))
00174         self.assertEquals(input, ujson.decode(output))
00175         pass
00176 
00177     def test_encodeIntConversion(self):
00178         input = 31337
00179         output = ujson.encode(input)
00180         self.assertEquals(input, json.loads(output))
00181         self.assertEquals(output, json.dumps(input))
00182         self.assertEquals(input, ujson.decode(output))
00183         pass
00184 
00185     def test_encodeIntNegConversion(self):
00186         input = -31337
00187         output = ujson.encode(input)
00188         self.assertEquals(input, json.loads(output))
00189         self.assertEquals(output, json.dumps(input))
00190         self.assertEquals(input, ujson.decode(output))
00191         pass
00192         
00193 
00194     def test_encodeLongNegConversion(self):
00195         input = -9223372036854775808
00196         output = ujson.encode(input)
00197 
00198         outputjson = json.loads(output)
00199         outputujson = ujson.decode(output)
00200 
00201         self.assertEquals(input, json.loads(output))
00202         self.assertEquals(output, json.dumps(input))
00203         self.assertEquals(input, ujson.decode(output))
00204         pass
00205 
00206     def test_encodeListConversion(self):
00207         input = [ 1, 2, 3, 4 ]
00208         output = ujson.encode(input)
00209         self.assertEquals(input, json.loads(output))
00210         self.assertEquals(input, ujson.decode(output))
00211         pass
00212 
00213     def test_encodeDictConversion(self):
00214         input = { "k1": 1, "k2":  2, "k3": 3, "k4": 4 }
00215         output = ujson.encode(input)
00216         self.assertEquals(input, json.loads(output))
00217         self.assertEquals(input, ujson.decode(output))
00218         self.assertEquals(input, ujson.decode(output))
00219         pass
00220 
00221     def test_encodeNoneConversion(self):
00222         input = None
00223         output = ujson.encode(input)
00224         self.assertEquals(input, json.loads(output))
00225         self.assertEquals(output, json.dumps(input))
00226         self.assertEquals(input, ujson.decode(output))
00227         pass
00228 
00229     def test_encodeTrueConversion(self):
00230         input = True
00231         output = ujson.encode(input)
00232         self.assertEquals(input, json.loads(output))
00233         self.assertEquals(output, json.dumps(input))
00234         self.assertEquals(input, ujson.decode(output))
00235         pass
00236 
00237     def test_encodeFalseConversion(self):
00238         input = False
00239         output = ujson.encode(input)
00240         self.assertEquals(input, json.loads(output))
00241         self.assertEquals(output, json.dumps(input))
00242         self.assertEquals(input, ujson.decode(output))
00243         pass
00244 
00245     def test_encodeDatetimeConversion(self):
00246         ts = time.time()
00247         input = datetime.datetime.fromtimestamp(ts)
00248         output = ujson.encode(input)
00249         expected = calendar.timegm(input.utctimetuple())
00250         self.assertEquals(int(expected), json.loads(output))
00251         self.assertEquals(int(expected), ujson.decode(output))
00252         pass
00253 
00254     def test_encodeDateConversion(self):
00255         ts = time.time()
00256         input = datetime.date.fromtimestamp(ts)
00257 
00258         output = ujson.encode(input)
00259         tup = ( input.year, input.month, input.day, 0, 0, 0 )
00260 
00261         expected = calendar.timegm(tup)
00262         self.assertEquals(int(expected), json.loads(output))
00263         self.assertEquals(int(expected), ujson.decode(output))
00264         pass
00265 
00266     def test_encodeToUTF8(self):
00267         input = "\xe6\x97\xa5\xd1\x88"
00268         enc = ujson.encode(input, ensure_ascii=False)
00269         dec = ujson.decode(enc)
00270         self.assertEquals(enc, json_unicode(input, ensure_ascii=False))
00271         self.assertEquals(dec, json.loads(enc))
00272 
00273     def test_decodeFromUnicode(self):
00274         input = u"{\"obj\": 31337}"
00275         dec1 = ujson.decode(input)
00276         dec2 = ujson.decode(str(input))
00277         self.assertEquals(dec1, dec2)
00278 
00279     def test_encodeRecursionMax(self):
00280         # 8 is the max recursion depth
00281 
00282         class O2:
00283             member = 0
00284             pass        
00285 
00286         class O1:
00287             member = 0
00288             pass
00289 
00290         input = O1()
00291         input.member = O2()
00292         input.member.member = input
00293 
00294         try:
00295             output = ujson.encode(input)
00296             assert False, "Expected overflow exception"
00297         except(OverflowError):
00298             pass
00299 
00300     def test_encodeDoubleNan(self):
00301         input = float('nan')
00302         try:
00303             ujson.encode(input)
00304             assert False, "Expected exception!"
00305         except(OverflowError):
00306             return
00307         assert False, "Wrong exception"
00308         
00309     def test_encodeDoubleInf(self):
00310         input = float('inf')
00311         try:
00312             ujson.encode(input)
00313             assert False, "Expected exception!"
00314         except(OverflowError):
00315             return
00316         assert False, "Wrong exception"
00317             
00318     def test_encodeDoubleNegInf(self):
00319         input = -float('inf')
00320         try:
00321             ujson.encode(input)
00322             assert False, "Expected exception!"
00323         except(OverflowError):
00324             return
00325         assert False, "Wrong exception"
00326             
00327 
00328     def test_decodeJibberish(self):
00329         input = "fdsa sda v9sa fdsa"
00330         try:
00331             ujson.decode(input)
00332             assert False, "Expected exception!"
00333         except(ValueError):
00334             return
00335         assert False, "Wrong exception"
00336 
00337     def test_decodeBrokenArrayStart(self):
00338         input = "["
00339         try:
00340             ujson.decode(input)
00341             assert False, "Expected exception!"
00342         except(ValueError):
00343             return
00344         assert False, "Wrong exception"
00345 
00346     def test_decodeBrokenObjectStart(self):
00347         input = "{"
00348         try:
00349             ujson.decode(input)
00350             assert False, "Expected exception!"
00351         except(ValueError):
00352             return
00353         assert False, "Wrong exception"
00354 
00355     def test_decodeBrokenArrayEnd(self):
00356         input = "]"
00357         try:
00358             ujson.decode(input)
00359             assert False, "Expected exception!"
00360         except(ValueError):
00361             return
00362         assert False, "Wrong exception"
00363 
00364     def test_decodeBrokenObjectEnd(self):
00365         input = "}"
00366         try:
00367             ujson.decode(input)
00368             assert False, "Expected exception!"
00369         except(ValueError):
00370             return
00371         assert False, "Wrong exception"
00372 
00373     def test_decodeStringUnterminated(self):
00374         input = "\"TESTING"
00375         try:
00376             ujson.decode(input)
00377             assert False, "Expected exception!"
00378         except(ValueError):
00379             return
00380         assert False, "Wrong exception"
00381 
00382     def test_decodeStringUntermEscapeSequence(self):
00383         input = "\"TESTING\\\""
00384         try:
00385             ujson.decode(input)
00386             assert False, "Expected exception!"
00387         except(ValueError):
00388             return
00389         assert False, "Wrong exception"
00390 
00391     def test_decodeStringBadEscape(self):
00392         input = "\"TESTING\\\""
00393         try:
00394             ujson.decode(input)
00395             assert False, "Expected exception!"
00396         except(ValueError):
00397             return
00398         assert False, "Wrong exception"
00399 
00400     def test_decodeTrueBroken(self):
00401         input = "tru"
00402         try:
00403             ujson.decode(input)
00404             assert False, "Expected exception!"
00405         except(ValueError):
00406             return
00407         assert False, "Wrong exception"
00408 
00409     def test_decodeFalseBroken(self):
00410         input = "fa"
00411         try:
00412             ujson.decode(input)
00413             assert False, "Expected exception!"
00414         except(ValueError):
00415             return
00416         assert False, "Wrong exception"
00417 
00418     def test_decodeNullBroken(self):
00419         input = "n"
00420         try:
00421             ujson.decode(input)
00422             assert False, "Expected exception!"
00423         except(ValueError):
00424             return
00425         assert False, "Wrong exception"
00426             
00427 
00428     def test_decodeBrokenDictKeyTypeLeakTest(self):
00429         input = '{{1337:""}}'
00430         for x in xrange(1000):
00431             try:
00432                 ujson.decode(input)
00433                 assert False, "Expected exception!"
00434             except(ValueError),e:
00435                 continue
00436 
00437             assert False, "Wrong exception"
00438             
00439     def test_decodeBrokenDictLeakTest(self):
00440         input = '{{"key":"}'
00441         for x in xrange(1000):
00442             try:
00443                 ujson.decode(input)
00444                 assert False, "Expected exception!"
00445             except(ValueError):
00446                 continue
00447 
00448             assert False, "Wrong exception"
00449             
00450     def test_decodeBrokenListLeakTest(self):
00451         input = '[[[true'
00452         for x in xrange(1000):
00453             try:
00454                 ujson.decode(input)
00455                 assert False, "Expected exception!"
00456             except(ValueError):
00457                 continue
00458 
00459             assert False, "Wrong exception"
00460 
00461     def test_decodeDictWithNoKey(self):
00462         input = "{{{{31337}}}}"
00463         try:
00464             ujson.decode(input)
00465             assert False, "Expected exception!"
00466         except(ValueError):
00467             return
00468 
00469         assert False, "Wrong exception"
00470 
00471     def test_decodeDictWithNoColonOrValue(self):
00472         input = "{{{{\"key\"}}}}"
00473         try:
00474             ujson.decode(input)
00475             assert False, "Expected exception!"
00476         except(ValueError):
00477             return
00478 
00479         assert False, "Wrong exception"
00480 
00481     def test_decodeDictWithNoValue(self):
00482         input = "{{{{\"key\":}}}}"
00483         try:
00484             ujson.decode(input)
00485             assert False, "Expected exception!"
00486         except(ValueError):
00487             return
00488 
00489         assert False, "Wrong exception"
00490 
00491     def test_decodeNumericIntPos(self):
00492         input = "31337"
00493         self.assertEquals (31337, ujson.decode(input))
00494 
00495     def test_decodeNumericIntNeg(self):
00496         input = "-31337"
00497         self.assertEquals (-31337, ujson.decode(input))
00498 
00499     #@unittest.skipIf(_python_ver(3), "No exception in Python 3")
00500     def test_encodeUnicode4BytesUTF8Fail(self):
00501         input = "\xfd\xbf\xbf\xbf\xbf\xbf"
00502         try:
00503             enc = ujson.encode(input)
00504             assert False, "Expected exception"
00505         except OverflowError:
00506             pass
00507             
00508     def test_encodeNullCharacter(self):
00509         input = "31337 \x00 1337"
00510         output = ujson.encode(input)
00511         self.assertEquals(input, json.loads(output))
00512         self.assertEquals(output, json.dumps(input))
00513         self.assertEquals(input, ujson.decode(output))
00514 
00515         input = "\x00"
00516         output = ujson.encode(input)
00517         self.assertEquals(input, json.loads(output))
00518         self.assertEquals(output, json.dumps(input))
00519         self.assertEquals(input, ujson.decode(output))
00520         
00521         self.assertEquals('"  \\u0000\\r\\n "', ujson.dumps(u"  \u0000\r\n "))
00522         pass
00523     
00524     def test_decodeNullCharacter(self):
00525         input = "\"31337 \\u0000 31337\""
00526         self.assertEquals(ujson.decode(input), json.loads(input))
00527         
00528             
00529     def test_encodeListLongConversion(self):
00530         input = [9223372036854775807, 9223372036854775807, 9223372036854775807,
00531                  9223372036854775807, 9223372036854775807, 9223372036854775807 ]
00532         output = ujson.encode(input)
00533         self.assertEquals(input, json.loads(output))
00534         self.assertEquals(input, ujson.decode(output))
00535         pass
00536 
00537     def test_encodeLongConversion(self):
00538         input = 9223372036854775807
00539         output = ujson.encode(input)
00540         self.assertEquals(input, json.loads(output))
00541         self.assertEquals(output, json.dumps(input))
00542         self.assertEquals(input, ujson.decode(output))
00543         pass
00544 
00545     def test_numericIntExp(self):
00546         input = "1337E40"
00547         output = ujson.decode(input)
00548         self.assertEquals(output, json.loads(input))
00549 
00550     def test_numericIntFrcExp(self):
00551         input = "1.337E40"
00552         output = ujson.decode(input)
00553         self.assertEquals(output, json.loads(input))
00554 
00555     def test_decodeNumericIntExpEPLUS(self):
00556         input = "1337E+40"
00557         output = ujson.decode(input)
00558         self.assertEquals(output, json.loads(input))
00559 
00560     def test_decodeNumericIntExpePLUS(self):
00561         input = "1.337e+40"
00562         output = ujson.decode(input)
00563         self.assertEquals(output, json.loads(input))
00564 
00565     def test_decodeNumericIntExpE(self):
00566         input = "1337E40"
00567         output = ujson.decode(input)
00568         self.assertEquals(output, json.loads(input))
00569 
00570     def test_decodeNumericIntExpe(self):
00571         input = "1337e40"
00572         output = ujson.decode(input)
00573         self.assertEquals(output, json.loads(input))
00574 
00575     def test_decodeNumericIntExpEMinus(self):
00576         input = "1.337E-4"
00577         output = ujson.decode(input)
00578         self.assertEquals(output, json.loads(input))
00579 
00580     def test_decodeNumericIntExpeMinus(self):
00581         input = "1.337e-4"
00582         output = ujson.decode(input)
00583         self.assertEquals(output, json.loads(input))
00584   
00585     def test_dumpToFile(self):
00586         f = StringIO.StringIO()
00587         ujson.dump([1, 2, 3], f)
00588         self.assertEquals("[1,2,3]", f.getvalue())
00589 
00590     def test_dumpToFileLikeObject(self):
00591         class filelike:
00592             def __init__(self):
00593                 self.bytes = ''
00594             def write(self, bytes):
00595                 self.bytes += bytes
00596         f = filelike()
00597         ujson.dump([1, 2, 3], f)
00598         self.assertEquals("[1,2,3]", f.bytes)
00599 
00600     def test_dumpFileArgsError(self):
00601         try:
00602             ujson.dump([], '')
00603         except TypeError:
00604             pass
00605         else:
00606             assert False, 'expected TypeError'
00607  
00608     def test_loadFile(self):
00609         f = StringIO.StringIO("[1,2,3,4]")
00610         self.assertEquals([1, 2, 3, 4], ujson.load(f))
00611 
00612     def test_loadFileLikeObject(self):
00613         class filelike:
00614             def read(self):
00615                 try:
00616                     self.end
00617                 except AttributeError:
00618                     self.end = True
00619                     return "[1,2,3,4]"
00620         f = filelike()
00621         self.assertEquals([1, 2, 3, 4], ujson.load(f))
00622 
00623     def test_loadFileArgsError(self):
00624         try:
00625             ujson.load("[]")
00626         except TypeError:
00627             pass
00628         else:
00629             assert False, "expected TypeError"
00630 
00631     def test_version(self):
00632         assert re.match(r'^\d+\.\d+(\.\d+)?$', ujson.__version__), \
00633                "ujson.__version__ must be a string like '1.4.0'"
00634 
00635     def test_encodeNumericOverflow(self):
00636         try:
00637             ujson.encode(12839128391289382193812939)
00638         except OverflowError:
00639             pass
00640         else:
00641             assert False, "expected OverflowError"
00642 
00643     def test_encodeNumericOverflowNested(self):
00644         for n in xrange(0, 100):
00645             class Nested:
00646                 x = 12839128391289382193812939
00647         
00648             nested = Nested()
00649         
00650             try:
00651                 ujson.encode(nested)
00652             except OverflowError:
00653                 pass
00654             else:
00655                 assert False, "expected OverflowError"
00656 
00657     def test_decodeNumberWith32bitSignBit(self):
00658         #Test that numbers that fit within 32 bits but would have the
00659         # sign bit set (2**31 <= x < 2**32) are decoded properly.
00660         boundary1 = 2**31
00661         boundary2 = 2**32
00662         docs = (
00663             '{"id": 3590016419}',
00664             '{"id": %s}' % 2**31,
00665             '{"id": %s}' % 2**32,
00666             '{"id": %s}' % ((2**32)-1),
00667         )
00668         results = (3590016419, 2**31, 2**32, 2**32-1)
00669         for doc,result in zip(docs, results):
00670             self.assertEqual(ujson.decode(doc)['id'], result)
00671 
00672     def test_encodeBigEscape(self):
00673         for x in xrange(10):
00674             if PY3:
00675                 base = '\u00e5'.encode('utf-8')
00676             else:
00677                 base = "\xc3\xa5"
00678             input = base * 1024 * 1024 * 2
00679             output = ujson.encode(input)
00680 
00681     def test_decodeBigEscape(self):
00682         for x in xrange(10):
00683             if PY3:
00684                 base = '\u00e5'.encode('utf-8')
00685                 quote = "\"".encode()
00686             else:
00687                 base = "\xc3\xa5"
00688                 quote = "\""
00689             input = quote + (base * 1024 * 1024 * 2) + quote
00690             output = ujson.decode(input)
00691 
00692     def test_toDict(self):
00693         d = {u"key": 31337}
00694     
00695         class DictTest:
00696             def toDict(self):
00697                 return d
00698 
00699         o = DictTest()
00700         output = ujson.encode(o)
00701         dec = ujson.decode(output)
00702         self.assertEquals(dec, d)
00703 
00704     def test_decodeArrayTrailingCommaFail(self):
00705         input = "[31337,]"
00706         try:
00707             ujson.decode(input)
00708         except ValueError:
00709             pass
00710         else:
00711             assert False, "expected ValueError"
00712 
00713     def test_decodeArrayLeadingCommaFail(self):
00714         input = "[,31337]"
00715         try:
00716             ujson.decode(input)
00717         except ValueError:
00718             pass
00719         else:
00720             assert False, "expected ValueError"
00721 
00722     def test_decodeArrayOnlyCommaFail(self):
00723         input = "[,]"
00724         try:
00725             ujson.decode(input)
00726         except ValueError:
00727             pass
00728         else:
00729             assert False, "expected ValueError"
00730             
00731     def test_decodeArrayUnmatchedBracketFail(self):
00732         input = "[]]"
00733         try:
00734             ujson.decode(input)
00735         except ValueError:
00736             pass
00737         else:
00738             assert False, "expected ValueError"
00739 
00740     def test_decodeArrayEmpty(self):
00741         input = "[]"
00742         ujson.decode(input)
00743 
00744     def test_decodeArrayOneItem(self):
00745         input = "[31337]"
00746         ujson.decode(input)
00747 
00748         
00749 """
00750 def test_decodeNumericIntFrcOverflow(self):
00751 input = "X.Y"
00752 raise NotImplementedError("Implement this test!")
00753 
00754 
00755 def test_decodeStringUnicodeEscape(self):
00756 input = "\u3131"
00757 raise NotImplementedError("Implement this test!")
00758 
00759 def test_decodeStringUnicodeBrokenEscape(self):
00760 input = "\u3131"
00761 raise NotImplementedError("Implement this test!")
00762 
00763 def test_decodeStringUnicodeInvalidEscape(self):
00764 input = "\u3131"
00765 raise NotImplementedError("Implement this test!")
00766 
00767 def test_decodeStringUTF8(self):
00768 input = "someutfcharacters"
00769 raise NotImplementedError("Implement this test!")
00770 
00771 """
00772 if __name__ == "__main__":
00773     unittest.main()
00774 
00775 """
00776 # Use this to look for memory leaks
00777 if __name__ == '__main__':
00778     from guppy import hpy
00779     hp = hpy()
00780     hp.setrelheap()
00781     while True:
00782         try:
00783             unittest.main()
00784         except SystemExit:
00785             pass
00786         heap = hp.heapu()
00787         print heap
00788 """        


rosbridge_library
Author(s): Jonathan Mace
autogenerated on Thu Jan 2 2014 11:53:35