~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to tests/regressiontests/i18n/commands/extraction.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone, Jakub Wilk, Luke Faraone
  • Date: 2013-05-09 15:10:47 UTC
  • mfrom: (1.1.21) (4.4.27 sid)
  • Revision ID: package-import@ubuntu.com-20130509151047-aqv8d71oj9wvcv8c
Tags: 1.5.1-2
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Luke Faraone ]
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
2
 
from __future__ import with_statement
 
2
from __future__ import unicode_literals
3
3
 
4
4
import os
5
5
import re
6
6
import shutil
7
 
from StringIO import StringIO
8
7
 
9
8
from django.core import management
10
9
from django.test import TestCase
 
10
from django.utils.encoding import force_text
 
11
from django.utils._os import upath
 
12
from django.utils.six import StringIO
11
13
 
12
14
 
13
15
LOCALE='de'
18
20
 
19
21
    def setUp(self):
20
22
        self._cwd = os.getcwd()
21
 
        self.test_dir = os.path.abspath(os.path.dirname(__file__))
 
23
        self.test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
22
24
 
23
25
    def _rmrf(self, dname):
24
26
        if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
56
58
        management.call_command('makemessages', locale=LOCALE, verbosity=0)
57
59
        self.assertTrue(os.path.exists(self.PO_FILE))
58
60
        with open(self.PO_FILE, 'r') as fp:
59
 
            po_contents = fp.read()
 
61
            po_contents = force_text(fp.read())
60
62
            self.assertTrue('#. Translators: This comment should be extracted' in po_contents)
61
63
            self.assertTrue('This comment should not be extracted' not in po_contents)
62
64
            # Comments in templates
84
86
        management.call_command('makemessages', locale=LOCALE, verbosity=0)
85
87
        self.assertTrue(os.path.exists(self.PO_FILE))
86
88
        with open(self.PO_FILE, 'r') as fp:
87
 
            po_contents = fp.read()
 
89
            po_contents = force_text(fp.read())
88
90
            self.assertMsgId('Literal with a percent symbol at the end %%', po_contents)
89
91
            self.assertMsgId('Literal with a percent %% symbol in the middle', po_contents)
90
92
            self.assertMsgId('Completed 50%% of all the tasks', po_contents)
100
102
        management.call_command('makemessages', locale=LOCALE, verbosity=0)
101
103
        self.assertTrue(os.path.exists(self.PO_FILE))
102
104
        with open(self.PO_FILE, 'r') as fp:
103
 
            po_contents = fp.read()
 
105
            po_contents = force_text(fp.read())
104
106
            self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents)
105
107
            self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents)
106
108
            self.assertMsgId("Blocktrans extraction shouldn't double escape this: %%, a=%(a)s", po_contents)
118
120
        # Check that the temporary file was cleaned up
119
121
        self.assertFalse(os.path.exists('./templates/template_with_error.html.py'))
120
122
 
 
123
    def test_extraction_warning(self):
 
124
        os.chdir(self.test_dir)
 
125
        shutil.copyfile('./code.sample', './code_sample.py')
 
126
        stdout = StringIO()
 
127
        management.call_command('makemessages', locale=LOCALE, stdout=stdout)
 
128
        os.remove('./code_sample.py')
 
129
        self.assertIn("code_sample.py:4", force_text(stdout.getvalue()))
 
130
 
121
131
    def test_template_message_context_extractor(self):
122
132
        """
123
133
        Ensure that message contexts are correctly extracted for the
128
138
        management.call_command('makemessages', locale=LOCALE, verbosity=0)
129
139
        self.assertTrue(os.path.exists(self.PO_FILE))
130
140
        with open(self.PO_FILE, 'r') as fp:
131
 
            po_contents = fp.read()
 
141
            po_contents = force_text(fp.read())
132
142
            # {% trans %}
133
143
            self.assertTrue('msgctxt "Special trans context #1"' in po_contents)
134
144
            self.assertTrue("Translatable literal #7a" in po_contents)
154
164
        management.call_command('makemessages', locale=LOCALE, verbosity=0)
155
165
        self.assertTrue(os.path.exists(self.PO_FILE))
156
166
        with open(self.PO_FILE, 'r') as fp:
157
 
            po_contents = fp.read()
 
167
            po_contents = force_text(fp.read())
158
168
            # {% trans %}
159
169
            self.assertTrue('msgctxt "Context wrapped in double quotes"' in po_contents)
160
170
            self.assertTrue('msgctxt "Context wrapped in single quotes"' in po_contents)
209
219
 
210
220
    def setUp(self):
211
221
        self._cwd = os.getcwd()
212
 
        self.test_dir = os.path.abspath(os.path.dirname(__file__))
 
222
        self.test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
213
223
        self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked')
214
224
 
215
225
    def tearDown(self):
231
241
            management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True)
232
242
            self.assertTrue(os.path.exists(self.PO_FILE))
233
243
            with open(self.PO_FILE, 'r') as fp:
234
 
                po_contents = fp.read()
 
244
                po_contents = force_text(fp.read())
235
245
                self.assertMsgId('This literal should be included.', po_contents)
236
246
                self.assertTrue('templates_symlinked/test.html' in po_contents)
237
247
 
243
253
        management.call_command('makemessages', locale=LOCALE, verbosity=0)
244
254
        self.assertTrue(os.path.exists(self.PO_FILE))
245
255
        with open(self.PO_FILE, 'r') as fp:
246
 
            po_contents = fp.read()
 
256
            po_contents = force_text(fp.read())
247
257
            self.assertTrue('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)
248
258
 
249
259
 
254
264
        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=True)
255
265
        self.assertTrue(os.path.exists(self.PO_FILE))
256
266
        with open(self.PO_FILE, 'r') as fp:
257
 
            po_contents = fp.read()
 
267
            po_contents = force_text(fp.read())
258
268
            self.assertMsgId('This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option.', po_contents)
259
269
 
260
270
    def test_no_wrap_disabled(self):
262
272
        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=False)
263
273
        self.assertTrue(os.path.exists(self.PO_FILE))
264
274
        with open(self.PO_FILE, 'r') as fp:
265
 
            po_contents = fp.read()
 
275
            po_contents = force_text(fp.read())
266
276
            self.assertMsgId('""\n"This literal should also be included wrapped or not wrapped depending on the "\n"use of the --no-wrap option."', po_contents, use_quotes=False)
267
277
 
268
278
 
273
283
        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True)
274
284
        self.assertTrue(os.path.exists(self.PO_FILE))
275
285
        with open(self.PO_FILE, 'r') as fp:
276
 
            po_contents = fp.read()
 
286
            po_contents = force_text(fp.read())
277
287
            self.assertFalse('#: templates/test.html:55' in po_contents)
278
288
 
279
289
    def test_no_location_disabled(self):
281
291
        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False)
282
292
        self.assertTrue(os.path.exists(self.PO_FILE))
283
293
        with open(self.PO_FILE, 'r') as fp:
284
 
            po_contents = fp.read()
 
294
            po_contents = force_text(fp.read())
285
295
            self.assertTrue('#: templates/test.html:55' in po_contents)