Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test
  • Loading branch information
methane committed Dec 4, 2019
commit 6f52d15420b9e5ca27c9080385297a4edae105a4
21 changes: 18 additions & 3 deletions Lib/test/test_json/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def test_stdin_stdout(self):
self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
self.assertEqual(err, b'')

def _create_infile(self):
def _create_infile(self, data=None):
infile = support.TESTFN
with open(infile, "w") as fp:
with open(infile, "w", encoding="utf-8") as fp:
self.addCleanup(os.remove, infile)
fp.write(self.data)
fp.write(data or self.data)
return infile

def test_infile_stdout(self):
Expand All @@ -103,6 +103,21 @@ def test_infile_stdout(self):
self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
self.assertEqual(err, b'')

def test_non_ascii_infile(self):
data = '{"msg": "\u3053\u3093\u306b\u3061\u306f"}'
expect = textwrap.dedent('''\
{
"msg": "\u3053\u3093\u306b\u3061\u306f"
}
''').encode()

infile = self._create_infile(data)
rc, out, err = assert_python_ok('-m', 'json.tool', infile)

self.assertEqual(rc, 0)
self.assertEqual(out.splitlines(), expect.encode().splitlines())
self.assertEqual(err, b'')

def test_infile_outfile(self):
infile = self._create_infile()
outfile = support.TESTFN + '.out'
Expand Down