Mercurial > babel > old > babel-test
annotate babel/messages/tests/frontend.py @ 524:4a5340c0821b stable-0.9.x
merge r573, r575 from trunk to 0.9 branch
author | fschwarz |
---|---|
date | Sat, 05 Mar 2011 14:58:58 +0000 |
parents | dbb70d75718a |
children | d71a490c11df |
rev | line source |
---|---|
12
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
2 # |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
3 # Copyright (C) 2007 Edgewall Software |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
5 # |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://babel.edgewall.org/wiki/License. |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
9 # |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://babel.edgewall.org/log/. |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
13 |
134 | 14 from datetime import datetime |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
15 from distutils.dist import Distribution |
379 | 16 from distutils.errors import DistutilsOptionError |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
17 from distutils.log import _global_log |
12
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
18 import doctest |
524 | 19 import logging |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
20 import os |
120 | 21 import shutil |
127 | 22 from StringIO import StringIO |
23 import sys | |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
24 import time |
12
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
25 import unittest |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
26 |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
27 from babel import __version__ as VERSION |
134 | 28 from babel.dates import format_datetime |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
29 from babel.messages import frontend |
134 | 30 from babel.util import LOCALTZ |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
31 |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
32 |
160 | 33 class CompileCatalogTestCase(unittest.TestCase): |
34 | |
35 def setUp(self): | |
36 self.olddir = os.getcwd() | |
37 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | |
38 os.chdir(self.datadir) | |
39 _global_log.threshold = 5 # shut up distutils logging | |
40 | |
41 self.dist = Distribution(dict( | |
42 name='TestProject', | |
43 version='0.1', | |
44 packages=['project'] | |
45 )) | |
46 self.cmd = frontend.compile_catalog(self.dist) | |
47 self.cmd.initialize_options() | |
48 | |
49 def tearDown(self): | |
50 os.chdir(self.olddir) | |
51 | |
52 def test_no_directory_or_output_file_specified(self): | |
53 self.cmd.locale = 'en_US' | |
54 self.cmd.input_file = 'dummy' | |
55 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
56 | |
57 def test_no_directory_or_input_file_specified(self): | |
58 self.cmd.locale = 'en_US' | |
59 self.cmd.output_file = 'dummy' | |
60 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
61 | |
62 | |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
63 class ExtractMessagesTestCase(unittest.TestCase): |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
64 |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
65 def setUp(self): |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
66 self.olddir = os.getcwd() |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
67 self.datadir = os.path.join(os.path.dirname(__file__), 'data') |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
68 os.chdir(self.datadir) |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
69 _global_log.threshold = 5 # shut up distutils logging |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
70 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
71 self.dist = Distribution(dict( |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
72 name='TestProject', |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
73 version='0.1', |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
74 packages=['project'] |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
75 )) |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
76 self.cmd = frontend.extract_messages(self.dist) |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
77 self.cmd.initialize_options() |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
78 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
79 def tearDown(self): |
120 | 80 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
81 if os.path.isfile(pot_file): |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
82 os.unlink(pot_file) |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
83 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
84 os.chdir(self.olddir) |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
85 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
86 def test_neither_default_nor_custom_keywords(self): |
120 | 87 self.cmd.output_file = 'dummy' |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
88 self.cmd.no_default_keywords = True |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
89 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
90 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
91 def test_no_output_file_specified(self): |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
92 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
93 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
94 def test_both_sort_output_and_sort_by_file(self): |
120 | 95 self.cmd.output_file = 'dummy' |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
96 self.cmd.sort_output = True |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
97 self.cmd.sort_by_file = True |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
98 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
99 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
100 def test_extraction_with_default_mapping(self): |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
101 self.cmd.copyright_holder = 'FooBar, Inc.' |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
102 self.cmd.msgid_bugs_address = 'bugs.address@email.tld' |
120 | 103 self.cmd.output_file = 'project/i18n/temp.pot' |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
104 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
105 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
106 self.cmd.finalize_options() |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
107 self.cmd.run() |
120 | 108 |
109 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
110 assert os.path.isfile(pot_file) | |
111 | |
112 self.assertEqual( | |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
113 r"""# Translations template for TestProject. |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
114 # Copyright (C) %(year)s FooBar, Inc. |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
115 # This file is distributed under the same license as the TestProject |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
116 # project. |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
117 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
118 # |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
119 #, fuzzy |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
120 msgid "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
121 msgstr "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
122 "Project-Id-Version: TestProject 0.1\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
123 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
124 "POT-Creation-Date: %(date)s\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
125 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
126 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
127 "Language-Team: LANGUAGE <LL@li.org>\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
128 "MIME-Version: 1.0\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
129 "Content-Type: text/plain; charset=utf-8\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
130 "Content-Transfer-Encoding: 8bit\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
131 "Generated-By: Babel %(version)s\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
132 |
346
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
133 #. TRANSLATOR: This will be a translator coment, |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
134 #. that will include several lines |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
135 #: project/file1.py:8 |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
136 msgid "bar" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
137 msgstr "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
138 |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
139 #: project/file2.py:9 |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
140 msgid "foobar" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
141 msgid_plural "foobars" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
142 msgstr[0] "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
143 msgstr[1] "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
144 |
459 | 145 #: project/ignored/this_wont_normally_be_here.py:11 |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
146 msgid "FooBar" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
147 msgid_plural "FooBars" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
148 msgstr[0] "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
149 msgstr[1] "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
150 |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
151 """ % {'version': VERSION, |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
152 'year': time.strftime('%Y'), |
134 | 153 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
154 tzinfo=LOCALTZ, locale='en')}, | |
155 open(pot_file, 'U').read()) | |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
156 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
157 def test_extraction_with_mapping_file(self): |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
158 self.cmd.copyright_holder = 'FooBar, Inc.' |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
159 self.cmd.msgid_bugs_address = 'bugs.address@email.tld' |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
160 self.cmd.mapping_file = 'mapping.cfg' |
120 | 161 self.cmd.output_file = 'project/i18n/temp.pot' |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
162 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
163 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
164 self.cmd.finalize_options() |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
165 self.cmd.run() |
120 | 166 |
167 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
168 assert os.path.isfile(pot_file) | |
169 | |
170 self.assertEqual( | |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
171 r"""# Translations template for TestProject. |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
172 # Copyright (C) %(year)s FooBar, Inc. |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
173 # This file is distributed under the same license as the TestProject |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
174 # project. |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
175 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
176 # |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
177 #, fuzzy |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
178 msgid "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
179 msgstr "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
180 "Project-Id-Version: TestProject 0.1\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
181 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
182 "POT-Creation-Date: %(date)s\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
183 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
184 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
185 "Language-Team: LANGUAGE <LL@li.org>\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
186 "MIME-Version: 1.0\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
187 "Content-Type: text/plain; charset=utf-8\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
188 "Content-Transfer-Encoding: 8bit\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
189 "Generated-By: Babel %(version)s\n" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
190 |
346
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
191 #. TRANSLATOR: This will be a translator coment, |
114
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
192 #. that will include several lines |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
193 #: project/file1.py:8 |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
194 msgid "bar" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
195 msgstr "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
196 |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
197 #: project/file2.py:9 |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
198 msgid "foobar" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
199 msgid_plural "foobars" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
200 msgstr[0] "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
201 msgstr[1] "" |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
202 |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
203 """ % {'version': VERSION, |
5ec3364f250a
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
54
diff
changeset
|
204 'year': time.strftime('%Y'), |
134 | 205 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
206 tzinfo=LOCALTZ, locale='en')}, | |
207 open(pot_file, 'U').read()) | |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
208 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
209 def test_extraction_with_mapping_dict(self): |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
210 self.dist.message_extractors = { |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
211 'project': [ |
459 | 212 ('**/ignored/**.*', 'ignore', None), |
213 ('**.py', 'python', None), | |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
214 ] |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
215 } |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
216 self.cmd.copyright_holder = 'FooBar, Inc.' |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
217 self.cmd.msgid_bugs_address = 'bugs.address@email.tld' |
120 | 218 self.cmd.output_file = 'project/i18n/temp.pot' |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
219 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
220 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
221 self.cmd.finalize_options() |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
222 self.cmd.run() |
120 | 223 |
224 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
225 assert os.path.isfile(pot_file) | |
226 | |
227 self.assertEqual( | |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
228 r"""# Translations template for TestProject. |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
229 # Copyright (C) %(year)s FooBar, Inc. |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
230 # This file is distributed under the same license as the TestProject |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
231 # project. |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
232 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
233 # |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
234 #, fuzzy |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
235 msgid "" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
236 msgstr "" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
237 "Project-Id-Version: TestProject 0.1\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
238 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
239 "POT-Creation-Date: %(date)s\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
240 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
241 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
242 "Language-Team: LANGUAGE <LL@li.org>\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
243 "MIME-Version: 1.0\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
244 "Content-Type: text/plain; charset=utf-8\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
245 "Content-Transfer-Encoding: 8bit\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
246 "Generated-By: Babel %(version)s\n" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
247 |
346
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
248 #. TRANSLATOR: This will be a translator coment, |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
249 #. that will include several lines |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
250 #: project/file1.py:8 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
251 msgid "bar" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
252 msgstr "" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
253 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
254 #: project/file2.py:9 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
255 msgid "foobar" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
256 msgid_plural "foobars" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
257 msgstr[0] "" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
258 msgstr[1] "" |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
259 |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
260 """ % {'version': VERSION, |
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
261 'year': time.strftime('%Y'), |
134 | 262 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
263 tzinfo=LOCALTZ, locale='en')}, | |
264 open(pot_file, 'U').read()) | |
120 | 265 |
266 | |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
267 class InitCatalogTestCase(unittest.TestCase): |
120 | 268 |
269 def setUp(self): | |
270 self.olddir = os.getcwd() | |
271 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | |
272 os.chdir(self.datadir) | |
273 _global_log.threshold = 5 # shut up distutils logging | |
274 | |
275 self.dist = Distribution(dict( | |
276 name='TestProject', | |
277 version='0.1', | |
278 packages=['project'] | |
279 )) | |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
280 self.cmd = frontend.init_catalog(self.dist) |
120 | 281 self.cmd.initialize_options() |
282 | |
283 def tearDown(self): | |
379 | 284 for dirname in ['en_US', 'ja_JP', 'lv_LV']: |
285 locale_dir = os.path.join(self.datadir, 'project', 'i18n', dirname) | |
286 if os.path.isdir(locale_dir): | |
287 shutil.rmtree(locale_dir) | |
120 | 288 |
289 os.chdir(self.olddir) | |
290 | |
291 def test_no_input_file(self): | |
292 self.cmd.locale = 'en_US' | |
293 self.cmd.output_file = 'dummy' | |
294 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
295 | |
296 def test_no_locale(self): | |
297 self.cmd.input_file = 'dummy' | |
298 self.cmd.output_file = 'dummy' | |
299 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
300 | |
121 | 301 def test_with_output_dir(self): |
120 | 302 self.cmd.input_file = 'project/i18n/messages.pot' |
303 self.cmd.locale = 'en_US' | |
304 self.cmd.output_dir = 'project/i18n' | |
305 | |
306 self.cmd.finalize_options() | |
307 self.cmd.run() | |
308 | |
309 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
310 'LC_MESSAGES', 'messages.po') | |
311 assert os.path.isfile(po_file) | |
312 | |
313 self.assertEqual( | |
314 r"""# English (United States) translations for TestProject. | |
315 # Copyright (C) 2007 FooBar, Inc. | |
316 # This file is distributed under the same license as the TestProject | |
317 # project. | |
318 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
319 # | |
320 msgid "" | |
321 msgstr "" | |
322 "Project-Id-Version: TestProject 0.1\n" | |
323 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
324 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
325 "PO-Revision-Date: %(date)s\n" | |
326 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
327 "Language-Team: en_US <LL@li.org>\n" | |
328 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
329 "MIME-Version: 1.0\n" | |
330 "Content-Type: text/plain; charset=utf-8\n" | |
331 "Content-Transfer-Encoding: 8bit\n" | |
332 "Generated-By: Babel %(version)s\n" | |
333 | |
334 #. This will be a translator coment, | |
335 #. that will include several lines | |
336 #: project/file1.py:8 | |
337 msgid "bar" | |
338 msgstr "" | |
339 | |
340 #: project/file2.py:9 | |
341 msgid "foobar" | |
342 msgid_plural "foobars" | |
343 msgstr[0] "" | |
344 msgstr[1] "" | |
345 | |
346 """ % {'version': VERSION, | |
134 | 347 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
348 tzinfo=LOCALTZ, locale='en')}, | |
120 | 349 open(po_file, 'U').read()) |
12
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
350 |
379 | 351 def test_keeps_catalog_non_fuzzy(self): |
176
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
352 self.cmd.input_file = 'project/i18n/messages_non_fuzzy.pot' |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
353 self.cmd.locale = 'en_US' |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
354 self.cmd.output_dir = 'project/i18n' |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
355 |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
356 self.cmd.finalize_options() |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
357 self.cmd.run() |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
358 |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
359 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
360 'LC_MESSAGES', 'messages.po') |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
361 assert os.path.isfile(po_file) |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
362 |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
363 self.assertEqual( |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
364 r"""# English (United States) translations for TestProject. |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
365 # Copyright (C) 2007 FooBar, Inc. |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
366 # This file is distributed under the same license as the TestProject |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
367 # project. |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
368 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
369 # |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
370 msgid "" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
371 msgstr "" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
372 "Project-Id-Version: TestProject 0.1\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
373 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
374 "POT-Creation-Date: 2007-04-01 15:30+0200\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
375 "PO-Revision-Date: %(date)s\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
376 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
377 "Language-Team: en_US <LL@li.org>\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
378 "Plural-Forms: nplurals=2; plural=(n != 1)\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
379 "MIME-Version: 1.0\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
380 "Content-Type: text/plain; charset=utf-8\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
381 "Content-Transfer-Encoding: 8bit\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
382 "Generated-By: Babel %(version)s\n" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
383 |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
384 #. This will be a translator coment, |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
385 #. that will include several lines |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
386 #: project/file1.py:8 |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
387 msgid "bar" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
388 msgstr "" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
389 |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
390 #: project/file2.py:9 |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
391 msgid "foobar" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
392 msgid_plural "foobars" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
393 msgstr[0] "" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
394 msgstr[1] "" |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
395 |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
396 """ % {'version': VERSION, |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
397 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
398 tzinfo=LOCALTZ, locale='en')}, |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
399 open(po_file, 'U').read()) |
115 | 400 |
379 | 401 def test_correct_init_more_than_2_plurals(self): |
402 self.cmd.input_file = 'project/i18n/messages.pot' | |
403 self.cmd.locale = 'lv_LV' | |
404 self.cmd.output_dir = 'project/i18n' | |
405 | |
406 self.cmd.finalize_options() | |
407 self.cmd.run() | |
408 | |
409 po_file = os.path.join(self.datadir, 'project', 'i18n', 'lv_LV', | |
410 'LC_MESSAGES', 'messages.po') | |
411 assert os.path.isfile(po_file) | |
412 | |
413 self.assertEqual( | |
414 r"""# Latvian (Latvia) translations for TestProject. | |
415 # Copyright (C) 2007 FooBar, Inc. | |
416 # This file is distributed under the same license as the TestProject | |
417 # project. | |
418 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
419 # | |
420 msgid "" | |
421 msgstr "" | |
422 "Project-Id-Version: TestProject 0.1\n" | |
423 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
424 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
425 "PO-Revision-Date: %(date)s\n" | |
426 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
427 "Language-Team: lv_LV <LL@li.org>\n" | |
428 "Plural-Forms: nplurals=3; plural=(n%%10==1 && n%%100!=11 ? 0 : n != 0 ? 1 :" | |
429 " 2)\n" | |
430 "MIME-Version: 1.0\n" | |
431 "Content-Type: text/plain; charset=utf-8\n" | |
432 "Content-Transfer-Encoding: 8bit\n" | |
433 "Generated-By: Babel %(version)s\n" | |
434 | |
435 #. This will be a translator coment, | |
436 #. that will include several lines | |
437 #: project/file1.py:8 | |
438 msgid "bar" | |
439 msgstr "" | |
440 | |
441 #: project/file2.py:9 | |
442 msgid "foobar" | |
443 msgid_plural "foobars" | |
444 msgstr[0] "" | |
445 msgstr[1] "" | |
446 msgstr[2] "" | |
447 | |
448 """ % {'version': VERSION, | |
449 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | |
450 tzinfo=LOCALTZ, locale='en')}, | |
451 open(po_file, 'U').read()) | |
452 | |
453 def test_correct_init_singular_plural_forms(self): | |
454 self.cmd.input_file = 'project/i18n/messages.pot' | |
455 self.cmd.locale = 'ja_JP' | |
456 self.cmd.output_dir = 'project/i18n' | |
457 | |
458 self.cmd.finalize_options() | |
459 self.cmd.run() | |
460 | |
461 po_file = os.path.join(self.datadir, 'project', 'i18n', 'ja_JP', | |
462 'LC_MESSAGES', 'messages.po') | |
463 assert os.path.isfile(po_file) | |
464 | |
465 self.assertEqual( | |
466 r"""# Japanese (Japan) translations for TestProject. | |
467 # Copyright (C) 2007 FooBar, Inc. | |
468 # This file is distributed under the same license as the TestProject | |
469 # project. | |
470 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
471 # | |
472 msgid "" | |
473 msgstr "" | |
474 "Project-Id-Version: TestProject 0.1\n" | |
475 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
476 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
477 "PO-Revision-Date: %(date)s\n" | |
478 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
479 "Language-Team: ja_JP <LL@li.org>\n" | |
480 "Plural-Forms: nplurals=1; plural=0\n" | |
481 "MIME-Version: 1.0\n" | |
482 "Content-Type: text/plain; charset=utf-8\n" | |
483 "Content-Transfer-Encoding: 8bit\n" | |
484 "Generated-By: Babel %(version)s\n" | |
485 | |
486 #. This will be a translator coment, | |
487 #. that will include several lines | |
488 #: project/file1.py:8 | |
489 msgid "bar" | |
490 msgstr "" | |
491 | |
492 #: project/file2.py:9 | |
493 msgid "foobar" | |
494 msgid_plural "foobars" | |
495 msgstr[0] "" | |
496 | |
497 """ % {'version': VERSION, | |
498 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | |
499 tzinfo=LOCALTZ, locale='ja_JP')}, | |
500 open(po_file, 'U').read()) | |
501 | |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
502 |
127 | 503 class CommandLineInterfaceTestCase(unittest.TestCase): |
504 | |
505 def setUp(self): | |
506 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | |
128 | 507 self.orig_argv = sys.argv |
127 | 508 self.orig_stdout = sys.stdout |
509 self.orig_stderr = sys.stderr | |
232 | 510 sys.argv = ['pybabel'] |
127 | 511 sys.stdout = StringIO() |
512 sys.stderr = StringIO() | |
524 | 513 |
514 # Logging handlers will be reused if possible (#227). This breaks the | |
515 # implicit assumption that our newly created StringIO for sys.stderr | |
516 # contains the console output. Removing the old handler ensures that a | |
517 # new handler with our new StringIO instance will be used. | |
518 log = logging.getLogger('babel') | |
519 for handler in log.handlers: | |
520 log.removeHandler(handler) | |
127 | 521 self.cli = frontend.CommandLineInterface() |
522 | |
523 def tearDown(self): | |
128 | 524 sys.argv = self.orig_argv |
127 | 525 sys.stdout = self.orig_stdout |
526 sys.stderr = self.orig_stderr | |
379 | 527 for dirname in ['lv_LV', 'ja_JP']: |
528 locale_dir = os.path.join(self.datadir, 'project', 'i18n', dirname) | |
529 if os.path.isdir(locale_dir): | |
530 shutil.rmtree(locale_dir) | |
127 | 531 |
532 def test_usage(self): | |
533 try: | |
128 | 534 self.cli.run(sys.argv) |
127 | 535 self.fail('Expected SystemExit') |
536 except SystemExit, e: | |
508
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
537 stderr = sys.stderr.getvalue() |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
538 if isinstance(e.code, int): |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
539 self.assertEqual(2, e.code) |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
540 else: |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
541 # OptionParser in Python 2.3 does not set the exit code. |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
542 # Instead the 'code' contains the custom error message from the |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
543 # frontend |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
544 stderr = stderr + e.code + '\n' |
127 | 545 self.assertEqual("""\ |
232 | 546 usage: pybabel command [options] [args] |
127 | 547 |
474 | 548 pybabel: error: no valid command or option passed. try the -h/--help option for more information. |
508
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
474
diff
changeset
|
549 """, stderr.lower()) |
127 | 550 |
551 def test_help(self): | |
552 try: | |
128 | 553 self.cli.run(sys.argv + ['--help']) |
127 | 554 self.fail('Expected SystemExit') |
555 except SystemExit, e: | |
556 self.assertEqual(0, e.code) | |
557 self.assertEqual("""\ | |
232 | 558 usage: pybabel command [options] [args] |
127 | 559 |
560 options: | |
185
170cffc66554
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
561 --version show program's version number and exit |
170cffc66554
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
562 -h, --help show this help message and exit |
170cffc66554
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
563 --list-locales print all known locales and exit |
232 | 564 -v, --verbose print as much as possible |
565 -q, --quiet print as little as possible | |
127 | 566 |
567 commands: | |
185
170cffc66554
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
568 compile compile message catalogs to mo files |
170cffc66554
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
569 extract extract messages from source files and generate a pot file |
170cffc66554
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
570 init create new message catalogs from a pot file |
170cffc66554
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
571 update update existing message catalogs from a pot file |
135
f22177653f86
Fix frontend tests on Python 2.5, where the case of some of the output of optparse usage has changed.
cmlenz
parents:
134
diff
changeset
|
572 """, sys.stdout.getvalue().lower()) |
127 | 573 |
574 def test_extract_with_default_mapping(self): | |
575 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
576 try: | |
128 | 577 self.cli.run(sys.argv + ['extract', |
127 | 578 '--copyright-holder', 'FooBar, Inc.', |
579 '--msgid-bugs-address', 'bugs.address@email.tld', | |
580 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | |
581 '-o', pot_file, os.path.join(self.datadir, 'project')]) | |
582 except SystemExit, e: | |
583 self.assertEqual(0, e.code) | |
584 assert os.path.isfile(pot_file) | |
585 self.assertEqual( | |
586 r"""# Translations template for TestProject. | |
587 # Copyright (C) %(year)s FooBar, Inc. | |
588 # This file is distributed under the same license as the TestProject | |
589 # project. | |
590 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
591 # | |
592 #, fuzzy | |
593 msgid "" | |
594 msgstr "" | |
595 "Project-Id-Version: TestProject 0.1\n" | |
596 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
597 "POT-Creation-Date: %(date)s\n" | |
598 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
599 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
600 "Language-Team: LANGUAGE <LL@li.org>\n" | |
601 "MIME-Version: 1.0\n" | |
602 "Content-Type: text/plain; charset=utf-8\n" | |
603 "Content-Transfer-Encoding: 8bit\n" | |
604 "Generated-By: Babel %(version)s\n" | |
605 | |
606 #. This will be a translator coment, | |
607 #. that will include several lines | |
608 #: project/file1.py:8 | |
609 msgid "bar" | |
610 msgstr "" | |
611 | |
612 #: project/file2.py:9 | |
613 msgid "foobar" | |
614 msgid_plural "foobars" | |
615 msgstr[0] "" | |
616 msgstr[1] "" | |
617 | |
459 | 618 #: project/ignored/this_wont_normally_be_here.py:11 |
127 | 619 msgid "FooBar" |
620 msgid_plural "FooBars" | |
621 msgstr[0] "" | |
622 msgstr[1] "" | |
623 | |
624 """ % {'version': VERSION, | |
625 'year': time.strftime('%Y'), | |
134 | 626 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
627 tzinfo=LOCALTZ, locale='en')}, | |
628 open(pot_file, 'U').read()) | |
127 | 629 |
630 def test_extract_with_mapping_file(self): | |
631 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
632 try: | |
128 | 633 self.cli.run(sys.argv + ['extract', |
127 | 634 '--copyright-holder', 'FooBar, Inc.', |
635 '--msgid-bugs-address', 'bugs.address@email.tld', | |
636 '--mapping', os.path.join(self.datadir, 'mapping.cfg'), | |
637 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | |
638 '-o', pot_file, os.path.join(self.datadir, 'project')]) | |
639 except SystemExit, e: | |
640 self.assertEqual(0, e.code) | |
641 assert os.path.isfile(pot_file) | |
642 self.assertEqual( | |
643 r"""# Translations template for TestProject. | |
644 # Copyright (C) %(year)s FooBar, Inc. | |
645 # This file is distributed under the same license as the TestProject | |
646 # project. | |
647 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
648 # | |
649 #, fuzzy | |
650 msgid "" | |
651 msgstr "" | |
652 "Project-Id-Version: TestProject 0.1\n" | |
653 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
654 "POT-Creation-Date: %(date)s\n" | |
655 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
656 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
657 "Language-Team: LANGUAGE <LL@li.org>\n" | |
658 "MIME-Version: 1.0\n" | |
659 "Content-Type: text/plain; charset=utf-8\n" | |
660 "Content-Transfer-Encoding: 8bit\n" | |
661 "Generated-By: Babel %(version)s\n" | |
662 | |
663 #. This will be a translator coment, | |
664 #. that will include several lines | |
665 #: project/file1.py:8 | |
666 msgid "bar" | |
667 msgstr "" | |
668 | |
669 #: project/file2.py:9 | |
670 msgid "foobar" | |
671 msgid_plural "foobars" | |
672 msgstr[0] "" | |
673 msgstr[1] "" | |
674 | |
675 """ % {'version': VERSION, | |
676 'year': time.strftime('%Y'), | |
134 | 677 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
678 tzinfo=LOCALTZ, locale='en')}, | |
679 open(pot_file, 'U').read()) | |
127 | 680 |
681 def test_init_with_output_dir(self): | |
682 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
683 'LC_MESSAGES', 'messages.po') | |
684 try: | |
128 | 685 self.cli.run(sys.argv + ['init', |
127 | 686 '--locale', 'en_US', |
687 '-d', os.path.join(self.datadir, 'project', 'i18n'), | |
688 '-i', os.path.join(self.datadir, 'project', 'i18n', | |
689 'messages.pot')]) | |
690 except SystemExit, e: | |
691 self.assertEqual(0, e.code) | |
171 | 692 assert os.path.isfile(po_file) |
127 | 693 self.assertEqual( |
694 r"""# English (United States) translations for TestProject. | |
695 # Copyright (C) 2007 FooBar, Inc. | |
696 # This file is distributed under the same license as the TestProject | |
697 # project. | |
698 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
699 # | |
700 #, fuzzy | |
701 msgid "" | |
702 msgstr "" | |
703 "Project-Id-Version: TestProject 0.1\n" | |
704 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
705 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
706 "PO-Revision-Date: %(date)s\n" | |
707 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
708 "Language-Team: en_US <LL@li.org>\n" | |
709 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
710 "MIME-Version: 1.0\n" | |
711 "Content-Type: text/plain; charset=utf-8\n" | |
712 "Content-Transfer-Encoding: 8bit\n" | |
713 "Generated-By: Babel %(version)s\n" | |
714 | |
715 #. This will be a translator coment, | |
716 #. that will include several lines | |
717 #: project/file1.py:8 | |
718 msgid "bar" | |
719 msgstr "" | |
720 | |
721 #: project/file2.py:9 | |
722 msgid "foobar" | |
723 msgid_plural "foobars" | |
724 msgstr[0] "" | |
725 msgstr[1] "" | |
726 | |
727 """ % {'version': VERSION, | |
134 | 728 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
729 tzinfo=LOCALTZ, locale='en')}, | |
127 | 730 open(po_file, 'U').read()) |
379 | 731 |
732 def test_init_singular_plural_forms(self): | |
733 po_file = os.path.join(self.datadir, 'project', 'i18n', 'ja_JP', | |
734 'LC_MESSAGES', 'messages.po') | |
735 try: | |
736 self.cli.run(sys.argv + ['init', | |
737 '--locale', 'ja_JP', | |
738 '-d', os.path.join(self.datadir, 'project', 'i18n'), | |
739 '-i', os.path.join(self.datadir, 'project', 'i18n', | |
740 'messages.pot')]) | |
741 except SystemExit, e: | |
742 self.assertEqual(0, e.code) | |
743 assert os.path.isfile(po_file) | |
744 self.assertEqual( | |
745 r"""# Japanese (Japan) translations for TestProject. | |
746 # Copyright (C) 2007 FooBar, Inc. | |
747 # This file is distributed under the same license as the TestProject | |
748 # project. | |
749 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
750 # | |
751 #, fuzzy | |
752 msgid "" | |
753 msgstr "" | |
754 "Project-Id-Version: TestProject 0.1\n" | |
755 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
756 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
757 "PO-Revision-Date: %(date)s\n" | |
758 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
759 "Language-Team: ja_JP <LL@li.org>\n" | |
760 "Plural-Forms: nplurals=1; plural=0\n" | |
761 "MIME-Version: 1.0\n" | |
762 "Content-Type: text/plain; charset=utf-8\n" | |
763 "Content-Transfer-Encoding: 8bit\n" | |
764 "Generated-By: Babel %(version)s\n" | |
765 | |
766 #. This will be a translator coment, | |
767 #. that will include several lines | |
768 #: project/file1.py:8 | |
769 msgid "bar" | |
770 msgstr "" | |
771 | |
772 #: project/file2.py:9 | |
773 msgid "foobar" | |
774 msgid_plural "foobars" | |
775 msgstr[0] "" | |
776 | |
777 """ % {'version': VERSION, | |
778 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | |
779 tzinfo=LOCALTZ, locale='en')}, | |
780 open(po_file, 'U').read()) | |
781 | |
782 def test_init_more_than_2_plural_forms(self): | |
783 po_file = os.path.join(self.datadir, 'project', 'i18n', 'lv_LV', | |
784 'LC_MESSAGES', 'messages.po') | |
785 try: | |
786 self.cli.run(sys.argv + ['init', | |
787 '--locale', 'lv_LV', | |
788 '-d', os.path.join(self.datadir, 'project', 'i18n'), | |
789 '-i', os.path.join(self.datadir, 'project', 'i18n', | |
790 'messages.pot')]) | |
791 except SystemExit, e: | |
792 self.assertEqual(0, e.code) | |
793 assert os.path.isfile(po_file) | |
794 self.assertEqual( | |
795 r"""# Latvian (Latvia) translations for TestProject. | |
796 # Copyright (C) 2007 FooBar, Inc. | |
797 # This file is distributed under the same license as the TestProject | |
798 # project. | |
799 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
800 # | |
801 #, fuzzy | |
802 msgid "" | |
803 msgstr "" | |
804 "Project-Id-Version: TestProject 0.1\n" | |
805 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
806 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
807 "PO-Revision-Date: %(date)s\n" | |
808 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
809 "Language-Team: lv_LV <LL@li.org>\n" | |
810 "Plural-Forms: nplurals=3; plural=(n%%10==1 && n%%100!=11 ? 0 : n != 0 ? 1 :" | |
811 " 2)\n" | |
812 "MIME-Version: 1.0\n" | |
813 "Content-Type: text/plain; charset=utf-8\n" | |
814 "Content-Transfer-Encoding: 8bit\n" | |
815 "Generated-By: Babel %(version)s\n" | |
816 | |
817 #. This will be a translator coment, | |
818 #. that will include several lines | |
819 #: project/file1.py:8 | |
820 msgid "bar" | |
821 msgstr "" | |
822 | |
823 #: project/file2.py:9 | |
824 msgid "foobar" | |
825 msgid_plural "foobars" | |
826 msgstr[0] "" | |
827 msgstr[1] "" | |
828 msgstr[2] "" | |
829 | |
830 """ % {'version': VERSION, | |
831 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | |
832 tzinfo=LOCALTZ, locale='en')}, | |
833 open(po_file, 'U').read()) | |
177
a7766f92f944
* Instead of an extra `compile-all` option on the `compile` (or `compile_catalog`) command, compilation of all catalogs is performed when neither an `input_file` nor a `locale` is specified.
cmlenz
parents:
176
diff
changeset
|
834 |
176
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
835 def test_compile_catalog(self): |
232 | 836 po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE', |
176
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
837 'LC_MESSAGES', 'messages.po') |
232 | 838 mo_file = po_file.replace('.po', '.mo') |
839 self.cli.run(sys.argv + ['compile', | |
840 '--locale', 'de_DE', | |
841 '-d', os.path.join(self.datadir, 'project', 'i18n')]) | |
842 assert not os.path.isfile(mo_file), 'Expected no file at %r' % mo_file | |
843 self.assertEqual("""\ | |
844 catalog %r is marked as fuzzy, skipping | |
845 """ % (po_file), sys.stderr.getvalue()) | |
846 | |
847 def test_compile_fuzzy_catalog(self): | |
848 po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE', | |
849 'LC_MESSAGES', 'messages.po') | |
850 mo_file = po_file.replace('.po', '.mo') | |
176
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
851 try: |
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
852 self.cli.run(sys.argv + ['compile', |
232 | 853 '--locale', 'de_DE', '--use-fuzzy', |
176
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
854 '-d', os.path.join(self.datadir, 'project', 'i18n')]) |
232 | 855 assert os.path.isfile(mo_file) |
176
c31a7948bb8e
Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents:
171
diff
changeset
|
856 self.assertEqual("""\ |
177
a7766f92f944
* Instead of an extra `compile-all` option on the `compile` (or `compile_catalog`) command, compilation of all catalogs is performed when neither an `input_file` nor a `locale` is specified.
cmlenz
parents:
176
diff
changeset
|
857 compiling catalog %r to %r |
232 | 858 """ % (po_file, mo_file), sys.stderr.getvalue()) |
859 finally: | |
860 if os.path.isfile(mo_file): | |
861 os.unlink(mo_file) | |
127 | 862 |
346
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
863 def test_compile_catalog_with_more_than_2_plural_forms(self): |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
864 po_file = os.path.join(self.datadir, 'project', 'i18n', 'ru_RU', |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
865 'LC_MESSAGES', 'messages.po') |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
866 mo_file = po_file.replace('.po', '.mo') |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
867 try: |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
868 self.cli.run(sys.argv + ['compile', |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
869 '--locale', 'ru_RU', '--use-fuzzy', |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
870 '-d', os.path.join(self.datadir, 'project', 'i18n')]) |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
871 assert os.path.isfile(mo_file) |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
872 self.assertEqual("""\ |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
873 compiling catalog %r to %r |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
874 """ % (po_file, mo_file), sys.stderr.getvalue()) |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
875 finally: |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
876 if os.path.isfile(mo_file): |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
877 os.unlink(mo_file) |
faf0ead3a132
Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents:
251
diff
changeset
|
878 |
177
a7766f92f944
* Instead of an extra `compile-all` option on the `compile` (or `compile_catalog`) command, compilation of all catalogs is performed when neither an `input_file` nor a `locale` is specified.
cmlenz
parents:
176
diff
changeset
|
879 |
12
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
880 def suite(): |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
881 suite = unittest.TestSuite() |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
882 suite.addTest(doctest.DocTestSuite(frontend)) |
160 | 883 suite.addTest(unittest.makeSuite(CompileCatalogTestCase)) |
117
41506e62701f
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
115
diff
changeset
|
884 suite.addTest(unittest.makeSuite(ExtractMessagesTestCase)) |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
885 suite.addTest(unittest.makeSuite(InitCatalogTestCase)) |
127 | 886 suite.addTest(unittest.makeSuite(CommandLineInterfaceTestCase)) |
12
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
887 return suite |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
888 |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
889 if __name__ == '__main__': |
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
890 unittest.main(defaultTest='suite') |