Add Django-1.2.1
[frozenviper.git] / Django-1.2.1 / tests / regressiontests / makemessages / extraction.py
blob4b4fa1b07e955f03de686c0555241abf45f9b8a9
1 import os
2 import re
3 import shutil
4 from django.test import TestCase
5 from django.core import management
7 LOCALE='de'
9 class ExtractorTests(TestCase):
11 PO_FILE='locale/%s/LC_MESSAGES/django.po' % LOCALE
13 def setUp(self):
14 self._cwd = os.getcwd()
15 self.test_dir = os.path.abspath(os.path.dirname(__file__))
17 def _rmrf(self, dname):
18 if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
19 return
20 shutil.rmtree(dname)
22 def tearDown(self):
23 os.chdir(self.test_dir)
24 try:
25 self._rmrf('locale/%s' % LOCALE)
26 except OSError:
27 pass
28 os.chdir(self._cwd)
30 def assertMsgId(self, msgid, s):
31 return self.assert_(re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
33 def assertNotMsgId(self, msgid, s):
34 return self.assert_(not re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
37 class JavascriptExtractorTests(ExtractorTests):
39 PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
41 def test_javascript_literals(self):
42 os.chdir(self.test_dir)
43 management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0)
44 self.assert_(os.path.exists(self.PO_FILE))
45 po_contents = open(self.PO_FILE, 'r').read()
46 self.assertMsgId('This literal should be included.', po_contents)
47 self.assertMsgId('This one as well.', po_contents)
50 class IgnoredExtractorTests(ExtractorTests):
52 def test_ignore_option(self):
53 os.chdir(self.test_dir)
54 management.call_command('makemessages', locale=LOCALE, verbosity=0, ignore_patterns=['ignore_dir/*'])
55 self.assert_(os.path.exists(self.PO_FILE))
56 po_contents = open(self.PO_FILE, 'r').read()
57 self.assertMsgId('This literal should be included.', po_contents)
58 self.assertNotMsgId('This should be ignored.', po_contents)
61 class SymlinkExtractorTests(ExtractorTests):
63 def setUp(self):
64 self._cwd = os.getcwd()
65 self.test_dir = os.path.abspath(os.path.dirname(__file__))
66 self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked')
68 def tearDown(self):
69 super(SymlinkExtractorTests, self).tearDown()
70 os.chdir(self.test_dir)
71 try:
72 os.remove(self.symlinked_dir)
73 except OSError:
74 pass
75 os.chdir(self._cwd)
77 def test_symlink(self):
78 if hasattr(os, 'symlink'):
79 if os.path.exists(self.symlinked_dir):
80 self.assert_(os.path.islink(self.symlinked_dir))
81 else:
82 os.symlink(os.path.join(self.test_dir, 'templates'), self.symlinked_dir)
83 os.chdir(self.test_dir)
84 management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True)
85 self.assert_(os.path.exists(self.PO_FILE))
86 po_contents = open(self.PO_FILE, 'r').read()
87 self.assertMsgId('This literal should be included.', po_contents)
88 self.assert_('templates_symlinked/test.html' in po_contents)
91 class CopyPluralFormsExtractorTests(ExtractorTests):
93 def test_copy_plural_forms(self):
94 os.chdir(self.test_dir)
95 management.call_command('makemessages', locale=LOCALE, verbosity=0)
96 self.assert_(os.path.exists(self.PO_FILE))
97 po_contents = open(self.PO_FILE, 'r').read()
98 self.assert_('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)