Fixed #26232 -- Fixed Popen mocking environment in i18n tests
Refs #25925. Thanks Jeroen Pulles for the report.
This commit is contained in:
parent
c30086159d
commit
eda306f1ce
@ -165,26 +165,27 @@ class CompilationErrorHandling(MessageCompilationTests):
|
|||||||
with self.assertRaises(CommandError):
|
with self.assertRaises(CommandError):
|
||||||
call_command('compilemessages', locale=['ja'], verbosity=0)
|
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):
|
def test_msgfmt_error_including_non_ascii(self):
|
||||||
# po file contains invalid msgstr content (triggers non-ascii error content).
|
# po file contains invalid msgstr content (triggers non-ascii error content).
|
||||||
mo_file = 'locale/ko/LC_MESSAGES/django.mo'
|
mo_file = 'locale/ko/LC_MESSAGES/django.mo'
|
||||||
self.addCleanup(self.rmfile, os.path.join(self.test_dir, mo_file))
|
self.addCleanup(self.rmfile, os.path.join(self.test_dir, mo_file))
|
||||||
if six.PY2:
|
# Make sure the output of msgfmt is unaffected by the current locale.
|
||||||
# Various assertRaises on PY2 don't support unicode error messages.
|
env = os.environ.copy()
|
||||||
try:
|
env.update({'LANG': 'C'})
|
||||||
call_command('compilemessages', locale=['ko'], verbosity=0)
|
with mock.patch('django.core.management.utils.Popen',
|
||||||
except CommandError as err:
|
lambda *args, **kwargs: Popen(*args, env=env, **kwargs)):
|
||||||
self.assertIn("'<EFBFBD>' cannot start a field name", six.text_type(err))
|
if six.PY2:
|
||||||
else:
|
# Various assertRaises on PY2 don't support unicode error messages.
|
||||||
cmd = MakeMessagesCommand()
|
try:
|
||||||
if cmd.gettext_version < (0, 18, 3):
|
call_command('compilemessages', locale=['ko'], verbosity=0)
|
||||||
raise unittest.SkipTest("python-brace-format is a recent gettext addition.")
|
except CommandError as err:
|
||||||
with self.assertRaisesMessage(CommandError, "'<EFBFBD>' cannot start a field name"):
|
self.assertIn("'<EFBFBD>' cannot start a field name", six.text_type(err))
|
||||||
call_command('compilemessages', locale=['ko'], verbosity=0)
|
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, "'<EFBFBD>' cannot start a field name"):
|
||||||
|
call_command('compilemessages', locale=['ko'], verbosity=0)
|
||||||
|
|
||||||
|
|
||||||
class ProjectAndAppTests(MessageCompilationTests):
|
class ProjectAndAppTests(MessageCompilationTests):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user