Merge pull request #910 from bmispelon/ticket-20058
Fix #20058: Make compilemessages use stdout instead of stderr.
This commit is contained in:
commit
74a80a5169
|
@ -15,7 +15,7 @@ def has_bom(fn):
|
|||
sample.startswith(codecs.BOM_UTF16_LE) or \
|
||||
sample.startswith(codecs.BOM_UTF16_BE)
|
||||
|
||||
def compile_messages(stderr, locale=None):
|
||||
def compile_messages(stdout, locale=None):
|
||||
program = 'msgfmt'
|
||||
if find_command(program) is None:
|
||||
raise CommandError("Can't find %s. Make sure you have GNU gettext tools 0.15 or newer installed." % program)
|
||||
|
@ -41,7 +41,7 @@ def compile_messages(stderr, locale=None):
|
|||
for f in filenames:
|
||||
if not f.endswith('.po'):
|
||||
continue
|
||||
stderr.write('processing file %s in %s\n' % (f, dirpath))
|
||||
stdout.write('processing file %s in %s\n' % (f, dirpath))
|
||||
fn = os.path.join(dirpath, f)
|
||||
if has_bom(fn):
|
||||
raise CommandError("The %s file has a BOM (Byte Order Mark). Django only supports .po files encoded in UTF-8 and without any BOM." % fn)
|
||||
|
@ -68,4 +68,4 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, **options):
|
||||
locale = options.get('locale')
|
||||
compile_messages(self.stderr, locale=locale)
|
||||
compile_messages(self.stdout, locale=locale)
|
||||
|
|
|
@ -29,7 +29,7 @@ class PoFileTests(MessageCompilationTests):
|
|||
|
||||
def test_bom_rejection(self):
|
||||
with self.assertRaises(CommandError) as cm:
|
||||
call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
|
||||
call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
|
||||
self.assertIn("file has a BOM (Byte Order Mark)", cm.exception.args[0])
|
||||
self.assertFalse(os.path.exists(self.MO_FILE))
|
||||
|
||||
|
@ -45,7 +45,7 @@ class PoFileContentsTests(MessageCompilationTests):
|
|||
self.addCleanup(os.unlink, os.path.join(test_dir, self.MO_FILE))
|
||||
|
||||
def test_percent_symbol_in_po_file(self):
|
||||
call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
|
||||
call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
|
||||
self.assertTrue(os.path.exists(self.MO_FILE))
|
||||
|
||||
|
||||
|
@ -63,7 +63,7 @@ class PercentRenderingTests(MessageCompilationTests):
|
|||
@override_settings(LOCALE_PATHS=(os.path.join(test_dir, 'locale'),))
|
||||
def test_percent_symbol_escaping(self):
|
||||
from django.template import Template, Context
|
||||
call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
|
||||
call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
|
||||
with translation.override(self.LOCALE):
|
||||
t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}')
|
||||
rendered = t.render(Context({}))
|
||||
|
@ -88,12 +88,12 @@ class MultipleLocaleCompilationTests(MessageCompilationTests):
|
|||
self.addCleanup(self.rmfile, os.path.join(localedir, self.MO_FILE_FR))
|
||||
|
||||
def test_one_locale(self):
|
||||
call_command('compilemessages', locale='hr', stderr=StringIO())
|
||||
call_command('compilemessages', locale='hr', stdout=StringIO())
|
||||
|
||||
self.assertTrue(os.path.exists(self.MO_FILE_HR))
|
||||
|
||||
def test_multiple_locales(self):
|
||||
call_command('compilemessages', locale=['hr', 'fr'], stderr=StringIO())
|
||||
call_command('compilemessages', locale=['hr', 'fr'], stdout=StringIO())
|
||||
|
||||
self.assertTrue(os.path.exists(self.MO_FILE_HR))
|
||||
self.assertTrue(os.path.exists(self.MO_FILE_FR))
|
||||
|
@ -110,4 +110,4 @@ class CompilationErrorHandling(MessageCompilationTests):
|
|||
|
||||
def test_error_reported_by_msgfmt(self):
|
||||
with self.assertRaises(CommandError):
|
||||
call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
|
||||
call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
|
||||
|
|
Loading…
Reference in New Issue