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