Skip to content

Commit 1306518

Browse files
committed
Move unicode tests outside of self.data
1 parent 52bafb0 commit 1306518

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

Lib/test/test_json/test_tool.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class TestTool(unittest.TestCase):
1111
data = """
1212
1313
[["blorpie"],[ "whoops" ] , [
14-
],\t"d-shtaeou",\r"\xA7 \N{snake} \u03B4 and \U0001D037",
14+
],\t"d-shtaeou",\r"d-nthiouh",
1515
"i-vhbjkhnth", {"nifty":87}, {"morefield" :\tfalse,"field"
1616
:"yes"} ]
1717
"""
1818

19-
expect_without_sort_keys = textwrap.dedent(r"""\
19+
expect_without_sort_keys = textwrap.dedent("""\
2020
[
2121
[
2222
"blorpie"
@@ -26,7 +26,7 @@ class TestTool(unittest.TestCase):
2626
],
2727
[],
2828
"d-shtaeou",
29-
"\u00a7 \ud83d\udc0d \u03b4 and \ud834\udc3",
29+
"d-nthiouh",
3030
"i-vhbjkhnth",
3131
{
3232
"nifty": 87
@@ -38,7 +38,7 @@ class TestTool(unittest.TestCase):
3838
]
3939
""")
4040

41-
expect = textwrap.dedent(r"""\
41+
expect = textwrap.dedent("""\
4242
[
4343
[
4444
"blorpie"
@@ -48,7 +48,7 @@ class TestTool(unittest.TestCase):
4848
],
4949
[],
5050
"d-shtaeou",
51-
"\u00a7 \ud83d\udc0d \u03b4 and \ud834\udc37",
51+
"d-nthiouh",
5252
"i-vhbjkhnth",
5353
{
5454
"nifty": 87
@@ -106,22 +106,14 @@ def test_sort_keys_flag(self):
106106
self.expect_without_sort_keys.encode().splitlines())
107107
self.assertEqual(err, b'')
108108

109-
def test_no_ensure_ascii_flag(self):
110-
infile = self._create_infile()
111-
rc, out, err = assert_python_ok('-m', 'json.tool', '--no-ensure-ascii', infile)
112-
self.assertEqual(rc, 0)
113-
self.assertEqual(out.splitlines(),
114-
self.expect_without_sort_keys.encode().splitlines())
115-
self.assertEqual(err, b'')
116-
117109
def test_indent(self):
118110
json_stdin = b'[1, 2]'
119-
expect = textwrap.dedent(b'''\
111+
expect = textwrap.dedent('''\
120112
[
121113
1,
122114
2
123115
]
124-
''')
116+
''').encode()
125117
args = sys.executable, '-m', 'json.tool', '--indent', '2'
126118
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
127119
json_stdout, err = proc.communicate(json_stdin)
@@ -133,5 +125,22 @@ def test_no_indent(self):
133125
args = sys.executable, '-m', 'json.tool', '--no-indent'
134126
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
135127
json_stdout, err = proc.communicate(json_stdin)
136-
self.assertEqual(json_stdin, json_stdout)
128+
self.assertEqual(json_stdin.splitlines(), json_stdout.splitlines())
129+
self.assertEqual(err, b'')
130+
131+
def test_ensure_ascii(self):
132+
json_stdin = '"\xA7 \N{snake} \u03B4 \U0001D037"'.encode()
133+
expect = b'"\\u00a7 \\ud83d\\udc0d \\u03b4 \\ud834\\udc37"\n'
134+
args = sys.executable, '-m', 'json.tool'
135+
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
136+
json_stdout, err = proc.communicate(json_stdin)
137+
self.assertEqual(expect.splitlines(), json_stdout.splitlines())
138+
self.assertEqual(err, b'')
139+
140+
def test_no_ensure_ascii(self):
141+
json_stdin = '"\xA7 \N{snake} \u03B4 \U0001D037"'.encode()
142+
args = sys.executable, '-m', 'json.tool', '--no-ensure-ascii'
143+
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
144+
json_stdout, err = proc.communicate(json_stdin)
145+
self.assertEqual(json_stdin.splitlines(), json_stdout.splitlines())
137146
self.assertEqual(err, b'')

0 commit comments

Comments
 (0)