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