mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-27413: json.tool: Add --no-ensure-ascii option. (GH-17472)
This commit is contained in:
parent
d863ade0c7
commit
efefe25443
4 changed files with 33 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue