Mercurial > babel > mirror
annotate babel/messages/tests/frontend.py @ 573:a95f6e35246c trunk
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
author | fschwarz |
---|---|
date | Mon, 23 Jul 2012 18:55:56 +0000 |
parents | 593157da23f3 |
children | 99c48a6ca1d6 |
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()) |
115 | 512 |
181
8a762ce37bf7
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
513 |
127 | 514 class CommandLineInterfaceTestCase(unittest.TestCase): |
515 | |
516 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
|
517 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
|
518 self.orig_working_dir = os.getcwd() |
128 | 519 self.orig_argv = sys.argv |
127 | 520 self.orig_stdout = sys.stdout |
521 self.orig_stderr = sys.stderr | |
232 | 522 sys.argv = ['pybabel'] |
127 | 523 sys.stdout = StringIO() |
524 sys.stderr = StringIO() | |
541
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
525 os.chdir(self.datadir) |
521
e4bd03d851ed
prevent !CommandLineInterface.run from accumulating logging handlers (fixes #227)
fschwarz
parents:
458
diff
changeset
|
526 |
548
5e08905fe812
test refactoring: clear global babel logger handlers to decrease test interdependencies (follow-up on #227)
fschwarz
parents:
541
diff
changeset
|
527 self._remove_log_handlers() |
127 | 528 self.cli = frontend.CommandLineInterface() |
529 | |
530 def tearDown(self): | |
541
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
531 os.chdir(self.orig_working_dir) |
128 | 532 sys.argv = self.orig_argv |
127 | 533 sys.stdout = self.orig_stdout |
534 sys.stderr = self.orig_stderr | |
371 | 535 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
|
536 locale_dir = os.path.join(self._i18n_dir(), dirname) |
371 | 537 if os.path.isdir(locale_dir): |
538 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
|
539 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
|
540 |
5e08905fe812
test refactoring: clear global babel logger handlers to decrease test interdependencies (follow-up on #227)
fschwarz
parents:
541
diff
changeset
|
541 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
|
542 # 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
|
543 # 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
|
544 # 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
|
545 # 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
|
546 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
|
547 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
|
548 log.removeHandler(handler) |
127 | 549 |
550 def test_usage(self): | |
551 try: | |
128 | 552 self.cli.run(sys.argv) |
127 | 553 self.fail('Expected SystemExit') |
554 except SystemExit, e: | |
555 self.assertEqual(2, e.code) | |
556 self.assertEqual("""\ | |
232 | 557 usage: pybabel command [options] [args] |
127 | 558 |
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
|
559 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
|
560 """, sys.stderr.getvalue().lower()) |
127 | 561 |
539
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
562 def _run_init_catalog(self): |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 '-i', pot_path] |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
567 self.cli.run(init_argv) |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
568 |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
569 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
|
570 self._run_init_catalog() |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
571 first_output = sys.stderr.getvalue() |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
572 self._run_init_catalog() |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
573 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
|
574 |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
575 # 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
|
576 # output as before |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
577 self.assertEqual(first_output, second_output) |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
578 |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
579 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
|
580 custom_stream = StringIO() |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
581 log = logging.getLogger('babel') |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
582 log.addHandler(logging.StreamHandler(custom_stream)) |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
583 |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
584 self._run_init_catalog() |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
585 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
|
586 self.assertEqual('', sys.stderr.getvalue()) |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
587 assert len(custom_stream.getvalue()) > 0 |
6d5452061971
add actual unit tests for #227 and add missing changelog entry
fschwarz
parents:
530
diff
changeset
|
588 |
127 | 589 def test_help(self): |
590 try: | |
128 | 591 self.cli.run(sys.argv + ['--help']) |
127 | 592 self.fail('Expected SystemExit') |
593 except SystemExit, e: | |
594 self.assertEqual(0, e.code) | |
595 self.assertEqual("""\ | |
232 | 596 usage: pybabel command [options] [args] |
127 | 597 |
598 options: | |
185
6503a227ba93
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
599 --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
|
600 -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
|
601 --list-locales print all known locales and exit |
232 | 602 -v, --verbose print as much as possible |
603 -q, --quiet print as little as possible | |
127 | 604 |
605 commands: | |
185
6503a227ba93
Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents:
181
diff
changeset
|
606 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
|
607 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
|
608 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
|
609 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
|
610 """, sys.stdout.getvalue().lower()) |
127 | 611 |
566
593157da23f3
use helper methods in frontend tests to concentrate assumptions about file system layout in these helper methods
fschwarz
parents:
548
diff
changeset
|
612 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
|
613 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
|
614 |
593157da23f3
use helper methods in frontend tests to concentrate assumptions about file system layout in these helper methods
fschwarz
parents:
548
diff
changeset
|
615 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
|
616 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
|
617 |
127 | 618 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
|
619 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
|
620 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
|
621 '--copyright-holder', 'FooBar, Inc.', |
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
622 '--project', 'TestProject', '--version', '0.1', |
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
623 '--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
|
624 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', |
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
625 '-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
|
626 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
|
627 self.assertEqual( |
127 | 628 r"""# Translations template for TestProject. |
629 # Copyright (C) %(year)s FooBar, Inc. | |
630 # This file is distributed under the same license as the TestProject | |
631 # project. | |
632 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
633 # | |
634 #, fuzzy | |
635 msgid "" | |
636 msgstr "" | |
637 "Project-Id-Version: TestProject 0.1\n" | |
638 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
639 "POT-Creation-Date: %(date)s\n" | |
640 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
641 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
642 "Language-Team: LANGUAGE <LL@li.org>\n" | |
643 "MIME-Version: 1.0\n" | |
644 "Content-Type: text/plain; charset=utf-8\n" | |
645 "Content-Transfer-Encoding: 8bit\n" | |
646 "Generated-By: Babel %(version)s\n" | |
647 | |
541
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
648 #. TRANSLATOR: This will be a translator coment, |
127 | 649 #. that will include several lines |
650 #: project/file1.py:8 | |
651 msgid "bar" | |
652 msgstr "" | |
653 | |
654 #: project/file2.py:9 | |
655 msgid "foobar" | |
656 msgid_plural "foobars" | |
657 msgstr[0] "" | |
658 msgstr[1] "" | |
659 | |
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
|
660 #: project/ignored/this_wont_normally_be_here.py:11 |
127 | 661 msgid "FooBar" |
662 msgid_plural "FooBars" | |
663 msgstr[0] "" | |
664 msgstr[1] "" | |
665 | |
666 """ % {'version': VERSION, | |
667 'year': time.strftime('%Y'), | |
134 | 668 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
669 tzinfo=LOCALTZ, locale='en')}, | |
670 open(pot_file, 'U').read()) | |
127 | 671 |
672 def test_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
|
673 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
|
674 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
|
675 '--copyright-holder', 'FooBar, Inc.', |
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
676 '--project', 'TestProject', '--version', '0.1', |
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
677 '--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
|
678 '--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
|
679 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', |
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
680 '-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
|
681 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
|
682 self.assertEqual( |
127 | 683 r"""# Translations template for TestProject. |
684 # Copyright (C) %(year)s FooBar, Inc. | |
685 # This file is distributed under the same license as the TestProject | |
686 # project. | |
687 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
688 # | |
689 #, fuzzy | |
690 msgid "" | |
691 msgstr "" | |
692 "Project-Id-Version: TestProject 0.1\n" | |
693 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
694 "POT-Creation-Date: %(date)s\n" | |
695 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
696 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
697 "Language-Team: LANGUAGE <LL@li.org>\n" | |
698 "MIME-Version: 1.0\n" | |
699 "Content-Type: text/plain; charset=utf-8\n" | |
700 "Content-Transfer-Encoding: 8bit\n" | |
701 "Generated-By: Babel %(version)s\n" | |
702 | |
541
8138648280ab
fix a couple of frontend tests so they actually test something (fixes #260)
fschwarz
parents:
539
diff
changeset
|
703 #. TRANSLATOR: This will be a translator coment, |
127 | 704 #. that will include several lines |
705 #: project/file1.py:8 | |
706 msgid "bar" | |
707 msgstr "" | |
708 | |
709 #: project/file2.py:9 | |
710 msgid "foobar" | |
711 msgid_plural "foobars" | |
712 msgstr[0] "" | |
713 msgstr[1] "" | |
714 | |
715 """ % {'version': VERSION, | |
716 'year': time.strftime('%Y'), | |
134 | 717 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
718 tzinfo=LOCALTZ, locale='en')}, | |
719 open(pot_file, 'U').read()) | |
127 | 720 |
721 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
|
722 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
|
723 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
|
724 '--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
|
725 '-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
|
726 '-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
|
727 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
|
728 self.assertEqual( |
127 | 729 r"""# English (United States) translations for TestProject. |
730 # Copyright (C) 2007 FooBar, Inc. | |
731 # This file is distributed under the same license as the TestProject | |
732 # project. | |
733 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
734 # | |
735 #, fuzzy | |
736 msgid "" | |
737 msgstr "" | |
738 "Project-Id-Version: TestProject 0.1\n" | |
739 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
740 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
741 "PO-Revision-Date: %(date)s\n" | |
742 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
743 "Language-Team: en_US <LL@li.org>\n" | |
744 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
745 "MIME-Version: 1.0\n" | |
746 "Content-Type: text/plain; charset=utf-8\n" | |
747 "Content-Transfer-Encoding: 8bit\n" | |
748 "Generated-By: Babel %(version)s\n" | |
749 | |
750 #. This will be a translator coment, | |
751 #. that will include several lines | |
752 #: project/file1.py:8 | |
753 msgid "bar" | |
754 msgstr "" | |
755 | |
756 #: project/file2.py:9 | |
757 msgid "foobar" | |
758 msgid_plural "foobars" | |
759 msgstr[0] "" | |
760 msgstr[1] "" | |
761 | |
762 """ % {'version': VERSION, | |
134 | 763 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
764 tzinfo=LOCALTZ, locale='en')}, | |
127 | 765 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
|
766 |
593157da23f3
use helper methods in frontend tests to concentrate assumptions about file system layout in these helper methods
fschwarz
parents:
548
diff
changeset
|
767 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
|
768 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
|
769 |
371 | 770 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
|
771 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
|
772 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
|
773 '--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
|
774 '-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
|
775 '-i', os.path.join(self._i18n_dir(), 'messages.pot')]) |
371 | 776 assert os.path.isfile(po_file) |
777 self.assertEqual( | |
778 r"""# Japanese (Japan) translations for TestProject. | |
779 # Copyright (C) 2007 FooBar, Inc. | |
780 # This file is distributed under the same license as the TestProject | |
781 # project. | |
782 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
783 # | |
784 #, fuzzy | |
785 msgid "" | |
786 msgstr "" | |
787 "Project-Id-Version: TestProject 0.1\n" | |
788 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
789 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
790 "PO-Revision-Date: %(date)s\n" | |
791 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
792 "Language-Team: ja_JP <LL@li.org>\n" | |
793 "Plural-Forms: nplurals=1; plural=0\n" | |
794 "MIME-Version: 1.0\n" | |
795 "Content-Type: text/plain; charset=utf-8\n" | |
796 "Content-Transfer-Encoding: 8bit\n" | |
797 "Generated-By: Babel %(version)s\n" | |
798 | |
799 #. This will be a translator coment, | |
800 #. that will include several lines | |
801 #: project/file1.py:8 | |
802 msgid "bar" | |
803 msgstr "" | |
804 | |
805 #: project/file2.py:9 | |
806 msgid "foobar" | |
807 msgid_plural "foobars" | |
808 msgstr[0] "" | |
809 | |
810 """ % {'version': VERSION, | |
811 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | |
812 tzinfo=LOCALTZ, locale='en')}, | |
813 open(po_file, 'U').read()) | |
814 | |
815 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
|
816 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
|
817 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
|
818 '--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
|
819 '-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
|
820 '-i', os.path.join(self._i18n_dir(), 'messages.pot')]) |
371 | 821 assert os.path.isfile(po_file) |
822 self.assertEqual( | |
823 r"""# Latvian (Latvia) translations for TestProject. | |
824 # Copyright (C) 2007 FooBar, Inc. | |
825 # This file is distributed under the same license as the TestProject | |
826 # project. | |
827 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
828 # | |
829 #, fuzzy | |
830 msgid "" | |
831 msgstr "" | |
832 "Project-Id-Version: TestProject 0.1\n" | |
833 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
834 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
835 "PO-Revision-Date: %(date)s\n" | |
836 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
837 "Language-Team: lv_LV <LL@li.org>\n" | |
838 "Plural-Forms: nplurals=3; plural=(n%%10==1 && n%%100!=11 ? 0 : n != 0 ? 1 :" | |
839 " 2)\n" | |
840 "MIME-Version: 1.0\n" | |
841 "Content-Type: text/plain; charset=utf-8\n" | |
842 "Content-Transfer-Encoding: 8bit\n" | |
843 "Generated-By: Babel %(version)s\n" | |
844 | |
845 #. This will be a translator coment, | |
846 #. that will include several lines | |
847 #: project/file1.py:8 | |
848 msgid "bar" | |
849 msgstr "" | |
850 | |
851 #: project/file2.py:9 | |
852 msgid "foobar" | |
853 msgid_plural "foobars" | |
854 msgstr[0] "" | |
855 msgstr[1] "" | |
856 msgstr[2] "" | |
857 | |
858 """ % {'version': VERSION, | |
859 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | |
860 tzinfo=LOCALTZ, locale='en')}, | |
861 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
|
862 |
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
|
863 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
|
864 po_file = self._po_file('de_DE') |
232 | 865 mo_file = po_file.replace('.po', '.mo') |
866 self.cli.run(sys.argv + ['compile', | |
867 '--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
|
868 '-d', self._i18n_dir()]) |
232 | 869 assert not os.path.isfile(mo_file), 'Expected no file at %r' % mo_file |
870 self.assertEqual("""\ | |
871 catalog %r is marked as fuzzy, skipping | |
872 """ % (po_file), sys.stderr.getvalue()) | |
873 | |
874 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
|
875 po_file = self._po_file('de_DE') |
232 | 876 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
|
877 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
|
878 self.cli.run(sys.argv + ['compile', |
232 | 879 '--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
|
880 '-d', self._i18n_dir()]) |
232 | 881 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
|
882 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
|
883 compiling catalog %r to %r |
232 | 884 """ % (po_file, mo_file), sys.stderr.getvalue()) |
885 finally: | |
886 if os.path.isfile(mo_file): | |
887 os.unlink(mo_file) | |
127 | 888 |
566
593157da23f3
use helper methods in frontend tests to concentrate assumptions about file system layout in these helper methods
fschwarz
parents:
548
diff
changeset
|
889 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
|
890 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
|
891 '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
|
892 |
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
|
893 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
|
894 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
|
895 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
|
896 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
|
897 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
|
898 '--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
|
899 '-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
|
900 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
|
901 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
|
902 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
|
903 """ % (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
|
904 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
|
905 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
|
906 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
|
907 |
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
|
908 |
12
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
909 def suite(): |
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
910 suite = unittest.TestSuite() |
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
911 suite.addTest(doctest.DocTestSuite(frontend)) |
160 | 912 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
|
913 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
|
914 suite.addTest(unittest.makeSuite(InitCatalogTestCase)) |
127 | 915 suite.addTest(unittest.makeSuite(CommandLineInterfaceTestCase)) |
12
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
916 return suite |
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
917 |
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
918 if __name__ == '__main__': |
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
919 unittest.main(defaultTest='suite') |