summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_json
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2019-12-04 09:39:31 (GMT)
committerGitHub <noreply@github.com>2019-12-04 09:39:31 (GMT)
commit808769f3a4cbdc47cf1a5708dd61b1787bb192d4 (patch)
tree5d0cb5aa5751e296bc2124c6ca26c1b1f13be2f2 /Lib/test/test_json
parent24f5cac7254177a4c9956d680c0a9b6dadd85c6f (diff)
downloadcpython-808769f3a4cbdc47cf1a5708dd61b1787bb192d4.zip
cpython-808769f3a4cbdc47cf1a5708dd61b1787bb192d4.tar.gz
cpython-808769f3a4cbdc47cf1a5708dd61b1787bb192d4.tar.bz2
bpo-33684: json.tool: Use utf-8 for infile and outfile. (GH-17460)
Diffstat (limited to 'Lib/test/test_json')
-rw-r--r--Lib/test/test_json/test_tool.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/Lib/test/test_json/test_tool.py b/Lib/test/test_json/test_tool.py
index 81d179c..953a569 100644
--- a/Lib/test/test_json/test_tool.py
+++ b/Lib/test/test_json/test_tool.py
@@ -89,11 +89,11 @@ class TestTool(unittest.TestCase):
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):
@@ -103,6 +103,21 @@ class TestTool(unittest.TestCase):
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.splitlines())
+ self.assertEqual(err, b'')
+
def test_infile_outfile(self):
infile = self._create_infile()
outfile = support.TESTFN + '.out'