@@ -11,12 +11,12 @@ class TestTool(unittest.TestCase):
11
11
data = """
12
12
13
13
[["blorpie"],[ "whoops" ] , [
14
- ],\t "d-shtaeou",\r "\xA7 \N{snake} \u03B4 and \U0001D037 ",
14
+ ],\t "d-shtaeou",\r "d-nthiouh ",
15
15
"i-vhbjkhnth", {"nifty":87}, {"morefield" :\t false,"field"
16
16
:"yes"} ]
17
17
"""
18
18
19
- expect_without_sort_keys = textwrap .dedent (r """\
19
+ expect_without_sort_keys = textwrap .dedent ("""\
20
20
[
21
21
[
22
22
"blorpie"
@@ -26,7 +26,7 @@ class TestTool(unittest.TestCase):
26
26
],
27
27
[],
28
28
"d-shtaeou",
29
- "\u00a7 \ud83d\udc0d \u03b4 and \ud834\udc3 ",
29
+ "d-nthiouh ",
30
30
"i-vhbjkhnth",
31
31
{
32
32
"nifty": 87
@@ -38,7 +38,7 @@ class TestTool(unittest.TestCase):
38
38
]
39
39
""" )
40
40
41
- expect = textwrap .dedent (r """\
41
+ expect = textwrap .dedent ("""\
42
42
[
43
43
[
44
44
"blorpie"
@@ -48,7 +48,7 @@ class TestTool(unittest.TestCase):
48
48
],
49
49
[],
50
50
"d-shtaeou",
51
- "\u00a7 \ud83d\udc0d \u03b4 and \ud834\udc37 ",
51
+ "d-nthiouh ",
52
52
"i-vhbjkhnth",
53
53
{
54
54
"nifty": 87
@@ -106,22 +106,14 @@ def test_sort_keys_flag(self):
106
106
self .expect_without_sort_keys .encode ().splitlines ())
107
107
self .assertEqual (err , b'' )
108
108
109
- def test_no_ensure_ascii_flag (self ):
110
- infile = self ._create_infile ()
111
- rc , out , err = assert_python_ok ('-m' , 'json.tool' , '--no-ensure-ascii' , infile )
112
- self .assertEqual (rc , 0 )
113
- self .assertEqual (out .splitlines (),
114
- self .expect_without_sort_keys .encode ().splitlines ())
115
- self .assertEqual (err , b'' )
116
-
117
109
def test_indent (self ):
118
110
json_stdin = b'[1, 2]'
119
- expect = textwrap .dedent (b '''\
111
+ expect = textwrap .dedent ('''\
120
112
[
121
113
1,
122
114
2
123
115
]
124
- ''' )
116
+ ''' ). encode ()
125
117
args = sys .executable , '-m' , 'json.tool' , '--indent' , '2'
126
118
with Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) as proc :
127
119
json_stdout , err = proc .communicate (json_stdin )
@@ -133,5 +125,22 @@ def test_no_indent(self):
133
125
args = sys .executable , '-m' , 'json.tool' , '--no-indent'
134
126
with Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) as proc :
135
127
json_stdout , err = proc .communicate (json_stdin )
136
- self .assertEqual (json_stdin , json_stdout )
128
+ self .assertEqual (json_stdin .splitlines (), json_stdout .splitlines ())
129
+ self .assertEqual (err , b'' )
130
+
131
+ def test_ensure_ascii (self ):
132
+ json_stdin = '"\xA7 \N{snake} \u03B4 \U0001D037 "' .encode ()
133
+ expect = b'"\\ u00a7 \\ ud83d\\ udc0d \\ u03b4 \\ ud834\\ udc37"\n '
134
+ args = sys .executable , '-m' , 'json.tool'
135
+ with Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) as proc :
136
+ json_stdout , err = proc .communicate (json_stdin )
137
+ self .assertEqual (expect .splitlines (), json_stdout .splitlines ())
138
+ self .assertEqual (err , b'' )
139
+
140
+ def test_no_ensure_ascii (self ):
141
+ json_stdin = '"\xA7 \N{snake} \u03B4 \U0001D037 "' .encode ()
142
+ args = sys .executable , '-m' , 'json.tool' , '--no-ensure-ascii'
143
+ with Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) as proc :
144
+ json_stdout , err = proc .communicate (json_stdin )
145
+ self .assertEqual (json_stdin .splitlines (), json_stdout .splitlines ())
137
146
self .assertEqual (err , b'' )
0 commit comments