diff options
author | wim glenn <hey@wimglenn.com> | 2019-12-06 06:44:01 (GMT) |
---|---|---|
committer | Inada Naoki <songofacandy@gmail.com> | 2019-12-06 06:44:01 (GMT) |
commit | efefe25443c56988841ab96cdac01352123ba268 (patch) | |
tree | 7154408936969702c8e86a8e8fd9dbf2985fa9fe /Lib/test | |
parent | d863ade0c7fa4826e8b71aa467809c83a711f019 (diff) | |
download | cpython-efefe25443c56988841ab96cdac01352123ba268.zip cpython-efefe25443c56988841ab96cdac01352123ba268.tar.gz cpython-efefe25443c56988841ab96cdac01352123ba268.tar.bz2 |
bpo-27413: json.tool: Add --no-ensure-ascii option. (GH-17472)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_json/test_tool.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_json/test_tool.py b/Lib/test/test_json/test_tool.py index 953a569..54800ae 100644 --- a/Lib/test/test_json/test_tool.py +++ b/Lib/test/test_json/test_tool.py @@ -190,3 +190,25 @@ class TestTool(unittest.TestCase): json_stdout, err = proc.communicate(json_stdin) self.assertEqual(expect.splitlines(), json_stdout.splitlines()) self.assertEqual(err, b'') + + def test_no_ensure_ascii_flag(self): + infile = self._create_infile('{"key":"💩"}') + outfile = support.TESTFN + '.out' + self.addCleanup(os.remove, outfile) + assert_python_ok('-m', 'json.tool', '--no-ensure-ascii', infile, outfile) + with open(outfile, "rb") as f: + lines = f.read().splitlines() + # asserting utf-8 encoded output file + expected = [b'{', b' "key": "\xf0\x9f\x92\xa9"', b"}"] + self.assertEqual(lines, expected) + + def test_ensure_ascii_default(self): + infile = self._create_infile('{"key":"💩"}') + outfile = support.TESTFN + '.out' + self.addCleanup(os.remove, outfile) + assert_python_ok('-m', 'json.tool', infile, outfile) + with open(outfile, "rb") as f: + lines = f.read().splitlines() + # asserting an ascii encoded output file + expected = [b'{', rb' "key": "\ud83d\udca9"', b"}"] + self.assertEqual(lines, expected) |