mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #21650: Add an --sort-keys
option to json.tool CLI.
This commit is contained in:
parent
ffd842e1d6
commit
39e4c4d873
5 changed files with 63 additions and 3 deletions
|
@ -6,6 +6,7 @@ import subprocess
|
|||
from test import support
|
||||
from test.script_helper import assert_python_ok
|
||||
|
||||
|
||||
class TestTool(unittest.TestCase):
|
||||
data = """
|
||||
|
||||
|
@ -15,7 +16,7 @@ class TestTool(unittest.TestCase):
|
|||
:"yes"} ]
|
||||
"""
|
||||
|
||||
expect = textwrap.dedent("""\
|
||||
expect_without_sort_keys = textwrap.dedent("""\
|
||||
[
|
||||
[
|
||||
"blorpie"
|
||||
|
@ -37,6 +38,28 @@ class TestTool(unittest.TestCase):
|
|||
]
|
||||
""")
|
||||
|
||||
expect = textwrap.dedent("""\
|
||||
[
|
||||
[
|
||||
"blorpie"
|
||||
],
|
||||
[
|
||||
"whoops"
|
||||
],
|
||||
[],
|
||||
"d-shtaeou",
|
||||
"d-nthiouh",
|
||||
"i-vhbjkhnth",
|
||||
{
|
||||
"nifty": 87
|
||||
},
|
||||
{
|
||||
"morefield": false,
|
||||
"field": "yes"
|
||||
}
|
||||
]
|
||||
""")
|
||||
|
||||
def test_stdin_stdout(self):
|
||||
with subprocess.Popen(
|
||||
(sys.executable, '-m', 'json.tool'),
|
||||
|
@ -75,3 +98,11 @@ class TestTool(unittest.TestCase):
|
|||
self.assertEqual(rc, 0)
|
||||
self.assertTrue(out.startswith(b'usage: '))
|
||||
self.assertEqual(err, b'')
|
||||
|
||||
def test_sort_keys_flag(self):
|
||||
infile = self._create_infile()
|
||||
rc, out, err = assert_python_ok('-m', 'json.tool', '--sort-keys', infile)
|
||||
self.assertEqual(rc, 0)
|
||||
self.assertEqual(out.splitlines(),
|
||||
self.expect_without_sort_keys.encode().splitlines())
|
||||
self.assertEqual(err, b'')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue