@@ -67,11 +67,11 @@ def test_stdin_stdout(self):
6767 self .assertEqual (out .splitlines (), self .expect .encode ().splitlines ())
6868 self .assertEqual (err , b'' )
6969
70- def _create_infile (self ):
70+ def _create_infile (self , data = None ):
7171 infile = support .TESTFN
72- with open (infile , "w" ) as fp :
72+ with open (infile , "w" , encoding = "utf-8" ) as fp :
7373 self .addCleanup (os .remove , infile )
74- fp .write (self .data )
74+ fp .write (data or self .data )
7575 return infile
7676
7777 def test_infile_stdout (self ):
@@ -81,6 +81,21 @@ def test_infile_stdout(self):
8181 self .assertEqual (out .splitlines (), self .expect .encode ().splitlines ())
8282 self .assertEqual (err , b'' )
8383
84+ def test_non_ascii_infile (self ):
85+ data = '{"msg": "\u3053 \u3093 \u306b \u3061 \u306f "}'
86+ expect = textwrap .dedent ('''\
87+ {
88+ "msg": "\\ u3053\\ u3093\\ u306b\\ u3061\\ u306f"
89+ }
90+ ''' ).encode ()
91+
92+ infile = self ._create_infile (data )
93+ rc , out , err = assert_python_ok ('-m' , 'json.tool' , infile )
94+
95+ self .assertEqual (rc , 0 )
96+ self .assertEqual (out .splitlines (), expect .splitlines ())
97+ self .assertEqual (err , b'' )
98+
8499 def test_infile_outfile (self ):
85100 infile = self ._create_infile ()
86101 outfile = support .TESTFN + '.out'
0 commit comments