Skip to content

Commit 05a205f

Browse files
committed
Use textwrap.dedent
1 parent 6ba1488 commit 05a205f

File tree

1 file changed

+88
-87
lines changed

1 file changed

+88
-87
lines changed

Lib/test/test_tools/test_msgfmt.py

Lines changed: 88 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from test.support.os_helper import temp_cwd
1111
from test.support.script_helper import assert_python_failure, assert_python_ok
1212
from test.test_tools import imports_under_tool, skip_if_missing, toolsdir
13+
from textwrap import dedent
1314

1415

1516
skip_if_missing('i18n')
@@ -255,63 +256,63 @@ def test_general_syntax_errors(self):
255256
'[0]',
256257

257258
# unclosed string
258-
'''
259-
msgid "
260-
msgstr "bar"
261-
''',
259+
dedent('''\
260+
msgid "
261+
msgstr "bar"
262+
'''),
262263

263264
# unclosed string
264-
'''
265-
msgid "foo
266-
msgstr "bar"
267-
''',
265+
dedent('''\
266+
msgid "foo
267+
msgstr "bar"
268+
'''),
268269

269270
# unclosed string
270-
'''
271-
msgid "foo" "
272-
msgstr "bar"
273-
''',
271+
dedent('''\
272+
msgid "foo" "
273+
msgstr "bar"
274+
'''),
274275

275276
# unclosed string
276-
'''
277-
msgid "foo"
278-
"
279-
msgstr "bar"
280-
''',
277+
dedent('''\
278+
msgid "foo"
279+
"
280+
msgstr "bar"
281+
'''),
281282

282283
# illegal backslash
283-
'''
284-
msgid "foo\\"
285-
"
286-
msgstr "bar"
287-
''',
284+
dedent('''\
285+
msgid "foo\\"
286+
"
287+
msgstr "bar"
288+
'''),
288289

289290
# msgid with an index
290-
'''
291-
msgid[0] "foo"
292-
msgstr "bar"
293-
''',
291+
dedent('''\
292+
msgid[0] "foo"
293+
msgstr "bar"
294+
'''),
294295

295296
# invalid plural index
296-
'''
297-
msgid "foo"
298-
msgid_plural "foos"
299-
msgstr[0 "baz"
300-
''',
297+
dedent('''\
298+
msgid "foo"
299+
msgid_plural "foos"
300+
msgstr[0 "baz"
301+
'''),
301302

302303
# invalid plural index
303-
'''
304-
msgid "foo"
305-
msgid_plural "foos"
306-
msgstr1] "baz"
307-
''',
304+
dedent('''\
305+
msgid "foo"
306+
msgid_plural "foos"
307+
msgstr1] "baz"
308+
'''),
308309

309310
# invalid plural index
310-
'''
311-
msgid "foo"
312-
msgid_plural "foos"
313-
msgstr[[0]] "baz"
314-
''',
311+
dedent('''\
312+
msgid "foo"
313+
msgid_plural "foos"
314+
msgstr[[0]] "baz"
315+
'''),
315316
)
316317
with temp_cwd():
317318
for invalid_po in invalid_po_files:
@@ -326,66 +327,66 @@ def test_general_syntax_errors(self):
326327
def test_semantic_errors(self):
327328
invalid_po_files = (
328329
# msgid_plural must be preceded by msgid
329-
'''
330-
msgid_plural "foos"
330+
dedent('''\
331+
msgid_plural "foos"
331332
332-
msgid "bar"
333-
msgstr "baz"
334-
''',
333+
msgid "bar"
334+
msgstr "baz"
335+
'''),
335336

336337
# msgid_plural not allowed after comment
337-
'''
338-
# comment
339-
msgid_plural "foos"
338+
dedent('''\
339+
# comment
340+
msgid_plural "foos"
340341
341-
msgid "bar"
342-
msgstr "baz"
343-
''',
342+
msgid "bar"
343+
msgstr "baz"
344+
'''),
344345

345346
# msgid_plural not allowed after msgctxt
346-
'''
347-
msgctxt "foo"
348-
msgid_plural "foos"
347+
dedent('''\
348+
msgctxt "foo"
349+
msgid_plural "foos"
349350
350-
msgid "bar"
351-
msgstr "baz"
352-
''',
351+
msgid "bar"
352+
msgstr "baz"
353+
'''),
353354

354355
# msgid_plural not allowed after msgstr
355-
'''
356-
msgid "foo"
357-
msgstr "bar"
358-
msgid_plural "foos"
356+
dedent('''\
357+
msgid "foo"
358+
msgstr "bar"
359+
msgid_plural "foos"
359360
360-
msgid "bar"
361-
msgstr "baz"
362-
''',
361+
msgid "bar"
362+
msgstr "baz"
363+
'''),
363364

364365
# msgstr must be preceded by msgid
365-
'''
366-
msgstr "foo"
366+
dedent('''\
367+
msgstr "foo"
367368
368-
msgid "bar"
369-
msgstr "baz"
370-
''',
369+
msgid "bar"
370+
msgstr "baz"
371+
'''),
371372

372373
# msgstr not allowed after msgctxt
373-
'''
374-
msgctxt "foo"
375-
msgstr "bar"
374+
dedent('''\
375+
msgctxt "foo"
376+
msgstr "bar"
376377
377-
msgid "foo"
378-
msgstr "bar"
379-
''',
378+
msgid "foo"
379+
msgstr "bar"
380+
'''),
380381

381382
# missing msgid_plural section
382-
'''
383-
msgid "foo"
384-
msgstr[0] "bar"
383+
dedent('''\
384+
msgid "foo"
385+
msgstr[0] "bar"
385386
386-
msgid "bar"
387-
msgstr "baz"
388-
'''
387+
msgid "bar"
388+
msgstr "baz"
389+
'''),
389390
)
390391
with temp_cwd():
391392
for invalid_po in invalid_po_files:
@@ -399,11 +400,11 @@ def test_semantic_errors(self):
399400
def test_msgstr_invalid_indices(self):
400401
invalid_po_files = (
401402
# msgstr not pluralized
402-
'''
403-
msgid "foo"
404-
msgid_plural "foos"
405-
msgstr "bar"
406-
''',
403+
dedent('''\
404+
msgid "foo"
405+
msgid_plural "foos"
406+
msgstr "bar"
407+
'''),
407408
)
408409
with temp_cwd():
409410
for invalid_po in invalid_po_files:

0 commit comments

Comments
 (0)