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