|
@@ -42,7 +42,7 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase):
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=2, stdout=out, **options)
|
|
|
output = out.getvalue()
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
return output, po_contents
|
|
|
|
|
@@ -59,7 +59,7 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase):
|
|
|
return self.assertTrue(not re.search('^msgid %s' % msgid, s, re.MULTILINE))
|
|
|
|
|
|
def _assertPoLocComment(self, assert_presence, po_filename, line_number, *comment_parts):
|
|
|
- with open(po_filename, 'r') as fp:
|
|
|
+ with open(po_filename) as fp:
|
|
|
po_contents = fp.read()
|
|
|
if os.name == 'nt':
|
|
|
# #: .\path\to\file.html:123
|
|
@@ -136,7 +136,7 @@ class BasicExtractorTests(ExtractorTests):
|
|
|
"""
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r', encoding='utf-8') as fp:
|
|
|
+ with open(self.PO_FILE, encoding='utf-8') as fp:
|
|
|
po_contents = fp.read()
|
|
|
# Check two random strings
|
|
|
self.assertIn('#. Translators: One-line translator comment #1', po_contents)
|
|
@@ -145,7 +145,7 @@ class BasicExtractorTests(ExtractorTests):
|
|
|
def test_comments_extractor(self):
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r', encoding='utf-8') as fp:
|
|
|
+ with open(self.PO_FILE, encoding='utf-8') as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertNotIn('This comment should not be extracted', po_contents)
|
|
|
|
|
@@ -178,14 +178,14 @@ class BasicExtractorTests(ExtractorTests):
|
|
|
def test_special_char_extracted(self):
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r', encoding='utf-8') as fp:
|
|
|
+ with open(self.PO_FILE, encoding='utf-8') as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertMsgId("Non-breaking space\u00a0:", po_contents)
|
|
|
|
|
|
def test_blocktrans_trimmed(self):
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
# should not be trimmed
|
|
|
self.assertNotMsgId('Text with a few line breaks.', po_contents)
|
|
@@ -229,7 +229,7 @@ class BasicExtractorTests(ExtractorTests):
|
|
|
"""
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
# {% trans %}
|
|
|
self.assertIn('msgctxt "Special trans context #1"', po_contents)
|
|
@@ -259,7 +259,7 @@ class BasicExtractorTests(ExtractorTests):
|
|
|
def test_context_in_single_quotes(self):
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
# {% trans %}
|
|
|
self.assertIn('msgctxt "Context wrapped in double quotes"', po_contents)
|
|
@@ -299,7 +299,7 @@ class BasicExtractorTests(ExtractorTests):
|
|
|
)
|
|
|
# Now test .po file contents
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
|
|
|
self.assertMsgId('Translatable literal #9a', po_contents)
|
|
@@ -391,7 +391,7 @@ class BasicExtractorTests(ExtractorTests):
|
|
|
shutil.copyfile(BR_PO_BASE + '.pristine', BR_PO_BASE + '.po')
|
|
|
management.call_command('makemessages', locale=['pt_BR'], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(BR_PO_BASE + '.po'))
|
|
|
- with open(BR_PO_BASE + '.po', 'r', encoding='utf-8') as fp:
|
|
|
+ with open(BR_PO_BASE + '.po', encoding='utf-8') as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertMsgStr("Größe", po_contents)
|
|
|
|
|
@@ -410,7 +410,7 @@ class BasicExtractorTests(ExtractorTests):
|
|
|
with tempfile.NamedTemporaryFile() as pot_file:
|
|
|
pot_filename = pot_file.name
|
|
|
write_pot_file(pot_filename, msgs)
|
|
|
- with open(pot_filename, 'r', encoding='utf-8') as fp:
|
|
|
+ with open(pot_filename, encoding='utf-8') as fp:
|
|
|
pot_contents = fp.read()
|
|
|
self.assertIn('Content-Type: text/plain; charset=UTF-8', pot_contents)
|
|
|
self.assertIn('mañana; charset=CHARSET', pot_contents)
|
|
@@ -506,7 +506,7 @@ class SymlinkExtractorTests(ExtractorTests):
|
|
|
os.chdir(self.test_dir)
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0, symlinks=True)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertMsgId('This literal should be included.', po_contents)
|
|
|
self.assertLocationCommentPresent(self.PO_FILE, None, 'templates_symlinked', 'test.html')
|
|
@@ -519,7 +519,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
|
|
|
def test_copy_plural_forms(self):
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertIn('Plural-Forms: nplurals=2; plural=(n != 1)', po_contents)
|
|
|
|
|
@@ -527,7 +527,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
|
|
|
"""Ticket #20311."""
|
|
|
management.call_command('makemessages', locale=['es'], extensions=['djtpl'], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE_ES))
|
|
|
- with open(self.PO_FILE_ES, 'r', encoding='utf-8') as fp:
|
|
|
+ with open(self.PO_FILE_ES, encoding='utf-8') as fp:
|
|
|
po_contents = fp.read()
|
|
|
found = re.findall(r'^(?P<value>"Plural-Forms.+?\\n")\s*$', po_contents, re.MULTILINE | re.DOTALL)
|
|
|
self.assertEqual(1, len(found))
|
|
@@ -540,7 +540,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
|
|
|
"""
|
|
|
management.call_command('makemessages', locale=[LOCALE], extensions=['html', 'djtpl'], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertNotIn("#-#-#-#-# django.pot (PACKAGE VERSION) #-#-#-#-#\\n", po_contents)
|
|
|
self.assertMsgId('First `trans`, then `blocktrans` with a plural', po_contents)
|
|
@@ -552,7 +552,7 @@ class NoWrapExtractorTests(ExtractorTests):
|
|
|
def test_no_wrap_enabled(self):
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=True)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertMsgId(
|
|
|
'This literal should also be included wrapped or not wrapped '
|
|
@@ -563,7 +563,7 @@ class NoWrapExtractorTests(ExtractorTests):
|
|
|
def test_no_wrap_disabled(self):
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=False)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertMsgId(
|
|
|
'""\n"This literal should also be included wrapped or not '
|
|
@@ -595,7 +595,7 @@ class LocationCommentsTests(ExtractorTests):
|
|
|
"""
|
|
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
|
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
|
|
- with open(self.PO_FILE, 'r') as fp:
|
|
|
+ with open(self.PO_FILE) as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertMsgId('#: templates/test.html.py', po_contents)
|
|
|
self.assertLocationCommentNotPresent(self.PO_FILE, None, '.html.py')
|
|
@@ -753,11 +753,11 @@ class CustomLayoutExtractionTests(ExtractorTests):
|
|
|
self.assertTrue(os.path.exists(project_de_locale))
|
|
|
self.assertTrue(os.path.exists(app_de_locale))
|
|
|
|
|
|
- with open(project_de_locale, 'r') as fp:
|
|
|
+ with open(project_de_locale) as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertMsgId('This app has no locale directory', po_contents)
|
|
|
self.assertMsgId('This is a project-level string', po_contents)
|
|
|
- with open(app_de_locale, 'r') as fp:
|
|
|
+ with open(app_de_locale) as fp:
|
|
|
po_contents = fp.read()
|
|
|
self.assertMsgId('This app has a locale directory', po_contents)
|
|
|
|