Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move tests into existing test files

  • Loading branch information...
commit 305867c060e256cc28e81c78b412fd2e51b28a20 1 parent 4fbb940
@jakul jakul authored
View
44 tests/regressiontests/i18n/commands/compilation.py
@@ -1,11 +1,17 @@
import os
from io import BytesIO
+from StringIO import StringIO
+from django.conf import settings
from django.core.management import call_command, CommandError
+from django.core.management.commands import compilemessages
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import translation
+
+
+
test_dir = os.path.abspath(os.path.dirname(__file__))
class MessageCompilationTests(TestCase):
@@ -66,3 +72,41 @@ def test_percent_symbol_escaping(self):
t = Template('{% load i18n %}{% trans "Completed 50%% of all the tasks" %}')
rendered = t.render(Context({}))
self.assertEqual(rendered, 'IT translation of Completed 50%% of all the tasks')
+
+
+class MultipleLocalesTestCase(TestCase):
+ MO_FILE_DE = None
+ MO_FILE_FR = None
+
+ def setUp(self):
+ self._old_locale_paths = settings.LOCALE_PATHS
+ self.stderr = StringIO()
+ self.localedir = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)), 'locale'
+ )
+ settings.LOCALE_PATHS = [self.localedir]
+ self.MO_FILE_DE = os.path.join(self.localedir, 'de/LC_MESSAGES/django.mo')
+ self.MO_FILE_FR = os.path.join(self.localedir, 'fr/LC_MESSAGES/django.mo')
+
+ def tearDown(self):
+ settings.LOCALE_PATHS = self._old_locale_paths
+ self.stderr.close()
+ self._rmfile(os.path.join(self.localedir, self.MO_FILE_DE))
+ self._rmfile(os.path.join(self.localedir, self.MO_FILE_FR))
+
+ def _rmfile(self, filepath):
+ if os.path.exists(filepath):
+ os.remove(filepath)
+
+ def test_one_locale(self):
+ command = compilemessages.Command()
+ command.execute(locale='de', stderr=self.stderr)
+
+ self.assertTrue(os.path.exists(self.MO_FILE_DE))
+
+ def test_multiple_locales(self):
+ command = compilemessages.Command()
+ command.execute(locale=['de', 'fr'], stderr=self.stderr)
+
+ self.assertTrue(os.path.exists(self.MO_FILE_DE))
+ self.assertTrue(os.path.exists(self.MO_FILE_FR))
View
42 tests/regressiontests/i18n/commands/compilemessages.py
@@ -1,42 +0,0 @@
-from StringIO import StringIO
-from django.test import TestCase
-import os
-from django.core.management.commands import compilemessages
-from django.conf import settings
-
-class CompileMessagesFunctionTestCase(TestCase):
- MO_FILE_DE = None
- MO_FILE_FR = None
-
- def setUp(self):
- self._old_locale_paths = settings.LOCALE_PATHS
- self.stderr = StringIO()
- self.localedir = os.path.join(
- os.path.dirname(os.path.abspath(__file__)), 'locale'
- )
- settings.LOCALE_PATHS = [self.localedir]
- self.MO_FILE_DE = os.path.join(self.localedir, 'de/LC_MESSAGES/django.mo')
- self.MO_FILE_FR = os.path.join(self.localedir, 'fr/LC_MESSAGES/django.mo')
-
- def tearDown(self):
- settings.LOCALE_PATHS = self._old_locale_paths
- self.stderr.close()
- self._rmfile(os.path.join(self.localedir, self.MO_FILE_DE))
- self._rmfile(os.path.join(self.localedir, self.MO_FILE_FR))
-
- def _rmfile(self, filepath):
- if os.path.exists(filepath):
- os.remove(filepath)
-
- def test_one_locale(self):
- command = compilemessages.Command()
- command.execute(locale='de', stderr=self.stderr)
-
- self.assertTrue(os.path.exists(self.MO_FILE_DE))
-
- def test_multiple_locales(self):
- command = compilemessages.Command()
- command.execute(locale=['de', 'fr'], stderr=self.stderr)
-
- self.assertTrue(os.path.exists(self.MO_FILE_DE))
- self.assertTrue(os.path.exists(self.MO_FILE_FR))
View
28 tests/regressiontests/i18n/commands/extraction.py
@@ -267,3 +267,31 @@ def test_no_location_disabled(self):
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertTrue('#: templates/test.html:55' in po_contents)
+
+
+class MultipleLocalesTestCase(ExtractorTests):
+ PO_FILE_PT = 'locale/pt/LC_MESSAGES/django.po'
+ PO_FILE_DE = 'locale/de/LC_MESSAGES/django.po'
+ LOCALES = ['pt', 'de', 'ch']
+
+
+ def tearDown(self):
+ os.chdir(self.test_dir)
+ for locale in self.LOCALES:
+ try:
+ self._rmrf('locale/%s' % locale)
+ except OSError:
+ pass
+ os.chdir(self._cwd)
+
+ def test_multiple_locales(self):
+ os.chdir(self.test_dir)
+ management.call_command('makemessages', locale=['pt','de'], verbosity=0)
+ self.assertTrue(os.path.exists(self.PO_FILE_PT))
+ self.assertTrue(os.path.exists(self.PO_FILE_DE))
+
+ def test_comma_separated_locales(self):
+ os.chdir(self.test_dir)
+ management.call_command('makemessages', locale='pt,de,ch', verbosity=0)
+ self.assertTrue(os.path.exists(self.PO_FILE_PT))
+ self.assertTrue(os.path.exists(self.PO_FILE_DE))
View
30 tests/regressiontests/i18n/commands/makemessages.py
@@ -1,30 +0,0 @@
-import os
-from .extraction import ExtractorTests
-from django.core import management
-
-class MakeMessagesFunctionTestCase(ExtractorTests):
- PO_FILE_PT = 'locale/pt/LC_MESSAGES/django.po'
- PO_FILE_DE = 'locale/de/LC_MESSAGES/django.po'
- LOCALES = ['pt', 'de', 'ch']
-
-
- def tearDown(self):
- os.chdir(self.test_dir)
- for locale in self.LOCALES:
- try:
- self._rmrf('locale/%s' % locale)
- except OSError:
- pass
- os.chdir(self._cwd)
-
- def test_multiple_locales(self):
- os.chdir(self.test_dir)
- management.call_command('makemessages', locale=['pt','de'], verbosity=0)
- self.assertTrue(os.path.exists(self.PO_FILE_PT))
- self.assertTrue(os.path.exists(self.PO_FILE_DE))
-
- def test_comma_separated_locales(self):
- os.chdir(self.test_dir)
- management.call_command('makemessages', locale='pt,de,ch', verbosity=0)
- self.assertTrue(os.path.exists(self.PO_FILE_PT))
- self.assertTrue(os.path.exists(self.PO_FILE_DE))
Please sign in to comment.
Something went wrong with that request. Please try again.