@@ -89,11 +89,11 @@ def test_stdin_stdout(self):
8989 self .assertEqual (out .splitlines (), self .expect .encode ().splitlines ())
9090 self .assertEqual (err , b'' )
9191
92- def _create_infile (self ):
92+ def _create_infile (self , data = None ):
9393 infile = support .TESTFN
94- with open (infile , "w" ) as fp :
94+ with open (infile , "w" , encoding = "utf-8" ) as fp :
9595 self .addCleanup (os .remove , infile )
96- fp .write (self .data )
96+ fp .write (data or self .data )
9797 return infile
9898
9999 def test_infile_stdout (self ):
@@ -103,6 +103,21 @@ def test_infile_stdout(self):
103103 self .assertEqual (out .splitlines (), self .expect .encode ().splitlines ())
104104 self .assertEqual (err , b'' )
105105
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 .splitlines ())
119+ self .assertEqual (err , b'' )
120+
106121 def test_infile_outfile (self ):
107122 infile = self ._create_infile ()
108123 outfile = support .TESTFN + '.out'
0 commit comments