Skip to content

Commit 4fb3bb3

Browse files
committed
Add test for no_escape arg of json.tool
1 parent fb5d984 commit 4fb3bb3

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Lib/test/test_json/test_tool.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ def test_stdin_stdout(self):
6868
self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
6969
self.assertEqual(err, None)
7070

71-
def _create_infile(self):
71+
def _create_infile(self, text):
7272
infile = support.TESTFN
7373
with open(infile, "w") as fp:
7474
self.addCleanup(os.remove, infile)
75-
fp.write(self.data)
75+
fp.write(text)
7676
return infile
7777

7878
def test_infile_stdout(self):
79-
infile = self._create_infile()
79+
infile = self._create_infile(self.data)
8080
rc, out, err = assert_python_ok('-m', 'json.tool', infile)
8181
self.assertEqual(rc, 0)
8282
self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
8383
self.assertEqual(err, b'')
8484

8585
def test_infile_outfile(self):
86-
infile = self._create_infile()
86+
infile = self._create_infile(self.data)
8787
outfile = support.TESTFN + '.out'
8888
rc, out, err = assert_python_ok('-m', 'json.tool', infile, outfile)
8989
self.addCleanup(os.remove, outfile)
@@ -100,9 +100,22 @@ def test_help_flag(self):
100100
self.assertEqual(err, b'')
101101

102102
def test_sort_keys_flag(self):
103-
infile = self._create_infile()
103+
infile = self._create_infile(self.data)
104104
rc, out, err = assert_python_ok('-m', 'json.tool', '--sort-keys', infile)
105105
self.assertEqual(rc, 0)
106106
self.assertEqual(out.splitlines(),
107107
self.expect_without_sort_keys.encode().splitlines())
108108
self.assertEqual(err, b'')
109+
110+
def test_no_ascii_flag(self):
111+
data = '{"json": "🐍 and δ"}'
112+
expect = textwrap.dedent('''\
113+
{
114+
"json": "🐍 and δ"
115+
}
116+
''')
117+
infile = self._create_infile(data)
118+
rc, out, err = assert_python_ok('-m', 'json.tool', '--no_ascii', infile)
119+
self.assertEqual(rc, 0)
120+
self.assertEqual(out.splitlines(), expect.splitlines())
121+
self.assertEqual(err, b'')

0 commit comments

Comments
 (0)