Used call_command in i18n compilation tests.
Now that call_command does not raise SystemExit any more, we can use call_command again for testing compilemessages.
This commit is contained in:
parent
cc4b4d9fd3
commit
c3b56c7cdd
|
@ -1,8 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from django.core.management import CommandError
|
from django.core.management import call_command, CommandError
|
||||||
from django.core.management.commands.compilemessages import compile_messages
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
@ -25,11 +24,9 @@ class PoFileTests(MessageCompilationTests):
|
||||||
|
|
||||||
def test_bom_rejection(self):
|
def test_bom_rejection(self):
|
||||||
os.chdir(test_dir)
|
os.chdir(test_dir)
|
||||||
# We don't use the django.core.management infrastructure (call_command()
|
with self.assertRaisesRegexp(CommandError,
|
||||||
# et al) because CommandError's cause exit(1) there. We test the
|
"file has a BOM \(Byte Order Mark\)"):
|
||||||
# underlying compile_messages function instead
|
call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO())
|
||||||
out = BytesIO()
|
|
||||||
self.assertRaises(CommandError, compile_messages, out, locale=self.LOCALE)
|
|
||||||
self.assertFalse(os.path.exists(self.MO_FILE))
|
self.assertFalse(os.path.exists(self.MO_FILE))
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,11 +42,7 @@ class PoFileContentsTests(MessageCompilationTests):
|
||||||
|
|
||||||
def test_percent_symbol_in_po_file(self):
|
def test_percent_symbol_in_po_file(self):
|
||||||
os.chdir(test_dir)
|
os.chdir(test_dir)
|
||||||
# We don't use the django.core.management infrastructure (call_command()
|
call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO())
|
||||||
# et al) because CommandError's cause exit(1) there. We test the
|
|
||||||
# underlying compile_messages function instead
|
|
||||||
out = BytesIO()
|
|
||||||
compile_messages(out, locale=self.LOCALE)
|
|
||||||
self.assertTrue(os.path.exists(self.MO_FILE))
|
self.assertTrue(os.path.exists(self.MO_FILE))
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,11 +57,7 @@ class PercentRenderingTests(MessageCompilationTests):
|
||||||
def test_percent_symbol_escaping(self):
|
def test_percent_symbol_escaping(self):
|
||||||
from django.template import Template, Context
|
from django.template import Template, Context
|
||||||
os.chdir(test_dir)
|
os.chdir(test_dir)
|
||||||
# We don't use the django.core.management infrastructure (call_command()
|
call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO())
|
||||||
# et al) because CommandError's cause exit(1) there. We test the
|
|
||||||
# underlying compile_messages function instead
|
|
||||||
out = BytesIO()
|
|
||||||
compile_messages(out, locale=self.LOCALE)
|
|
||||||
with translation.override(self.LOCALE):
|
with translation.override(self.LOCALE):
|
||||||
t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}')
|
t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}')
|
||||||
rendered = t.render(Context({}))
|
rendered = t.render(Context({}))
|
||||||
|
|
Loading…
Reference in New Issue