Mercurial > babel > old > mirror
annotate babel/messages/tests/frontend.py @ 234:541b6d630575
Use logging module for output from CLI frontend.
author | cmlenz |
---|---|
date | Mon, 30 Jul 2007 20:28:43 +0000 |
parents | d3bde66ac8a9 |
children | 72351fd5fc29 |
rev | line source |
---|---|
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
2 # |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
3 # Copyright (C) 2007 Edgewall Software |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
5 # |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://babel.edgewall.org/wiki/License. |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
9 # |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://babel.edgewall.org/log/. |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
13 |
136 | 14 from datetime import datetime |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
15 from distutils.dist import Distribution |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
16 from distutils.errors import DistutilsOptionError, DistutilsSetupError |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
17 from distutils.log import _global_log |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
18 import doctest |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
19 import os |
122 | 20 import shutil |
129 | 21 from StringIO import StringIO |
22 import sys | |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
23 import time |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
24 import unittest |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
25 |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
26 from babel import __version__ as VERSION |
136 | 27 from babel.dates import format_datetime |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
28 from babel.messages import frontend |
136 | 29 from babel.util import LOCALTZ |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
30 |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
31 |
162 | 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 | |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
62 class ExtractMessagesTestCase(unittest.TestCase): |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
63 |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
64 def setUp(self): |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
65 self.olddir = os.getcwd() |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
66 self.datadir = os.path.join(os.path.dirname(__file__), 'data') |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
67 os.chdir(self.datadir) |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
68 _global_log.threshold = 5 # shut up distutils logging |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
69 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
70 self.dist = Distribution(dict( |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
71 name='TestProject', |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
72 version='0.1', |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
73 packages=['project'] |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
74 )) |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
75 self.cmd = frontend.extract_messages(self.dist) |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
76 self.cmd.initialize_options() |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
77 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
78 def tearDown(self): |
122 | 79 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
80 if os.path.isfile(pot_file): |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
81 os.unlink(pot_file) |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
82 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
83 os.chdir(self.olddir) |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
84 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
85 def test_neither_default_nor_custom_keywords(self): |
122 | 86 self.cmd.output_file = 'dummy' |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
87 self.cmd.no_default_keywords = True |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
88 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
89 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
90 def test_no_output_file_specified(self): |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
91 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
92 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
93 def test_both_sort_output_and_sort_by_file(self): |
122 | 94 self.cmd.output_file = 'dummy' |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
95 self.cmd.sort_output = True |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
96 self.cmd.sort_by_file = True |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
97 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
98 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
99 def test_extraction_with_default_mapping(self): |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
100 self.cmd.copyright_holder = 'FooBar, Inc.' |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
101 self.cmd.msgid_bugs_address = 'bugs.address@email.tld' |
122 | 102 self.cmd.output_file = 'project/i18n/temp.pot' |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
103 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
104 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
105 self.cmd.finalize_options() |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
106 self.cmd.run() |
122 | 107 |
108 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
109 assert os.path.isfile(pot_file) | |
110 | |
111 self.assertEqual( | |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
112 r"""# Translations template for TestProject. |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
113 # Copyright (C) %(year)s FooBar, Inc. |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
114 # This file is distributed under the same license as the TestProject |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
115 # project. |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
116 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
117 # |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
118 #, fuzzy |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
119 msgid "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
120 msgstr "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
121 "Project-Id-Version: TestProject 0.1\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
122 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
123 "POT-Creation-Date: %(date)s\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
124 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
125 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
126 "Language-Team: LANGUAGE <LL@li.org>\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
127 "MIME-Version: 1.0\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
128 "Content-Type: text/plain; charset=utf-8\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
129 "Content-Transfer-Encoding: 8bit\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
130 "Generated-By: Babel %(version)s\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
131 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
132 #. This will be a translator coment, |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
133 #. that will include several lines |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
134 #: project/file1.py:8 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
135 msgid "bar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
136 msgstr "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
137 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
138 #: project/file2.py:9 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
139 msgid "foobar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
140 msgid_plural "foobars" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
141 msgstr[0] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
142 msgstr[1] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
143 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
144 #: project/CVS/this_wont_normally_be_here.py:11 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
145 msgid "FooBar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
146 msgid_plural "FooBars" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
147 msgstr[0] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
148 msgstr[1] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
149 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
150 """ % {'version': VERSION, |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
151 'year': time.strftime('%Y'), |
136 | 152 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
153 tzinfo=LOCALTZ, locale='en')}, | |
154 open(pot_file, 'U').read()) | |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
155 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
156 def test_extraction_with_mapping_file(self): |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
157 self.cmd.copyright_holder = 'FooBar, Inc.' |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
158 self.cmd.msgid_bugs_address = 'bugs.address@email.tld' |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
159 self.cmd.mapping_file = 'mapping.cfg' |
122 | 160 self.cmd.output_file = 'project/i18n/temp.pot' |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
161 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
162 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
163 self.cmd.finalize_options() |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
164 self.cmd.run() |
122 | 165 |
166 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
167 assert os.path.isfile(pot_file) | |
168 | |
169 self.assertEqual( | |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
170 r"""# Translations template for TestProject. |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
171 # Copyright (C) %(year)s FooBar, Inc. |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
172 # This file is distributed under the same license as the TestProject |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
173 # project. |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
174 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
175 # |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
176 #, fuzzy |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
177 msgid "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
178 msgstr "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
179 "Project-Id-Version: TestProject 0.1\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
180 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
181 "POT-Creation-Date: %(date)s\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
182 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
183 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
184 "Language-Team: LANGUAGE <LL@li.org>\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
185 "MIME-Version: 1.0\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
186 "Content-Type: text/plain; charset=utf-8\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
187 "Content-Transfer-Encoding: 8bit\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
188 "Generated-By: Babel %(version)s\n" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
189 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
190 #. This will be a translator coment, |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
191 #. that will include several lines |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
192 #: project/file1.py:8 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
193 msgid "bar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
194 msgstr "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
195 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
196 #: project/file2.py:9 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
197 msgid "foobar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
198 msgid_plural "foobars" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
199 msgstr[0] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
200 msgstr[1] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
201 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
202 """ % {'version': VERSION, |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
203 'year': time.strftime('%Y'), |
136 | 204 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
205 tzinfo=LOCALTZ, locale='en')}, | |
206 open(pot_file, 'U').read()) | |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
207 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
208 def test_extraction_with_mapping_dict(self): |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
209 self.dist.message_extractors = { |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
210 'project': [ |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
211 ('**/CVS/**.*', 'ignore', None), |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
212 ('**.py', 'python', None), |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
213 ] |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
214 } |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
215 self.cmd.copyright_holder = 'FooBar, Inc.' |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
216 self.cmd.msgid_bugs_address = 'bugs.address@email.tld' |
122 | 217 self.cmd.output_file = 'project/i18n/temp.pot' |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
218 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
219 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
220 self.cmd.finalize_options() |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
221 self.cmd.run() |
122 | 222 |
223 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
224 assert os.path.isfile(pot_file) | |
225 | |
226 self.assertEqual( | |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
227 r"""# Translations template for TestProject. |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
228 # Copyright (C) %(year)s FooBar, Inc. |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
229 # This file is distributed under the same license as the TestProject |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
230 # project. |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
231 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
232 # |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
233 #, fuzzy |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
234 msgid "" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
235 msgstr "" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
236 "Project-Id-Version: TestProject 0.1\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
237 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
238 "POT-Creation-Date: %(date)s\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
239 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
240 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
241 "Language-Team: LANGUAGE <LL@li.org>\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
242 "MIME-Version: 1.0\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
243 "Content-Type: text/plain; charset=utf-8\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
244 "Content-Transfer-Encoding: 8bit\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
245 "Generated-By: Babel %(version)s\n" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
246 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
247 #. This will be a translator coment, |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
248 #. that will include several lines |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
249 #: project/file1.py:8 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
250 msgid "bar" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
251 msgstr "" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
252 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
253 #: project/file2.py:9 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
254 msgid "foobar" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
255 msgid_plural "foobars" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
256 msgstr[0] "" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
257 msgstr[1] "" |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
258 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
259 """ % {'version': VERSION, |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
260 'year': time.strftime('%Y'), |
136 | 261 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
262 tzinfo=LOCALTZ, locale='en')}, | |
263 open(pot_file, 'U').read()) | |
122 | 264 |
265 | |
183
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
266 class InitCatalogTestCase(unittest.TestCase): |
122 | 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 )) | |
183
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
279 self.cmd = frontend.init_catalog(self.dist) |
122 | 280 self.cmd.initialize_options() |
281 | |
282 def tearDown(self): | |
283 locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US') | |
284 if os.path.isdir(locale_dir): | |
285 shutil.rmtree(locale_dir) | |
286 | |
287 os.chdir(self.olddir) | |
288 | |
289 def test_no_input_file(self): | |
290 self.cmd.locale = 'en_US' | |
291 self.cmd.output_file = 'dummy' | |
292 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
293 | |
294 def test_no_locale(self): | |
295 self.cmd.input_file = 'dummy' | |
296 self.cmd.output_file = 'dummy' | |
297 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
298 | |
123 | 299 def test_with_output_dir(self): |
122 | 300 self.cmd.input_file = 'project/i18n/messages.pot' |
301 self.cmd.locale = 'en_US' | |
302 self.cmd.output_dir = 'project/i18n' | |
303 | |
304 self.cmd.finalize_options() | |
305 self.cmd.run() | |
306 | |
307 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
308 'LC_MESSAGES', 'messages.po') | |
309 assert os.path.isfile(po_file) | |
310 | |
311 self.assertEqual( | |
312 r"""# English (United States) translations for TestProject. | |
313 # Copyright (C) 2007 FooBar, Inc. | |
314 # This file is distributed under the same license as the TestProject | |
315 # project. | |
316 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
317 # | |
318 #, fuzzy | |
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, | |
136 | 346 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
347 tzinfo=LOCALTZ, locale='en')}, | |
122 | 348 open(po_file, 'U').read()) |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
349 |
183
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
350 |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
351 class InitCatalogNonFuzzyTestCase(unittest.TestCase): |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
352 # FIXME: what is this test case about? |
178
51fffa0a51ac
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:
173
diff
changeset
|
353 |
51fffa0a51ac
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:
173
diff
changeset
|
354 def setUp(self): |
51fffa0a51ac
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:
173
diff
changeset
|
355 self.olddir = os.getcwd() |
51fffa0a51ac
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:
173
diff
changeset
|
356 self.datadir = os.path.join(os.path.dirname(__file__), 'data') |
51fffa0a51ac
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:
173
diff
changeset
|
357 os.chdir(self.datadir) |
51fffa0a51ac
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:
173
diff
changeset
|
358 _global_log.threshold = 5 # shut up distutils logging |
51fffa0a51ac
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:
173
diff
changeset
|
359 |
51fffa0a51ac
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:
173
diff
changeset
|
360 self.dist = Distribution(dict( |
51fffa0a51ac
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:
173
diff
changeset
|
361 name='TestProject', |
51fffa0a51ac
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:
173
diff
changeset
|
362 version='0.1', |
51fffa0a51ac
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:
173
diff
changeset
|
363 packages=['project'] |
51fffa0a51ac
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:
173
diff
changeset
|
364 )) |
183
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
365 self.cmd = frontend.init_catalog(self.dist) |
178
51fffa0a51ac
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:
173
diff
changeset
|
366 self.cmd.initialize_options() |
51fffa0a51ac
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:
173
diff
changeset
|
367 |
51fffa0a51ac
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:
173
diff
changeset
|
368 def tearDown(self): |
51fffa0a51ac
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:
173
diff
changeset
|
369 locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US') |
51fffa0a51ac
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:
173
diff
changeset
|
370 if os.path.isdir(locale_dir): |
51fffa0a51ac
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:
173
diff
changeset
|
371 shutil.rmtree(locale_dir) |
51fffa0a51ac
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:
173
diff
changeset
|
372 |
51fffa0a51ac
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:
173
diff
changeset
|
373 os.chdir(self.olddir) |
51fffa0a51ac
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:
173
diff
changeset
|
374 |
51fffa0a51ac
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:
173
diff
changeset
|
375 def test_with_output_dir(self): |
51fffa0a51ac
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:
173
diff
changeset
|
376 self.cmd.input_file = 'project/i18n/messages_non_fuzzy.pot' |
51fffa0a51ac
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:
173
diff
changeset
|
377 self.cmd.locale = 'en_US' |
51fffa0a51ac
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:
173
diff
changeset
|
378 self.cmd.output_dir = 'project/i18n' |
51fffa0a51ac
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:
173
diff
changeset
|
379 |
51fffa0a51ac
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:
173
diff
changeset
|
380 self.cmd.finalize_options() |
51fffa0a51ac
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:
173
diff
changeset
|
381 self.cmd.run() |
51fffa0a51ac
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:
173
diff
changeset
|
382 |
51fffa0a51ac
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:
173
diff
changeset
|
383 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', |
51fffa0a51ac
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:
173
diff
changeset
|
384 'LC_MESSAGES', 'messages.po') |
51fffa0a51ac
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:
173
diff
changeset
|
385 assert os.path.isfile(po_file) |
51fffa0a51ac
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:
173
diff
changeset
|
386 |
51fffa0a51ac
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:
173
diff
changeset
|
387 self.assertEqual( |
51fffa0a51ac
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:
173
diff
changeset
|
388 r"""# English (United States) translations for TestProject. |
51fffa0a51ac
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:
173
diff
changeset
|
389 # Copyright (C) 2007 FooBar, Inc. |
51fffa0a51ac
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:
173
diff
changeset
|
390 # This file is distributed under the same license as the TestProject |
51fffa0a51ac
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:
173
diff
changeset
|
391 # project. |
51fffa0a51ac
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:
173
diff
changeset
|
392 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
51fffa0a51ac
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:
173
diff
changeset
|
393 # |
51fffa0a51ac
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:
173
diff
changeset
|
394 msgid "" |
51fffa0a51ac
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:
173
diff
changeset
|
395 msgstr "" |
51fffa0a51ac
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:
173
diff
changeset
|
396 "Project-Id-Version: TestProject 0.1\n" |
51fffa0a51ac
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:
173
diff
changeset
|
397 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" |
51fffa0a51ac
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:
173
diff
changeset
|
398 "POT-Creation-Date: 2007-04-01 15:30+0200\n" |
51fffa0a51ac
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:
173
diff
changeset
|
399 "PO-Revision-Date: %(date)s\n" |
51fffa0a51ac
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:
173
diff
changeset
|
400 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
51fffa0a51ac
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:
173
diff
changeset
|
401 "Language-Team: en_US <LL@li.org>\n" |
51fffa0a51ac
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:
173
diff
changeset
|
402 "Plural-Forms: nplurals=2; plural=(n != 1)\n" |
51fffa0a51ac
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:
173
diff
changeset
|
403 "MIME-Version: 1.0\n" |
51fffa0a51ac
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:
173
diff
changeset
|
404 "Content-Type: text/plain; charset=utf-8\n" |
51fffa0a51ac
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:
173
diff
changeset
|
405 "Content-Transfer-Encoding: 8bit\n" |
51fffa0a51ac
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:
173
diff
changeset
|
406 "Generated-By: Babel %(version)s\n" |
51fffa0a51ac
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:
173
diff
changeset
|
407 |
51fffa0a51ac
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:
173
diff
changeset
|
408 #. This will be a translator coment, |
51fffa0a51ac
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:
173
diff
changeset
|
409 #. that will include several lines |
51fffa0a51ac
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:
173
diff
changeset
|
410 #: project/file1.py:8 |
51fffa0a51ac
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:
173
diff
changeset
|
411 msgid "bar" |
51fffa0a51ac
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:
173
diff
changeset
|
412 msgstr "" |
51fffa0a51ac
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:
173
diff
changeset
|
413 |
51fffa0a51ac
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:
173
diff
changeset
|
414 #: project/file2.py:9 |
51fffa0a51ac
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:
173
diff
changeset
|
415 msgid "foobar" |
51fffa0a51ac
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:
173
diff
changeset
|
416 msgid_plural "foobars" |
51fffa0a51ac
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:
173
diff
changeset
|
417 msgstr[0] "" |
51fffa0a51ac
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:
173
diff
changeset
|
418 msgstr[1] "" |
51fffa0a51ac
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:
173
diff
changeset
|
419 |
51fffa0a51ac
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:
173
diff
changeset
|
420 """ % {'version': VERSION, |
51fffa0a51ac
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:
173
diff
changeset
|
421 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
51fffa0a51ac
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:
173
diff
changeset
|
422 tzinfo=LOCALTZ, locale='en')}, |
51fffa0a51ac
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:
173
diff
changeset
|
423 open(po_file, 'U').read()) |
117 | 424 |
183
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
425 |
129 | 426 class CommandLineInterfaceTestCase(unittest.TestCase): |
427 | |
428 def setUp(self): | |
429 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | |
130 | 430 self.orig_argv = sys.argv |
129 | 431 self.orig_stdout = sys.stdout |
432 self.orig_stderr = sys.stderr | |
234 | 433 sys.argv = ['pybabel'] |
129 | 434 sys.stdout = StringIO() |
435 sys.stderr = StringIO() | |
436 self.cli = frontend.CommandLineInterface() | |
437 | |
438 def tearDown(self): | |
130 | 439 sys.argv = self.orig_argv |
129 | 440 sys.stdout = self.orig_stdout |
441 sys.stderr = self.orig_stderr | |
442 | |
443 def test_usage(self): | |
444 try: | |
130 | 445 self.cli.run(sys.argv) |
129 | 446 self.fail('Expected SystemExit') |
447 except SystemExit, e: | |
448 self.assertEqual(2, e.code) | |
449 self.assertEqual("""\ | |
234 | 450 usage: pybabel command [options] [args] |
129 | 451 |
234 | 452 pybabel: error: incorrect number of arguments |
137
ade36d5897f4
Fix frontend tests on Python 2.5, where the case of some of the output of optparse usage has changed.
cmlenz
parents:
136
diff
changeset
|
453 """, sys.stderr.getvalue().lower()) |
129 | 454 |
455 def test_help(self): | |
456 try: | |
130 | 457 self.cli.run(sys.argv + ['--help']) |
129 | 458 self.fail('Expected SystemExit') |
459 except SystemExit, e: | |
460 self.assertEqual(0, e.code) | |
461 self.assertEqual("""\ | |
234 | 462 usage: pybabel command [options] [args] |
129 | 463 |
464 options: | |
187
d3bde66ac8a9
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
183
diff
changeset
|
465 --version show program's version number and exit |
d3bde66ac8a9
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
183
diff
changeset
|
466 -h, --help show this help message and exit |
d3bde66ac8a9
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
183
diff
changeset
|
467 --list-locales print all known locales and exit |
234 | 468 -v, --verbose print as much as possible |
469 -q, --quiet print as little as possible | |
129 | 470 |
471 commands: | |
187
d3bde66ac8a9
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
183
diff
changeset
|
472 compile compile message catalogs to mo files |
d3bde66ac8a9
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
183
diff
changeset
|
473 extract extract messages from source files and generate a pot file |
d3bde66ac8a9
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
183
diff
changeset
|
474 init create new message catalogs from a pot file |
d3bde66ac8a9
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
183
diff
changeset
|
475 update update existing message catalogs from a pot file |
137
ade36d5897f4
Fix frontend tests on Python 2.5, where the case of some of the output of optparse usage has changed.
cmlenz
parents:
136
diff
changeset
|
476 """, sys.stdout.getvalue().lower()) |
129 | 477 |
478 def test_extract_with_default_mapping(self): | |
479 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
480 try: | |
130 | 481 self.cli.run(sys.argv + ['extract', |
129 | 482 '--copyright-holder', 'FooBar, Inc.', |
483 '--msgid-bugs-address', 'bugs.address@email.tld', | |
484 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | |
485 '-o', pot_file, os.path.join(self.datadir, 'project')]) | |
486 except SystemExit, e: | |
487 self.assertEqual(0, e.code) | |
488 assert os.path.isfile(pot_file) | |
489 self.assertEqual( | |
490 r"""# Translations template for TestProject. | |
491 # Copyright (C) %(year)s FooBar, Inc. | |
492 # This file is distributed under the same license as the TestProject | |
493 # project. | |
494 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
495 # | |
496 #, fuzzy | |
497 msgid "" | |
498 msgstr "" | |
499 "Project-Id-Version: TestProject 0.1\n" | |
500 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
501 "POT-Creation-Date: %(date)s\n" | |
502 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
503 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
504 "Language-Team: LANGUAGE <LL@li.org>\n" | |
505 "MIME-Version: 1.0\n" | |
506 "Content-Type: text/plain; charset=utf-8\n" | |
507 "Content-Transfer-Encoding: 8bit\n" | |
508 "Generated-By: Babel %(version)s\n" | |
509 | |
510 #. This will be a translator coment, | |
511 #. that will include several lines | |
512 #: project/file1.py:8 | |
513 msgid "bar" | |
514 msgstr "" | |
515 | |
516 #: project/file2.py:9 | |
517 msgid "foobar" | |
518 msgid_plural "foobars" | |
519 msgstr[0] "" | |
520 msgstr[1] "" | |
521 | |
522 #: project/CVS/this_wont_normally_be_here.py:11 | |
523 msgid "FooBar" | |
524 msgid_plural "FooBars" | |
525 msgstr[0] "" | |
526 msgstr[1] "" | |
527 | |
528 """ % {'version': VERSION, | |
529 'year': time.strftime('%Y'), | |
136 | 530 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
531 tzinfo=LOCALTZ, locale='en')}, | |
532 open(pot_file, 'U').read()) | |
129 | 533 |
534 def test_extract_with_mapping_file(self): | |
535 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
536 try: | |
130 | 537 self.cli.run(sys.argv + ['extract', |
129 | 538 '--copyright-holder', 'FooBar, Inc.', |
539 '--msgid-bugs-address', 'bugs.address@email.tld', | |
540 '--mapping', os.path.join(self.datadir, 'mapping.cfg'), | |
541 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | |
542 '-o', pot_file, os.path.join(self.datadir, 'project')]) | |
543 except SystemExit, e: | |
544 self.assertEqual(0, e.code) | |
545 assert os.path.isfile(pot_file) | |
546 self.assertEqual( | |
547 r"""# Translations template for TestProject. | |
548 # Copyright (C) %(year)s FooBar, Inc. | |
549 # This file is distributed under the same license as the TestProject | |
550 # project. | |
551 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
552 # | |
553 #, fuzzy | |
554 msgid "" | |
555 msgstr "" | |
556 "Project-Id-Version: TestProject 0.1\n" | |
557 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
558 "POT-Creation-Date: %(date)s\n" | |
559 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
560 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
561 "Language-Team: LANGUAGE <LL@li.org>\n" | |
562 "MIME-Version: 1.0\n" | |
563 "Content-Type: text/plain; charset=utf-8\n" | |
564 "Content-Transfer-Encoding: 8bit\n" | |
565 "Generated-By: Babel %(version)s\n" | |
566 | |
567 #. This will be a translator coment, | |
568 #. that will include several lines | |
569 #: project/file1.py:8 | |
570 msgid "bar" | |
571 msgstr "" | |
572 | |
573 #: project/file2.py:9 | |
574 msgid "foobar" | |
575 msgid_plural "foobars" | |
576 msgstr[0] "" | |
577 msgstr[1] "" | |
578 | |
579 """ % {'version': VERSION, | |
580 'year': time.strftime('%Y'), | |
136 | 581 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
582 tzinfo=LOCALTZ, locale='en')}, | |
583 open(pot_file, 'U').read()) | |
129 | 584 |
585 def test_init_with_output_dir(self): | |
586 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
587 'LC_MESSAGES', 'messages.po') | |
588 try: | |
130 | 589 self.cli.run(sys.argv + ['init', |
129 | 590 '--locale', 'en_US', |
591 '-d', os.path.join(self.datadir, 'project', 'i18n'), | |
592 '-i', os.path.join(self.datadir, 'project', 'i18n', | |
593 'messages.pot')]) | |
594 except SystemExit, e: | |
595 self.assertEqual(0, e.code) | |
173 | 596 assert os.path.isfile(po_file) |
129 | 597 self.assertEqual( |
598 r"""# English (United States) translations for TestProject. | |
599 # Copyright (C) 2007 FooBar, Inc. | |
600 # This file is distributed under the same license as the TestProject | |
601 # project. | |
602 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
603 # | |
604 #, fuzzy | |
605 msgid "" | |
606 msgstr "" | |
607 "Project-Id-Version: TestProject 0.1\n" | |
608 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
609 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
610 "PO-Revision-Date: %(date)s\n" | |
611 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
612 "Language-Team: en_US <LL@li.org>\n" | |
613 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
614 "MIME-Version: 1.0\n" | |
615 "Content-Type: text/plain; charset=utf-8\n" | |
616 "Content-Transfer-Encoding: 8bit\n" | |
617 "Generated-By: Babel %(version)s\n" | |
618 | |
619 #. This will be a translator coment, | |
620 #. that will include several lines | |
621 #: project/file1.py:8 | |
622 msgid "bar" | |
623 msgstr "" | |
624 | |
625 #: project/file2.py:9 | |
626 msgid "foobar" | |
627 msgid_plural "foobars" | |
628 msgstr[0] "" | |
629 msgstr[1] "" | |
630 | |
631 """ % {'version': VERSION, | |
136 | 632 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
633 tzinfo=LOCALTZ, locale='en')}, | |
129 | 634 open(po_file, 'U').read()) |
179
6138ea7ef7a8
* 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:
178
diff
changeset
|
635 |
178
51fffa0a51ac
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:
173
diff
changeset
|
636 def test_compile_catalog(self): |
234 | 637 po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE', |
178
51fffa0a51ac
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:
173
diff
changeset
|
638 'LC_MESSAGES', 'messages.po') |
234 | 639 mo_file = po_file.replace('.po', '.mo') |
640 self.cli.run(sys.argv + ['compile', | |
641 '--locale', 'de_DE', | |
642 '-d', os.path.join(self.datadir, 'project', 'i18n')]) | |
643 assert not os.path.isfile(mo_file), 'Expected no file at %r' % mo_file | |
644 self.assertEqual("""\ | |
645 catalog %r is marked as fuzzy, skipping | |
646 """ % (po_file), sys.stderr.getvalue()) | |
647 | |
648 def test_compile_fuzzy_catalog(self): | |
649 po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE', | |
650 'LC_MESSAGES', 'messages.po') | |
651 mo_file = po_file.replace('.po', '.mo') | |
178
51fffa0a51ac
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:
173
diff
changeset
|
652 try: |
51fffa0a51ac
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:
173
diff
changeset
|
653 self.cli.run(sys.argv + ['compile', |
234 | 654 '--locale', 'de_DE', '--use-fuzzy', |
178
51fffa0a51ac
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:
173
diff
changeset
|
655 '-d', os.path.join(self.datadir, 'project', 'i18n')]) |
234 | 656 assert os.path.isfile(mo_file) |
178
51fffa0a51ac
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:
173
diff
changeset
|
657 self.assertEqual("""\ |
179
6138ea7ef7a8
* 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:
178
diff
changeset
|
658 compiling catalog %r to %r |
234 | 659 """ % (po_file, mo_file), sys.stderr.getvalue()) |
660 finally: | |
661 if os.path.isfile(mo_file): | |
662 os.unlink(mo_file) | |
129 | 663 |
179
6138ea7ef7a8
* 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:
178
diff
changeset
|
664 |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
665 def suite(): |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
666 suite = unittest.TestSuite() |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
667 suite.addTest(doctest.DocTestSuite(frontend)) |
162 | 668 suite.addTest(unittest.makeSuite(CompileCatalogTestCase)) |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
669 suite.addTest(unittest.makeSuite(ExtractMessagesTestCase)) |
183
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
670 suite.addTest(unittest.makeSuite(InitCatalogTestCase)) |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
179
diff
changeset
|
671 suite.addTest(unittest.makeSuite(InitCatalogNonFuzzyTestCase)) |
129 | 672 suite.addTest(unittest.makeSuite(CommandLineInterfaceTestCase)) |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
673 return suite |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
674 |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
675 if __name__ == '__main__': |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
676 unittest.main(defaultTest='suite') |