bpo-27413: add --no-ensure-ascii argument to json.tool by dhimmel · Pull Request #201 · python/cpython
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'')
def _create_infile(self): infile = support.TESTFN
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'')