Mercurial > babel > old > mirror
annotate babel/messages/tests/frontend.py @ 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.
author | palgarvio |
---|---|
date | Tue, 26 Jun 2007 18:22:19 +0000 |
parents | 6655bb6ae28d |
children | 6138ea7ef7a8 |
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_locale_specified(self): | |
52 self.cmd.directory = 'dummy' | |
53 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
54 | |
55 def test_no_directory_or_output_file_specified(self): | |
56 self.cmd.locale = 'en_US' | |
57 self.cmd.input_file = 'dummy' | |
58 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
59 | |
60 def test_no_directory_or_input_file_specified(self): | |
61 self.cmd.locale = 'en_US' | |
62 self.cmd.output_file = 'dummy' | |
63 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
64 | |
65 | |
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
|
66 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
|
67 |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
68 def setUp(self): |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 _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
|
73 |
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 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
|
75 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
|
76 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
|
77 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
|
78 )) |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
79 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
|
80 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
|
81 |
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 def tearDown(self): |
122 | 83 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
|
84 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
|
85 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
|
86 |
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 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
|
88 |
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 def test_neither_default_nor_custom_keywords(self): |
122 | 90 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
|
91 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
|
92 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
|
93 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
94 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
|
95 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
|
96 |
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 def test_both_sort_output_and_sort_by_file(self): |
122 | 98 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
|
99 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
|
100 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
|
101 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
|
102 |
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 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
|
104 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
|
105 self.cmd.msgid_bugs_address = 'bugs.address@email.tld' |
122 | 106 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
|
107 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
|
108 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
109 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
|
110 self.cmd.run() |
122 | 111 |
112 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
113 assert os.path.isfile(pot_file) | |
114 | |
115 self.assertEqual( | |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
116 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
|
117 # 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
|
118 # 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
|
119 # project. |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
120 # 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
|
121 # |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
122 #, fuzzy |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
123 msgid "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
124 msgstr "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
125 "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
|
126 "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
|
127 "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
|
128 "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
|
129 "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
|
130 "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
|
131 "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
|
132 "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
|
133 "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
|
134 "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
|
135 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
136 #. 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
|
137 #. 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
|
138 #: 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
|
139 msgid "bar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
140 msgstr "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
141 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
142 #: 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
|
143 msgid "foobar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
144 msgid_plural "foobars" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
145 msgstr[0] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
146 msgstr[1] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
147 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
148 #: 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
|
149 msgid "FooBar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
150 msgid_plural "FooBars" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
151 msgstr[0] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
152 msgstr[1] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
153 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
154 """ % {'version': VERSION, |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
155 'year': time.strftime('%Y'), |
136 | 156 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
157 tzinfo=LOCALTZ, locale='en')}, | |
158 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
|
159 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 self.cmd.mapping_file = 'mapping.cfg' |
122 | 164 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
|
165 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
|
166 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
167 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
|
168 self.cmd.run() |
122 | 169 |
170 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
171 assert os.path.isfile(pot_file) | |
172 | |
173 self.assertEqual( | |
116
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
174 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
|
175 # 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
|
176 # 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
|
177 # project. |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
178 # 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
|
179 # |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
180 #, fuzzy |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
181 msgid "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
182 msgstr "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
183 "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
|
184 "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
|
185 "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
|
186 "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
|
187 "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
|
188 "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
|
189 "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
|
190 "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
|
191 "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
|
192 "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
|
193 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
194 #. 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
|
195 #. 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
|
196 #: 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
|
197 msgid "bar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
198 msgstr "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
199 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
200 #: 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
|
201 msgid "foobar" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
202 msgid_plural "foobars" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
203 msgstr[0] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
204 msgstr[1] "" |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
205 |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
206 """ % {'version': VERSION, |
c6214115e4da
Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents:
56
diff
changeset
|
207 'year': time.strftime('%Y'), |
136 | 208 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
209 tzinfo=LOCALTZ, locale='en')}, | |
210 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
|
211 |
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 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
|
213 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
|
214 '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
|
215 ('**/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
|
216 ('**.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
|
217 ] |
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 } |
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 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
|
220 self.cmd.msgid_bugs_address = 'bugs.address@email.tld' |
122 | 221 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
|
222 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
|
223 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
224 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
|
225 self.cmd.run() |
122 | 226 |
227 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
228 assert os.path.isfile(pot_file) | |
229 | |
230 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
|
231 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
|
232 # 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
|
233 # 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
|
234 # 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
|
235 # 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
|
236 # |
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 #, 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
|
238 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
|
239 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
|
240 "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
|
241 "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
|
242 "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
|
243 "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
|
244 "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
|
245 "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
|
246 "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
|
247 "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
|
248 "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
|
249 "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
|
250 |
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 #. 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
|
252 #. 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
|
253 #: 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
|
254 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
|
255 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
|
256 |
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 #: 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
117
diff
changeset
|
263 """ % {'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
|
264 'year': time.strftime('%Y'), |
136 | 265 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
266 tzinfo=LOCALTZ, locale='en')}, | |
267 open(pot_file, 'U').read()) | |
122 | 268 |
269 | |
270 class NewCatalogTestCase(unittest.TestCase): | |
271 | |
272 def setUp(self): | |
273 self.olddir = os.getcwd() | |
274 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | |
275 os.chdir(self.datadir) | |
276 _global_log.threshold = 5 # shut up distutils logging | |
277 | |
278 self.dist = Distribution(dict( | |
279 name='TestProject', | |
280 version='0.1', | |
281 packages=['project'] | |
282 )) | |
283 self.cmd = frontend.new_catalog(self.dist) | |
284 self.cmd.initialize_options() | |
285 | |
286 def tearDown(self): | |
287 locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US') | |
288 if os.path.isdir(locale_dir): | |
289 shutil.rmtree(locale_dir) | |
290 | |
291 os.chdir(self.olddir) | |
292 | |
293 def test_no_input_file(self): | |
294 self.cmd.locale = 'en_US' | |
295 self.cmd.output_file = 'dummy' | |
296 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
297 | |
298 def test_no_locale(self): | |
299 self.cmd.input_file = 'dummy' | |
300 self.cmd.output_file = 'dummy' | |
301 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
302 | |
123 | 303 def test_with_output_dir(self): |
122 | 304 self.cmd.input_file = 'project/i18n/messages.pot' |
305 self.cmd.locale = 'en_US' | |
306 self.cmd.output_dir = 'project/i18n' | |
307 | |
308 self.cmd.finalize_options() | |
309 self.cmd.run() | |
310 | |
311 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
312 'LC_MESSAGES', 'messages.po') | |
313 assert os.path.isfile(po_file) | |
314 | |
315 self.assertEqual( | |
316 r"""# English (United States) translations for TestProject. | |
317 # Copyright (C) 2007 FooBar, Inc. | |
318 # This file is distributed under the same license as the TestProject | |
319 # project. | |
320 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
321 # | |
322 #, fuzzy | |
323 msgid "" | |
324 msgstr "" | |
325 "Project-Id-Version: TestProject 0.1\n" | |
326 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
327 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
328 "PO-Revision-Date: %(date)s\n" | |
329 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
330 "Language-Team: en_US <LL@li.org>\n" | |
331 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
332 "MIME-Version: 1.0\n" | |
333 "Content-Type: text/plain; charset=utf-8\n" | |
334 "Content-Transfer-Encoding: 8bit\n" | |
335 "Generated-By: Babel %(version)s\n" | |
336 | |
337 #. This will be a translator coment, | |
338 #. that will include several lines | |
339 #: project/file1.py:8 | |
340 msgid "bar" | |
341 msgstr "" | |
342 | |
343 #: project/file2.py:9 | |
344 msgid "foobar" | |
345 msgid_plural "foobars" | |
346 msgstr[0] "" | |
347 msgstr[1] "" | |
348 | |
349 """ % {'version': VERSION, | |
136 | 350 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
351 tzinfo=LOCALTZ, locale='en')}, | |
122 | 352 open(po_file, 'U').read()) |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
353 |
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
|
354 class NewNonFuzzyCatalogTestCase(unittest.TestCase): |
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 |
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 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
|
357 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
|
358 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
|
359 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
|
360 _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
|
361 |
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 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
|
363 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
|
364 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
|
365 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
|
366 )) |
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 self.cmd = frontend.new_catalog(self.dist) |
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 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
|
369 |
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 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
|
371 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
|
372 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
|
373 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
|
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 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
|
376 |
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 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
|
378 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
|
379 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
|
380 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
|
381 |
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 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
|
383 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
|
384 |
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 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
|
386 '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
|
387 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
|
388 |
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 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
|
390 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
|
391 # 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
|
392 # 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
|
393 # 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
|
394 # 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
|
395 # |
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 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
|
397 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
|
398 "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
|
399 "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
|
400 "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
|
401 "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
|
402 "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
|
403 "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
|
404 "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
|
405 "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
|
406 "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
|
407 "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
|
408 "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
|
409 |
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 #. 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
|
411 #. 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
|
412 #: 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
|
413 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
|
414 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
|
415 |
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 #: 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 |
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 """ % {'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
|
423 '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
|
424 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
|
425 open(po_file, 'U').read()) |
117 | 426 |
129 | 427 class CommandLineInterfaceTestCase(unittest.TestCase): |
428 | |
429 def setUp(self): | |
430 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | |
130 | 431 self.orig_argv = sys.argv |
129 | 432 self.orig_stdout = sys.stdout |
433 self.orig_stderr = sys.stderr | |
130 | 434 sys.argv = ['babel'] |
129 | 435 sys.stdout = StringIO() |
436 sys.stderr = StringIO() | |
437 self.cli = frontend.CommandLineInterface() | |
438 | |
439 def tearDown(self): | |
130 | 440 sys.argv = self.orig_argv |
129 | 441 sys.stdout = self.orig_stdout |
442 sys.stderr = self.orig_stderr | |
443 | |
444 def test_usage(self): | |
445 try: | |
130 | 446 self.cli.run(sys.argv) |
129 | 447 self.fail('Expected SystemExit') |
448 except SystemExit, e: | |
449 self.assertEqual(2, e.code) | |
450 self.assertEqual("""\ | |
130 | 451 usage: babel command [options] [args] |
129 | 452 |
130 | 453 babel: 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
|
454 """, sys.stderr.getvalue().lower()) |
129 | 455 |
456 def test_help(self): | |
457 try: | |
130 | 458 self.cli.run(sys.argv + ['--help']) |
129 | 459 self.fail('Expected SystemExit') |
460 except SystemExit, e: | |
461 self.assertEqual(0, e.code) | |
462 self.assertEqual("""\ | |
130 | 463 usage: babel command [options] [args] |
129 | 464 |
465 options: | |
466 --version show program's version number and exit | |
467 -h, --help show this help message and exit | |
468 | |
469 commands: | |
162 | 470 compile compile a message catalog to a mo 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
|
471 extract extract messages from source files and generate a pot file |
129 | 472 init create new message catalogs from a template |
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
|
473 """, sys.stdout.getvalue().lower()) |
129 | 474 |
475 def test_extract_with_default_mapping(self): | |
476 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
477 try: | |
130 | 478 self.cli.run(sys.argv + ['extract', |
129 | 479 '--copyright-holder', 'FooBar, Inc.', |
480 '--msgid-bugs-address', 'bugs.address@email.tld', | |
481 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | |
482 '-o', pot_file, os.path.join(self.datadir, 'project')]) | |
483 except SystemExit, e: | |
484 self.assertEqual(0, e.code) | |
485 assert os.path.isfile(pot_file) | |
486 self.assertEqual( | |
487 r"""# Translations template for TestProject. | |
488 # Copyright (C) %(year)s FooBar, Inc. | |
489 # This file is distributed under the same license as the TestProject | |
490 # project. | |
491 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
492 # | |
493 #, fuzzy | |
494 msgid "" | |
495 msgstr "" | |
496 "Project-Id-Version: TestProject 0.1\n" | |
497 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
498 "POT-Creation-Date: %(date)s\n" | |
499 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
500 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
501 "Language-Team: LANGUAGE <LL@li.org>\n" | |
502 "MIME-Version: 1.0\n" | |
503 "Content-Type: text/plain; charset=utf-8\n" | |
504 "Content-Transfer-Encoding: 8bit\n" | |
505 "Generated-By: Babel %(version)s\n" | |
506 | |
507 #. This will be a translator coment, | |
508 #. that will include several lines | |
509 #: project/file1.py:8 | |
510 msgid "bar" | |
511 msgstr "" | |
512 | |
513 #: project/file2.py:9 | |
514 msgid "foobar" | |
515 msgid_plural "foobars" | |
516 msgstr[0] "" | |
517 msgstr[1] "" | |
518 | |
519 #: project/CVS/this_wont_normally_be_here.py:11 | |
520 msgid "FooBar" | |
521 msgid_plural "FooBars" | |
522 msgstr[0] "" | |
523 msgstr[1] "" | |
524 | |
525 """ % {'version': VERSION, | |
526 'year': time.strftime('%Y'), | |
136 | 527 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
528 tzinfo=LOCALTZ, locale='en')}, | |
529 open(pot_file, 'U').read()) | |
129 | 530 |
531 def test_extract_with_mapping_file(self): | |
532 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
533 try: | |
130 | 534 self.cli.run(sys.argv + ['extract', |
129 | 535 '--copyright-holder', 'FooBar, Inc.', |
536 '--msgid-bugs-address', 'bugs.address@email.tld', | |
537 '--mapping', os.path.join(self.datadir, 'mapping.cfg'), | |
538 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | |
539 '-o', pot_file, os.path.join(self.datadir, 'project')]) | |
540 except SystemExit, e: | |
541 self.assertEqual(0, e.code) | |
542 assert os.path.isfile(pot_file) | |
543 self.assertEqual( | |
544 r"""# Translations template for TestProject. | |
545 # Copyright (C) %(year)s FooBar, Inc. | |
546 # This file is distributed under the same license as the TestProject | |
547 # project. | |
548 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
549 # | |
550 #, fuzzy | |
551 msgid "" | |
552 msgstr "" | |
553 "Project-Id-Version: TestProject 0.1\n" | |
554 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
555 "POT-Creation-Date: %(date)s\n" | |
556 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
557 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
558 "Language-Team: LANGUAGE <LL@li.org>\n" | |
559 "MIME-Version: 1.0\n" | |
560 "Content-Type: text/plain; charset=utf-8\n" | |
561 "Content-Transfer-Encoding: 8bit\n" | |
562 "Generated-By: Babel %(version)s\n" | |
563 | |
564 #. This will be a translator coment, | |
565 #. that will include several lines | |
566 #: project/file1.py:8 | |
567 msgid "bar" | |
568 msgstr "" | |
569 | |
570 #: project/file2.py:9 | |
571 msgid "foobar" | |
572 msgid_plural "foobars" | |
573 msgstr[0] "" | |
574 msgstr[1] "" | |
575 | |
576 """ % {'version': VERSION, | |
577 'year': time.strftime('%Y'), | |
136 | 578 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
579 tzinfo=LOCALTZ, locale='en')}, | |
580 open(pot_file, 'U').read()) | |
129 | 581 |
582 def test_init_with_output_dir(self): | |
583 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
584 'LC_MESSAGES', 'messages.po') | |
585 try: | |
130 | 586 self.cli.run(sys.argv + ['init', |
129 | 587 '--locale', 'en_US', |
588 '-d', os.path.join(self.datadir, 'project', 'i18n'), | |
589 '-i', os.path.join(self.datadir, 'project', 'i18n', | |
590 'messages.pot')]) | |
591 except SystemExit, e: | |
592 self.assertEqual(0, e.code) | |
173 | 593 assert os.path.isfile(po_file) |
129 | 594 self.assertEqual( |
595 r"""# English (United States) translations for TestProject. | |
596 # Copyright (C) 2007 FooBar, Inc. | |
597 # This file is distributed under the same license as the TestProject | |
598 # project. | |
599 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
600 # | |
601 #, fuzzy | |
602 msgid "" | |
603 msgstr "" | |
604 "Project-Id-Version: TestProject 0.1\n" | |
605 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
606 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
607 "PO-Revision-Date: %(date)s\n" | |
608 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
609 "Language-Team: en_US <LL@li.org>\n" | |
610 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
611 "MIME-Version: 1.0\n" | |
612 "Content-Type: text/plain; charset=utf-8\n" | |
613 "Content-Transfer-Encoding: 8bit\n" | |
614 "Generated-By: Babel %(version)s\n" | |
615 | |
616 #. This will be a translator coment, | |
617 #. that will include several lines | |
618 #: project/file1.py:8 | |
619 msgid "bar" | |
620 msgstr "" | |
621 | |
622 #: project/file2.py:9 | |
623 msgid "foobar" | |
624 msgid_plural "foobars" | |
625 msgstr[0] "" | |
626 msgstr[1] "" | |
627 | |
628 """ % {'version': VERSION, | |
136 | 629 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
630 tzinfo=LOCALTZ, locale='en')}, | |
129 | 631 open(po_file, 'U').read()) |
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
|
632 |
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
|
633 def test_compile_catalog(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
|
634 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
|
635 '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
|
636 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'messages.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
|
637 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
|
638 self.cli.run(sys.argv + ['init', |
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
|
639 '--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
|
640 '-d', os.path.join(self.datadir, '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
|
641 '-i', pot_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
|
642 except SystemExit, e: |
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
|
643 self.assertEqual(0, e.code) |
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
|
644 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
|
645 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
|
646 self.cli.run(sys.argv + ['compile', |
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
|
647 '--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
|
648 '-d', os.path.join(self.datadir, '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
|
649 except SystemExit, e: |
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
|
650 self.assertEqual(0, e.code) |
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
|
651 mo_file = po_file.replace('.po', '.mo') |
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 assert not os.path.isfile(mo_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
|
653 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
|
654 creating catalog %r based on %r |
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 catalog is marked as fuzzy, not compiling it |
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
|
656 """ % (po_file, pot_file), sys.stdout.getvalue()) |
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 shutil.rmtree(os.path.join(self.datadir, '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
|
658 '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
|
659 |
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
|
660 def test_compile_fuzzy_catalog(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
|
661 self.setUp() |
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
|
662 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
|
663 '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
|
664 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'messages.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
|
665 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
|
666 self.cli.run(sys.argv + ['init', |
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
|
667 '--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
|
668 '-d', os.path.join(self.datadir, '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
|
669 '-i', pot_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
|
670 except SystemExit, e: |
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
|
671 self.assertEqual(0, e.code) |
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
|
672 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
|
673 self.cli.run(sys.argv + ['compile', |
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
|
674 '--locale', 'en_US', '--use-fuzzy', |
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
|
675 '-d', os.path.join(self.datadir, '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
|
676 mo_file = po_file.replace('.po', '.mo') |
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
|
677 assert os.path.isfile(mo_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
|
678 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
|
679 creating catalog %r based on %r |
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
|
680 compiling catalog to %r |
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
|
681 """ % (po_file, pot_file, mo_file), sys.stdout.getvalue()) |
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
|
682 shutil.rmtree(os.path.join(self.datadir, 'project', 'i18n', 'en_US')) |
129 | 683 |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
684 def suite(): |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
685 suite = unittest.TestSuite() |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
686 suite.addTest(doctest.DocTestSuite(frontend)) |
162 | 687 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
|
688 suite.addTest(unittest.makeSuite(ExtractMessagesTestCase)) |
122 | 689 suite.addTest(unittest.makeSuite(NewCatalogTestCase)) |
129 | 690 suite.addTest(unittest.makeSuite(CommandLineInterfaceTestCase)) |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
691 return suite |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
692 |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
693 if __name__ == '__main__': |
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
694 unittest.main(defaultTest='suite') |