summaryrefslogtreecommitdiff
path: root/tests/i18n/test_extraction.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-04-28 20:37:36 +0200
committerClaude Paroz <claude@2xlibre.net>2016-04-30 12:07:40 +0200
commit185f90c45f4398f186ee9dffe1c9bd7392a47686 (patch)
treec70bd7e99f99b4a83b791d6279581b87f4c6180f /tests/i18n/test_extraction.py
parent7f51876f99851fdc3fef63aecdfbcffa199c26b9 (diff)
downloaddjango-185f90c45f4398f186ee9dffe1c9bd7392a47686.tar.gz
Adapted _assertPoLocComment for multi-file source lines in po files
Refs #17375.
Diffstat (limited to 'tests/i18n/test_extraction.py')
-rw-r--r--tests/i18n/test_extraction.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index 6fdfbcb896..bae2840934 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -107,10 +107,9 @@ class ExtractorTests(SerializeMixin, SimpleTestCase):
else:
# #: path/to/file.html:123
cwd_prefix = ''
- parts = ['#: ']
path = os.path.join(cwd_prefix, *comment_parts)
- parts.append(path)
+ parts = [path]
if isinstance(line_number, six.string_types):
line_number = self._get_token_line_number(path, line_number)
@@ -118,10 +117,18 @@ class ExtractorTests(SerializeMixin, SimpleTestCase):
parts.append(':%d' % line_number)
needle = ''.join(parts)
+ pattern = re.compile(r'^\#\:.*' + re.escape(needle), re.MULTILINE)
if assert_presence:
- return self.assertIn(needle, po_contents, '"%s" not found in final .po file.' % needle)
+ return six.assertRegex(self, po_contents, pattern, '"%s" not found in final .po file.' % needle)
else:
- return self.assertNotIn(needle, po_contents, '"%s" shouldn\'t be in final .po file.' % needle)
+ if six.PY3:
+ return self.assertNotRegex(
+ po_contents, pattern, '"%s" shouldn\'t be in final .po file.' % needle
+ )
+ else:
+ return self.assertNotRegexpMatches(
+ po_contents, pattern, '"%s" shouldn\'t be in final .po file.' % needle
+ )
def _get_token_line_number(self, path, token):
with open(path) as f:
@@ -632,7 +639,7 @@ class LocationCommentsTests(ExtractorTests):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_location=True)
self.assertTrue(os.path.exists(self.PO_FILE))
- self.assertLocationCommentNotPresent(self.PO_FILE, 55, 'templates', 'test.html.py')
+ self.assertLocationCommentNotPresent(self.PO_FILE, None, 'test.html')
def test_no_location_disabled(self):
"""Behavior is correct if --no-location switch isn't specified."""
@@ -642,7 +649,7 @@ class LocationCommentsTests(ExtractorTests):
# #16903 -- Standard comment with source file relative path should be present
self.assertLocationCommentPresent(self.PO_FILE, 'Translatable literal #6b', 'templates', 'test.html')
- # #21208 -- Leaky paths in comments on Windows e.g. #: path\to\file.html.py:123
+ # #21209 -- Leaky paths in comments on Windows e.g. #: path\to\file.html.py:123
self.assertLocationCommentNotPresent(self.PO_FILE, None, 'templates', 'test.html.py')