@@ -160,28 +160,33 @@ def testBugDecodeFailure1():
160
160
161
161
def testReportErrorOnIncompleteArray1 ():
162
162
s = "test = [1, 2, "
163
- with pytest .raises (Exception ):
163
+ with pytest .raises (sjson . ParseException ):
164
164
sjson .loads (s )
165
165
166
166
167
167
def testReportErrorOnIncompleteArray2 ():
168
168
s = "test = ["
169
- with pytest .raises (Exception ):
169
+ with pytest .raises (sjson . ParseException ):
170
170
sjson .loads (s )
171
171
172
172
173
173
def testReportOnIncompleteMap1 ():
174
174
s = "test = "
175
- with pytest .raises (Exception ):
175
+ with pytest .raises (sjson . ParseException ):
176
176
sjson .loads (s )
177
177
178
178
179
179
def testReportOnIncompleteMap2 ():
180
180
s = "test "
181
- with pytest .raises (Exception ):
181
+ with pytest .raises (sjson . ParseException ):
182
182
sjson .loads (s )
183
183
184
184
185
+ def testReportOnKeyOnly ():
186
+ with pytest .raises (sjson .ParseException ):
187
+ sjson .loads ('foo' )
188
+
189
+
185
190
def testBugDecodeFailsForFloats ():
186
191
s = "test = 1.0"
187
192
r = sjson .loads (s )
@@ -209,12 +214,12 @@ def testBugDecodeFailsOnStringWithDot():
209
214
210
215
211
216
def testStringWithoutQuotesAsValueThrows ():
212
- with pytest .raises (Exception ):
217
+ with pytest .raises (sjson . ParseException ):
213
218
sjson .loads ("key = baz\n " )
214
219
215
220
216
221
def testStringWithoutClosingQuotesThrows ():
217
- with pytest .raises (Exception ):
222
+ with pytest .raises (sjson . ParseException ):
218
223
sjson .loads ('key = "baz\n ' )
219
224
220
225
@@ -249,23 +254,23 @@ def testStringWithEmptyRawLiteral():
249
254
250
255
251
256
def testStringWithIncorrectlyTerminatedRawLiteral ():
252
- with pytest .raises (Exception ):
257
+ with pytest .raises (sjson . ParseException ):
253
258
sjson .loads ("""foo = [=[=]""" )
254
- with pytest .raises (Exception ):
259
+ with pytest .raises (sjson . ParseException ):
255
260
sjson .loads ("""foo = [=[]]""" )
256
- with pytest .raises (Exception ):
261
+ with pytest .raises (sjson . ParseException ):
257
262
sjson .loads ("""foo = [=[]=""" )
258
263
259
264
260
265
def testUndelimitedMapThrows ():
261
- with pytest .raises (Exception ):
266
+ with pytest .raises (sjson . ParseException ):
262
267
sjson .loads ('foo = { bar = "value", baz = { ui = "foo",' )
263
268
264
269
265
270
def testInvalidRawQuotedStringStart ():
266
- with pytest .raises (Exception ):
271
+ with pytest .raises (sjson . ParseException ):
267
272
sjson .loads ("foo = [=? wrong ?=]" )
268
- with pytest .raises (Exception ):
273
+ with pytest .raises (sjson . ParseException ):
269
274
sjson .loads ("foo = [=] wrong [=]" )
270
275
271
276
@@ -307,7 +312,7 @@ def testCStyleCommentIsIgnored():
307
312
308
313
309
314
def testNotClosedCStyleCommentThrows ():
310
- with pytest .raises (Exception ):
315
+ with pytest .raises (sjson . ParseException ):
311
316
sjson .loads ("""foo = /* bar * 23""" )
312
317
313
318
@@ -319,7 +324,8 @@ def testCppStyleCommentIsIgnored():
319
324
320
325
321
326
def testParseStringraySJSONExample ():
322
- r = sjson .loads ("""// The script that should be started when the application runs.
327
+ r = sjson .loads (
328
+ """// The script that should be started when the application runs.
323
329
boot_script = "boot"
324
330
325
331
// The port on which the console server runs.
@@ -407,32 +413,33 @@ def testIndentWithNegativeNumberDoesNotIndent():
407
413
408
414
409
415
def testDoubleColonSeparator ():
410
- assert sjson .loads ("""{"smells-like" : "json"}""" ) == {'smells-like' : 'json' }
416
+ assert sjson .loads ("""{"smells-like" : "json"}""" ) == {
417
+ 'smells-like' : 'json' }
411
418
412
419
413
420
def testUnknownEscapeGetsIgnored ():
414
- l = sjson .loads (r'foo = "Bar\lbaz"' )
415
- assert l ['foo' ] == r'Bar\lbaz'
421
+ r = sjson .loads (r'foo = "Bar\lbaz"' )
422
+ assert r ['foo' ] == r'Bar\lbaz'
416
423
417
424
418
425
def testPythonStyleString ():
419
- l = sjson .loads ('''foo = """This is
426
+ r = sjson .loads ('''foo = """This is
420
427
multiline!"""''' )
421
428
assert (
422
- l ['foo' ]
429
+ r ['foo' ]
423
430
== """This is
424
431
multiline!"""
425
432
)
426
433
427
434
428
435
def testQuadrupleQuotedString ():
429
- l = sjson .loads ('''Foo = """"Why oh why""""''' )
430
- assert l ['Foo' ] == '"Why oh why"'
436
+ r = sjson .loads ('''Foo = """"Why oh why""""''' )
437
+ assert r ['Foo' ] == '"Why oh why"'
431
438
432
439
433
440
def testQuintupleQuotedString ():
434
- l = sjson .loads ('''Foo = """""Why oh why"""""''' )
435
- assert l ['Foo' ] == '""Why oh why""'
441
+ r = sjson .loads ('''Foo = """""Why oh why"""""''' )
442
+ assert r ['Foo' ] == '""Why oh why""'
436
443
437
444
438
445
def testSixtupleQuotedStringIsInvalid ():
@@ -441,13 +448,13 @@ def testSixtupleQuotedStringIsInvalid():
441
448
442
449
443
450
def testPythonRawQuotedStringInsideLuaRawString ():
444
- l = sjson .loads ('''foo = [=[ String """ string ]=]''' )
445
- assert l ['foo' ] == ''' String """ string '''
451
+ r = sjson .loads ('''foo = [=[ String """ string ]=]''' )
452
+ assert r ['foo' ] == ''' String """ string '''
446
453
447
454
448
455
def testLuaRawQuotedStringInsidePythonRawString ():
449
- l = sjson .loads ('''foo = """ String [=[ baz ]=] string """''' )
450
- assert l ['foo' ] == ''' String [=[ baz ]=] string '''
456
+ r = sjson .loads ('''foo = """ String [=[ baz ]=] string """''' )
457
+ assert r ['foo' ] == ''' String [=[ baz ]=] string '''
451
458
452
459
453
460
def testEncodeUnknownTypeRaisesException ():
@@ -459,5 +466,5 @@ class X:
459
466
460
467
461
468
def testDecodeEscapedCharacters ():
462
- l = sjson .loads ('''a = "\\ b\\ n\\ t"''' )
463
- assert l ['a' ] == """\b \n \t """
469
+ r = sjson .loads ('''a = "\\ b\\ n\\ t"''' )
470
+ assert r ['a' ] == """\b \n \t """
0 commit comments