-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-27413: add --no-ensure-ascii argument to json.tool #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a47f396
fb5d984
4fb3bb3
29d01fe
a3e2b23
97152e9
d699070
0f38c18
66a173a
dd25cf3
3413f4f
52bafb0
1306518
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import sys | ||
import textwrap | ||
import unittest | ||
import subprocess | ||
from subprocess import Popen, PIPE | ||
from test import support | ||
from test.support.script_helper import assert_python_ok | ||
|
||
|
@@ -61,12 +61,11 @@ class TestTool(unittest.TestCase): | |
""") | ||
|
||
def test_stdin_stdout(self): | ||
with subprocess.Popen( | ||
(sys.executable, '-m', 'json.tool'), | ||
stdin=subprocess.PIPE, stdout=subprocess.PIPE) as proc: | ||
args = sys.executable, '-m', 'json.tool' | ||
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc: | ||
out, err = proc.communicate(self.data.encode()) | ||
self.assertEqual(out.splitlines(), self.expect.encode().splitlines()) | ||
self.assertEqual(err, None) | ||
self.assertEqual(err, b'') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @berkerpeksag is it okay to bundle a change to an unrelated test within these PRs? Previously stderr wasn't being piped, and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@berkerpeksag will keep this PR for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say open a third pull request for this one (this way we can quickly merge the pipe change) No need to create a new issue on bugs.python.org. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @berkerpeksag opened at #346 |
||
|
||
def _create_infile(self): | ||
infile = support.TESTFN | ||
|
@@ -106,3 +105,42 @@ def test_sort_keys_flag(self): | |
self.assertEqual(out.splitlines(), | ||
self.expect_without_sort_keys.encode().splitlines()) | ||
self.assertEqual(err, b'') | ||
|
||
def test_indent(self): | ||
json_stdin = b'[1, 2]' | ||
expect = textwrap.dedent('''\ | ||
[ | ||
1, | ||
2 | ||
] | ||
''').encode() | ||
args = sys.executable, '-m', 'json.tool', '--indent', '2' | ||
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc: | ||
json_stdout, err = proc.communicate(json_stdin) | ||
self.assertEqual(expect.splitlines(), json_stdout.splitlines()) | ||
self.assertEqual(err, b'') | ||
|
||
def test_no_indent(self): | ||
json_stdin = b'[1, 2]' | ||
args = sys.executable, '-m', 'json.tool', '--no-indent' | ||
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc: | ||
json_stdout, err = proc.communicate(json_stdin) | ||
self.assertEqual(json_stdin.splitlines(), json_stdout.splitlines()) | ||
self.assertEqual(err, b'') | ||
|
||
def test_ensure_ascii(self): | ||
json_stdin = '"\xA7 \N{snake} \u03B4 \U0001D037"'.encode() | ||
expect = b'"\\u00a7 \\ud83d\\udc0d \\u03b4 \\ud834\\udc37"\n' | ||
args = sys.executable, '-m', 'json.tool' | ||
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc: | ||
json_stdout, err = proc.communicate(json_stdin) | ||
self.assertEqual(expect.splitlines(), json_stdout.splitlines()) | ||
self.assertEqual(err, b'') | ||
|
||
def test_no_ensure_ascii(self): | ||
json_stdin = '"\xA7 \N{snake} \u03B4 \U0001D037"'.encode() | ||
args = sys.executable, '-m', 'json.tool', '--no-ensure-ascii' | ||
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc: | ||
json_stdout, err = proc.communicate(json_stdin) | ||
self.assertEqual(json_stdin.splitlines(), json_stdout.splitlines()) | ||
self.assertEqual(err, b'') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed tests for
--indent
and--no-indent
.