summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-02-20 09:36:01 +0100
committerClaude Paroz <claude@2xlibre.net>2016-02-23 20:06:18 +0100
commiteda306f1cec20d490d5dc798ddaa8e8e8d13f26e (patch)
tree78682b49de588e33aca073b59803963e574dec0d
parentc30086159d6b6e33a10f18ec0d11719636bc1a94 (diff)
Fixed #26232 -- Fixed Popen mocking environment in i18n tests
Refs #25925. Thanks Jeroen Pulles for the report.
-rw-r--r--tests/i18n/test_compilation.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py
index 6410b8d74a..f60904ffa6 100644
--- a/tests/i18n/test_compilation.py
+++ b/tests/i18n/test_compilation.py
@@ -165,26 +165,27 @@ class CompilationErrorHandling(MessageCompilationTests):
with self.assertRaises(CommandError):
call_command('compilemessages', locale=['ja'], verbosity=0)
- # We will check the output of msgfmt, so we need to make sure its output
- # is unaffected by the current locale.
- @mock.patch('django.core.management.utils.Popen',
- lambda *args, **kwargs: Popen(*args, env={'LANG': 'C'}, **kwargs))
def test_msgfmt_error_including_non_ascii(self):
# po file contains invalid msgstr content (triggers non-ascii error content).
mo_file = 'locale/ko/LC_MESSAGES/django.mo'
self.addCleanup(self.rmfile, os.path.join(self.test_dir, mo_file))
- if six.PY2:
- # Various assertRaises on PY2 don't support unicode error messages.
- try:
- call_command('compilemessages', locale=['ko'], verbosity=0)
- except CommandError as err:
- self.assertIn("'�' cannot start a field name", six.text_type(err))
- else:
- cmd = MakeMessagesCommand()
- if cmd.gettext_version < (0, 18, 3):
- raise unittest.SkipTest("python-brace-format is a recent gettext addition.")
- with self.assertRaisesMessage(CommandError, "'�' cannot start a field name"):
- call_command('compilemessages', locale=['ko'], verbosity=0)
+ # Make sure the output of msgfmt is unaffected by the current locale.
+ env = os.environ.copy()
+ env.update({'LANG': 'C'})
+ with mock.patch('django.core.management.utils.Popen',
+ lambda *args, **kwargs: Popen(*args, env=env, **kwargs)):
+ if six.PY2:
+ # Various assertRaises on PY2 don't support unicode error messages.
+ try:
+ call_command('compilemessages', locale=['ko'], verbosity=0)
+ except CommandError as err:
+ self.assertIn("'�' cannot start a field name", six.text_type(err))
+ else:
+ cmd = MakeMessagesCommand()
+ if cmd.gettext_version < (0, 18, 3):
+ raise unittest.SkipTest("python-brace-format is a recent gettext addition.")
+ with self.assertRaisesMessage(CommandError, "'�' cannot start a field name"):
+ call_command('compilemessages', locale=['ko'], verbosity=0)
class ProjectAndAppTests(MessageCompilationTests):