1
1
from test .test_json import CTest
2
2
3
3
4
+ class BadBool :
5
+ def __bool__ (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" )
@@ -17,8 +22,25 @@ class TestDecode(CTest):
17
22
def test_make_scanner (self ):
18
23
self .assertRaises (AttributeError , self .json .scanner .c_make_scanner , 1 )
19
24
25
+ def test_bad_bool_args (self ):
26
+ def test (value ):
27
+ self .json .decoder .JSONDecoder (strict = BadBool ()).decode (value )
28
+ self .assertRaises (ZeroDivisionError , test , '""' )
29
+ self .assertRaises (ZeroDivisionError , test , '{}' )
30
+
31
+
32
+ class TestEncode (CTest ):
20
33
def test_make_encoder (self ):
21
34
self .assertRaises (TypeError , self .json .encoder .c_make_encoder ,
22
35
(True , False ),
23
36
b"\xCD \x7D \x3D \x4E \x12 \x4C \xF9 \x79 \xD7 \x52 \xBA \x82 \xF2 \x27 \x4A \x7D \xA0 \xCA \x75 " ,
24
37
None )
38
+
39
+ def test_bad_bool_args (self ):
40
+ def test (name ):
41
+ self .json .encoder .JSONEncoder (** {name : BadBool ()}).encode ({'a' : 1 })
42
+ self .assertRaises (ZeroDivisionError , test , 'skipkeys' )
43
+ self .assertRaises (ZeroDivisionError , test , 'ensure_ascii' )
44
+ self .assertRaises (ZeroDivisionError , test , 'check_circular' )
45
+ self .assertRaises (ZeroDivisionError , test , 'allow_nan' )
46
+ self .assertRaises (ZeroDivisionError , test , 'sort_keys' )
0 commit comments