1
1
from json .tests import CTest
2
2
3
3
4
+ class BadBool :
5
+ def __nonzero__ (self ):
6
+ 1 / 0
7
+
8
+
4
9
class TestSpeedups (CTest ):
5
10
def test_scanstring (self ):
6
11
self .assertEqual (self .json .decoder .scanstring .__module__ , "_json" )
@@ -16,8 +21,31 @@ class TestDecode(CTest):
16
21
def test_make_scanner (self ):
17
22
self .assertRaises (AttributeError , self .json .scanner .c_make_scanner , 1 )
18
23
24
+ def test_bad_bool_args (self ):
25
+ def test (value ):
26
+ self .json .decoder .JSONDecoder (strict = BadBool ()).decode (value )
27
+ self .assertRaises (ZeroDivisionError , test , '""' )
28
+ self .assertRaises (ZeroDivisionError , test , '{}' )
29
+ self .assertRaises (ZeroDivisionError , test , u'""' )
30
+ self .assertRaises (ZeroDivisionError , test , u'{}' )
31
+
32
+
33
+ class TestEncode (CTest ):
19
34
def test_make_encoder (self ):
20
35
self .assertRaises (TypeError , self .json .encoder .c_make_encoder ,
21
36
None ,
22
37
"\xCD \x7D \x3D \x4E \x12 \x4C \xF9 \x79 \xD7 \x52 \xBA \x82 \xF2 \x27 \x4A \x7D \xA0 \xCA \x75 " ,
23
38
None )
39
+
40
+ def test_bad_bool_args (self ):
41
+ def test (name ):
42
+ self .json .encoder .JSONEncoder (** {name : BadBool ()}).encode ({'a' : 1 })
43
+ self .assertRaises (ZeroDivisionError , test , 'skipkeys' )
44
+ self .assertRaises (ZeroDivisionError , test , 'ensure_ascii' )
45
+ self .assertRaises (ZeroDivisionError , test , 'check_circular' )
46
+ self .assertRaises (ZeroDivisionError , test , 'allow_nan' )
47
+ self .assertRaises (ZeroDivisionError , test , 'sort_keys' )
48
+
49
+ def test_bad_encoding (self ):
50
+ with self .assertRaises (UnicodeEncodeError ):
51
+ self .json .encoder .JSONEncoder (encoding = u'\udcff ' ).encode ({'key' : 123 })
0 commit comments