@@ -89,11 +89,11 @@ def test_stdin_stdout(self):
89
89
self .assertEqual (out .splitlines (), self .expect .encode ().splitlines ())
90
90
self .assertEqual (err , b'' )
91
91
92
- def _create_infile (self ):
92
+ def _create_infile (self , data = None ):
93
93
infile = support .TESTFN
94
- with open (infile , "w" ) as fp :
94
+ with open (infile , "w" , encoding = "utf-8" ) as fp :
95
95
self .addCleanup (os .remove , infile )
96
- fp .write (self .data )
96
+ fp .write (data or self .data )
97
97
return infile
98
98
99
99
def test_infile_stdout (self ):
@@ -103,6 +103,21 @@ def test_infile_stdout(self):
103
103
self .assertEqual (out .splitlines (), self .expect .encode ().splitlines ())
104
104
self .assertEqual (err , b'' )
105
105
106
+ def test_non_ascii_infile (self ):
107
+ data = '{"msg": "\u3053 \u3093 \u306b \u3061 \u306f "}'
108
+ expect = textwrap .dedent ('''\
109
+ {
110
+ "msg": "\u3053 \u3093 \u306b \u3061 \u306f "
111
+ }
112
+ ''' ).encode ()
113
+
114
+ infile = self ._create_infile (data )
115
+ rc , out , err = assert_python_ok ('-m' , 'json.tool' , infile )
116
+
117
+ self .assertEqual (rc , 0 )
118
+ self .assertEqual (out .splitlines (), expect .encode ().splitlines ())
119
+ self .assertEqual (err , b'' )
120
+
106
121
def test_infile_outfile (self ):
107
122
infile = self ._create_infile ()
108
123
outfile = support .TESTFN + '.out'
0 commit comments