annotate babel/messages/tests/frontend.py @ 573:a95f6e35246c trunk

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