annotate babel/messages/tests/frontend.py @ 234:541b6d630575

Use logging module for output from CLI frontend.
author cmlenz
date Mon, 30 Jul 2007 20:28:43 +0000
parents d3bde66ac8a9
children 72351fd5fc29
rev   line source
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
2 #
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
3 # Copyright (C) 2007 Edgewall Software
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
4 # All rights reserved.
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
5 #
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
9 #
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
13
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
14 from datetime import datetime
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
15 from distutils.dist import Distribution
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
16 from distutils.errors import DistutilsOptionError, DistutilsSetupError
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
17 from distutils.log import _global_log
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
18 import doctest
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
19 import os
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
20 import shutil
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
21 from StringIO import StringIO
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
22 import sys
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
23 import time
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
24 import unittest
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
25
116
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
26 from babel import __version__ as VERSION
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
27 from babel.dates import format_datetime
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
28 from babel.messages import frontend
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
29 from babel.util import LOCALTZ
116
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
30
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
31
162
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
32 class CompileCatalogTestCase(unittest.TestCase):
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
33
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
34 def setUp(self):
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
35 self.olddir = os.getcwd()
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
36 self.datadir = os.path.join(os.path.dirname(__file__), 'data')
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
37 os.chdir(self.datadir)
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
38 _global_log.threshold = 5 # shut up distutils logging
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
39
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
40 self.dist = Distribution(dict(
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
41 name='TestProject',
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
42 version='0.1',
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
43 packages=['project']
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
44 ))
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
45 self.cmd = frontend.compile_catalog(self.dist)
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
46 self.cmd.initialize_options()
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
47
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
48 def tearDown(self):
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
49 os.chdir(self.olddir)
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
50
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
51 def test_no_directory_or_output_file_specified(self):
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
52 self.cmd.locale = 'en_US'
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
53 self.cmd.input_file = 'dummy'
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
54 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
55
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
56 def test_no_directory_or_input_file_specified(self):
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
57 self.cmd.locale = 'en_US'
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
58 self.cmd.output_file = 'dummy'
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
59 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
60
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
61
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
62 class ExtractMessagesTestCase(unittest.TestCase):
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
63
116
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
64 def setUp(self):
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
65 self.olddir = os.getcwd()
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
66 self.datadir = os.path.join(os.path.dirname(__file__), 'data')
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
67 os.chdir(self.datadir)
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
68 _global_log.threshold = 5 # shut up distutils logging
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
69
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
70 self.dist = Distribution(dict(
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
71 name='TestProject',
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
72 version='0.1',
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
73 packages=['project']
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
74 ))
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
75 self.cmd = frontend.extract_messages(self.dist)
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
76 self.cmd.initialize_options()
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
77
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
78 def tearDown(self):
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
79 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
80 if os.path.isfile(pot_file):
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
81 os.unlink(pot_file)
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
82
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
83 os.chdir(self.olddir)
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
84
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
85 def test_neither_default_nor_custom_keywords(self):
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
86 self.cmd.output_file = 'dummy'
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
87 self.cmd.no_default_keywords = True
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
88 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
89
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
90 def test_no_output_file_specified(self):
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
91 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
92
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
93 def test_both_sort_output_and_sort_by_file(self):
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
94 self.cmd.output_file = 'dummy'
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
95 self.cmd.sort_output = True
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
96 self.cmd.sort_by_file = True
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
97 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
98
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
99 def test_extraction_with_default_mapping(self):
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
100 self.cmd.copyright_holder = 'FooBar, Inc.'
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
101 self.cmd.msgid_bugs_address = 'bugs.address@email.tld'
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
102 self.cmd.output_file = 'project/i18n/temp.pot'
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
103 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:'
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
104
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
105 self.cmd.finalize_options()
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
106 self.cmd.run()
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
107
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
108 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
109 assert os.path.isfile(pot_file)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
110
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
111 self.assertEqual(
116
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
112 r"""# Translations template for TestProject.
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
113 # Copyright (C) %(year)s FooBar, Inc.
116
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
114 # This file is distributed under the same license as the TestProject
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
115 # project.
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
116 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
117 #
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
118 #, fuzzy
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
119 msgid ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
120 msgstr ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
121 "Project-Id-Version: TestProject 0.1\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
122 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
123 "POT-Creation-Date: %(date)s\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
124 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
125 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
126 "Language-Team: LANGUAGE <LL@li.org>\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
127 "MIME-Version: 1.0\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
128 "Content-Type: text/plain; charset=utf-8\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
129 "Content-Transfer-Encoding: 8bit\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
130 "Generated-By: Babel %(version)s\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
131
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
132 #. This will be a translator coment,
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
133 #. that will include several lines
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
134 #: project/file1.py:8
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
135 msgid "bar"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
136 msgstr ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
137
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
138 #: project/file2.py:9
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
139 msgid "foobar"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
140 msgid_plural "foobars"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
141 msgstr[0] ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
142 msgstr[1] ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
143
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
144 #: project/CVS/this_wont_normally_be_here.py:11
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
145 msgid "FooBar"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
146 msgid_plural "FooBars"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
147 msgstr[0] ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
148 msgstr[1] ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
149
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
150 """ % {'version': VERSION,
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
151 'year': time.strftime('%Y'),
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
152 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
153 tzinfo=LOCALTZ, locale='en')},
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
154 open(pot_file, 'U').read())
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
155
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
156 def test_extraction_with_mapping_file(self):
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
157 self.cmd.copyright_holder = 'FooBar, Inc.'
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
158 self.cmd.msgid_bugs_address = 'bugs.address@email.tld'
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
159 self.cmd.mapping_file = 'mapping.cfg'
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
160 self.cmd.output_file = 'project/i18n/temp.pot'
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
161 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:'
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
162
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
163 self.cmd.finalize_options()
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
164 self.cmd.run()
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
165
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
166 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
167 assert os.path.isfile(pot_file)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
168
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
169 self.assertEqual(
116
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
170 r"""# Translations template for TestProject.
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
171 # Copyright (C) %(year)s FooBar, Inc.
116
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
172 # This file is distributed under the same license as the TestProject
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
173 # project.
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
174 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
175 #
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
176 #, fuzzy
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
177 msgid ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
178 msgstr ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
179 "Project-Id-Version: TestProject 0.1\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
180 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
181 "POT-Creation-Date: %(date)s\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
182 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
183 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
184 "Language-Team: LANGUAGE <LL@li.org>\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
185 "MIME-Version: 1.0\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
186 "Content-Type: text/plain; charset=utf-8\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
187 "Content-Transfer-Encoding: 8bit\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
188 "Generated-By: Babel %(version)s\n"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
189
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
190 #. This will be a translator coment,
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
191 #. that will include several lines
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
192 #: project/file1.py:8
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
193 msgid "bar"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
194 msgstr ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
195
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
196 #: project/file2.py:9
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
197 msgid "foobar"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
198 msgid_plural "foobars"
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
199 msgstr[0] ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
200 msgstr[1] ""
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
201
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
202 """ % {'version': VERSION,
c6214115e4da Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 56
diff changeset
203 'year': time.strftime('%Y'),
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
204 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
205 tzinfo=LOCALTZ, locale='en')},
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
206 open(pot_file, 'U').read())
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
207
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
208 def test_extraction_with_mapping_dict(self):
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
209 self.dist.message_extractors = {
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
210 'project': [
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
211 ('**/CVS/**.*', 'ignore', None),
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
212 ('**.py', 'python', None),
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
213 ]
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
214 }
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
215 self.cmd.copyright_holder = 'FooBar, Inc.'
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
216 self.cmd.msgid_bugs_address = 'bugs.address@email.tld'
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
217 self.cmd.output_file = 'project/i18n/temp.pot'
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
218 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:'
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
219
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
220 self.cmd.finalize_options()
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
221 self.cmd.run()
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
222
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
223 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
224 assert os.path.isfile(pot_file)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
225
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
226 self.assertEqual(
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
227 r"""# Translations template for TestProject.
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
228 # Copyright (C) %(year)s FooBar, Inc.
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
229 # This file is distributed under the same license as the TestProject
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
230 # project.
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
231 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
232 #
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
233 #, fuzzy
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
234 msgid ""
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
235 msgstr ""
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
236 "Project-Id-Version: TestProject 0.1\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
237 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
238 "POT-Creation-Date: %(date)s\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
239 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
240 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
241 "Language-Team: LANGUAGE <LL@li.org>\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
242 "MIME-Version: 1.0\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
243 "Content-Type: text/plain; charset=utf-8\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
244 "Content-Transfer-Encoding: 8bit\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
245 "Generated-By: Babel %(version)s\n"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
246
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
247 #. This will be a translator coment,
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
248 #. that will include several lines
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
249 #: project/file1.py:8
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
250 msgid "bar"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
251 msgstr ""
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
252
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
253 #: project/file2.py:9
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
254 msgid "foobar"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
255 msgid_plural "foobars"
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
256 msgstr[0] ""
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
257 msgstr[1] ""
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
258
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
259 """ % {'version': VERSION,
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
260 'year': time.strftime('%Y'),
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
261 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
262 tzinfo=LOCALTZ, locale='en')},
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
263 open(pot_file, 'U').read())
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
264
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
265
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
266 class InitCatalogTestCase(unittest.TestCase):
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
267
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
268 def setUp(self):
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
269 self.olddir = os.getcwd()
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
270 self.datadir = os.path.join(os.path.dirname(__file__), 'data')
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
271 os.chdir(self.datadir)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
272 _global_log.threshold = 5 # shut up distutils logging
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
273
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
274 self.dist = Distribution(dict(
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
275 name='TestProject',
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
276 version='0.1',
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
277 packages=['project']
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
278 ))
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
279 self.cmd = frontend.init_catalog(self.dist)
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
280 self.cmd.initialize_options()
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
281
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
282 def tearDown(self):
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
283 locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US')
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
284 if os.path.isdir(locale_dir):
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
285 shutil.rmtree(locale_dir)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
286
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
287 os.chdir(self.olddir)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
288
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
289 def test_no_input_file(self):
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
290 self.cmd.locale = 'en_US'
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
291 self.cmd.output_file = 'dummy'
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
292 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
293
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
294 def test_no_locale(self):
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
295 self.cmd.input_file = 'dummy'
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
296 self.cmd.output_file = 'dummy'
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
297 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
298
123
5b4f302abf53 Fix parsing of timezone in POT creation date.
cmlenz
parents: 122
diff changeset
299 def test_with_output_dir(self):
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
300 self.cmd.input_file = 'project/i18n/messages.pot'
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
301 self.cmd.locale = 'en_US'
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
302 self.cmd.output_dir = 'project/i18n'
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
303
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
304 self.cmd.finalize_options()
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
305 self.cmd.run()
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
306
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
307 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US',
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
308 'LC_MESSAGES', 'messages.po')
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
309 assert os.path.isfile(po_file)
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
310
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
311 self.assertEqual(
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
312 r"""# English (United States) translations for TestProject.
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
313 # Copyright (C) 2007 FooBar, Inc.
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
314 # This file is distributed under the same license as the TestProject
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
315 # project.
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
316 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
317 #
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
318 #, fuzzy
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
319 msgid ""
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
320 msgstr ""
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
321 "Project-Id-Version: TestProject 0.1\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
322 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
323 "POT-Creation-Date: 2007-04-01 15:30+0200\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
324 "PO-Revision-Date: %(date)s\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
325 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
326 "Language-Team: en_US <LL@li.org>\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
327 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
328 "MIME-Version: 1.0\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
329 "Content-Type: text/plain; charset=utf-8\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
330 "Content-Transfer-Encoding: 8bit\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
331 "Generated-By: Babel %(version)s\n"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
332
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
333 #. This will be a translator coment,
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
334 #. that will include several lines
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
335 #: project/file1.py:8
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
336 msgid "bar"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
337 msgstr ""
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
338
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
339 #: project/file2.py:9
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
340 msgid "foobar"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
341 msgid_plural "foobars"
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
342 msgstr[0] ""
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
343 msgstr[1] ""
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
344
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
345 """ % {'version': VERSION,
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
346 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
347 tzinfo=LOCALTZ, locale='en')},
122
03f106700f02 Added tests for `new_catalog` distutils command.
cmlenz
parents: 119
diff changeset
348 open(po_file, 'U').read())
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
349
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
350
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
351 class InitCatalogNonFuzzyTestCase(unittest.TestCase):
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
352 # FIXME: what is this test case about?
178
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
353
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
354 def setUp(self):
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
355 self.olddir = os.getcwd()
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
356 self.datadir = os.path.join(os.path.dirname(__file__), 'data')
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
357 os.chdir(self.datadir)
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
358 _global_log.threshold = 5 # shut up distutils logging
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
359
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
360 self.dist = Distribution(dict(
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
361 name='TestProject',
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
362 version='0.1',
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
363 packages=['project']
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
364 ))
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
365 self.cmd = frontend.init_catalog(self.dist)
178
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
366 self.cmd.initialize_options()
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
367
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
368 def tearDown(self):
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
369 locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US')
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
370 if os.path.isdir(locale_dir):
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
371 shutil.rmtree(locale_dir)
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
372
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
373 os.chdir(self.olddir)
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
374
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
375 def test_with_output_dir(self):
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
376 self.cmd.input_file = 'project/i18n/messages_non_fuzzy.pot'
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
377 self.cmd.locale = 'en_US'
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
378 self.cmd.output_dir = 'project/i18n'
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
379
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
380 self.cmd.finalize_options()
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
381 self.cmd.run()
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
382
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
383 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US',
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
384 'LC_MESSAGES', 'messages.po')
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
385 assert os.path.isfile(po_file)
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
386
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
387 self.assertEqual(
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
388 r"""# English (United States) translations for TestProject.
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
389 # Copyright (C) 2007 FooBar, Inc.
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
390 # This file is distributed under the same license as the TestProject
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
391 # project.
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
392 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
393 #
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
394 msgid ""
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
395 msgstr ""
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
396 "Project-Id-Version: TestProject 0.1\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
397 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
398 "POT-Creation-Date: 2007-04-01 15:30+0200\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
399 "PO-Revision-Date: %(date)s\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
400 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
401 "Language-Team: en_US <LL@li.org>\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
402 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
403 "MIME-Version: 1.0\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
404 "Content-Type: text/plain; charset=utf-8\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
405 "Content-Transfer-Encoding: 8bit\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
406 "Generated-By: Babel %(version)s\n"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
407
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
408 #. This will be a translator coment,
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
409 #. that will include several lines
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
410 #: project/file1.py:8
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
411 msgid "bar"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
412 msgstr ""
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
413
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
414 #: project/file2.py:9
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
415 msgid "foobar"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
416 msgid_plural "foobars"
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
417 msgstr[0] ""
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
418 msgstr[1] ""
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
419
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
420 """ % {'version': VERSION,
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
421 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
422 tzinfo=LOCALTZ, locale='en')},
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
423 open(po_file, 'U').read())
117
0b4796ed9426 Added new logo.
cmlenz
parents: 116
diff changeset
424
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
425
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
426 class CommandLineInterfaceTestCase(unittest.TestCase):
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
427
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
428 def setUp(self):
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
429 self.datadir = os.path.join(os.path.dirname(__file__), 'data')
130
383b18bfcc95 Fake `sys.argv` for CLI tests.
cmlenz
parents: 129
diff changeset
430 self.orig_argv = sys.argv
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
431 self.orig_stdout = sys.stdout
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
432 self.orig_stderr = sys.stderr
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
433 sys.argv = ['pybabel']
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
434 sys.stdout = StringIO()
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
435 sys.stderr = StringIO()
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
436 self.cli = frontend.CommandLineInterface()
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
437
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
438 def tearDown(self):
130
383b18bfcc95 Fake `sys.argv` for CLI tests.
cmlenz
parents: 129
diff changeset
439 sys.argv = self.orig_argv
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
440 sys.stdout = self.orig_stdout
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
441 sys.stderr = self.orig_stderr
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
442
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
443 def test_usage(self):
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
444 try:
130
383b18bfcc95 Fake `sys.argv` for CLI tests.
cmlenz
parents: 129
diff changeset
445 self.cli.run(sys.argv)
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
446 self.fail('Expected SystemExit')
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
447 except SystemExit, e:
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
448 self.assertEqual(2, e.code)
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
449 self.assertEqual("""\
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
450 usage: pybabel command [options] [args]
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
451
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
452 pybabel: error: incorrect number of arguments
137
ade36d5897f4 Fix frontend tests on Python 2.5, where the case of some of the output of optparse usage has changed.
cmlenz
parents: 136
diff changeset
453 """, sys.stderr.getvalue().lower())
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
454
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
455 def test_help(self):
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
456 try:
130
383b18bfcc95 Fake `sys.argv` for CLI tests.
cmlenz
parents: 129
diff changeset
457 self.cli.run(sys.argv + ['--help'])
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
458 self.fail('Expected SystemExit')
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
459 except SystemExit, e:
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
460 self.assertEqual(0, e.code)
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
461 self.assertEqual("""\
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
462 usage: pybabel command [options] [args]
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
463
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
464 options:
187
d3bde66ac8a9 Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents: 183
diff changeset
465 --version show program's version number and exit
d3bde66ac8a9 Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents: 183
diff changeset
466 -h, --help show this help message and exit
d3bde66ac8a9 Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents: 183
diff changeset
467 --list-locales print all known locales and exit
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
468 -v, --verbose print as much as possible
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
469 -q, --quiet print as little as possible
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
470
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
471 commands:
187
d3bde66ac8a9 Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents: 183
diff changeset
472 compile compile message catalogs to mo files
d3bde66ac8a9 Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents: 183
diff changeset
473 extract extract messages from source files and generate a pot file
d3bde66ac8a9 Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents: 183
diff changeset
474 init create new message catalogs from a pot file
d3bde66ac8a9 Add a command-line option that prints out all available locales. Closes #24.
cmlenz
parents: 183
diff changeset
475 update update existing message catalogs from a pot file
137
ade36d5897f4 Fix frontend tests on Python 2.5, where the case of some of the output of optparse usage has changed.
cmlenz
parents: 136
diff changeset
476 """, sys.stdout.getvalue().lower())
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
477
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
478 def test_extract_with_default_mapping(self):
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
479 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
480 try:
130
383b18bfcc95 Fake `sys.argv` for CLI tests.
cmlenz
parents: 129
diff changeset
481 self.cli.run(sys.argv + ['extract',
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
482 '--copyright-holder', 'FooBar, Inc.',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
483 '--msgid-bugs-address', 'bugs.address@email.tld',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
484 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
485 '-o', pot_file, os.path.join(self.datadir, 'project')])
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
486 except SystemExit, e:
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
487 self.assertEqual(0, e.code)
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
488 assert os.path.isfile(pot_file)
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
489 self.assertEqual(
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
490 r"""# Translations template for TestProject.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
491 # Copyright (C) %(year)s FooBar, Inc.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
492 # This file is distributed under the same license as the TestProject
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
493 # project.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
494 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
495 #
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
496 #, fuzzy
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
497 msgid ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
498 msgstr ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
499 "Project-Id-Version: TestProject 0.1\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
500 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
501 "POT-Creation-Date: %(date)s\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
502 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
503 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
504 "Language-Team: LANGUAGE <LL@li.org>\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
505 "MIME-Version: 1.0\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
506 "Content-Type: text/plain; charset=utf-8\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
507 "Content-Transfer-Encoding: 8bit\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
508 "Generated-By: Babel %(version)s\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
509
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
510 #. This will be a translator coment,
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
511 #. that will include several lines
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
512 #: project/file1.py:8
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
513 msgid "bar"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
514 msgstr ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
515
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
516 #: project/file2.py:9
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
517 msgid "foobar"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
518 msgid_plural "foobars"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
519 msgstr[0] ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
520 msgstr[1] ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
521
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
522 #: project/CVS/this_wont_normally_be_here.py:11
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
523 msgid "FooBar"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
524 msgid_plural "FooBars"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
525 msgstr[0] ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
526 msgstr[1] ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
527
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
528 """ % {'version': VERSION,
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
529 'year': time.strftime('%Y'),
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
530 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
531 tzinfo=LOCALTZ, locale='en')},
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
532 open(pot_file, 'U').read())
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
533
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
534 def test_extract_with_mapping_file(self):
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
535 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
536 try:
130
383b18bfcc95 Fake `sys.argv` for CLI tests.
cmlenz
parents: 129
diff changeset
537 self.cli.run(sys.argv + ['extract',
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
538 '--copyright-holder', 'FooBar, Inc.',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
539 '--msgid-bugs-address', 'bugs.address@email.tld',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
540 '--mapping', os.path.join(self.datadir, 'mapping.cfg'),
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
541 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
542 '-o', pot_file, os.path.join(self.datadir, 'project')])
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
543 except SystemExit, e:
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
544 self.assertEqual(0, e.code)
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
545 assert os.path.isfile(pot_file)
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
546 self.assertEqual(
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
547 r"""# Translations template for TestProject.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
548 # Copyright (C) %(year)s FooBar, Inc.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
549 # This file is distributed under the same license as the TestProject
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
550 # project.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
551 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
552 #
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
553 #, fuzzy
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
554 msgid ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
555 msgstr ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
556 "Project-Id-Version: TestProject 0.1\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
557 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
558 "POT-Creation-Date: %(date)s\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
559 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
560 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
561 "Language-Team: LANGUAGE <LL@li.org>\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
562 "MIME-Version: 1.0\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
563 "Content-Type: text/plain; charset=utf-8\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
564 "Content-Transfer-Encoding: 8bit\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
565 "Generated-By: Babel %(version)s\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
566
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
567 #. This will be a translator coment,
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
568 #. that will include several lines
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
569 #: project/file1.py:8
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
570 msgid "bar"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
571 msgstr ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
572
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
573 #: project/file2.py:9
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
574 msgid "foobar"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
575 msgid_plural "foobars"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
576 msgstr[0] ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
577 msgstr[1] ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
578
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
579 """ % {'version': VERSION,
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
580 'year': time.strftime('%Y'),
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
581 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
582 tzinfo=LOCALTZ, locale='en')},
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
583 open(pot_file, 'U').read())
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
584
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
585 def test_init_with_output_dir(self):
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
586 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
587 'LC_MESSAGES', 'messages.po')
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
588 try:
130
383b18bfcc95 Fake `sys.argv` for CLI tests.
cmlenz
parents: 129
diff changeset
589 self.cli.run(sys.argv + ['init',
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
590 '--locale', 'en_US',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
591 '-d', os.path.join(self.datadir, 'project', 'i18n'),
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
592 '-i', os.path.join(self.datadir, 'project', 'i18n',
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
593 'messages.pot')])
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
594 except SystemExit, e:
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
595 self.assertEqual(0, e.code)
173
6655bb6ae28d pot_file is a typo here
pjenvey
parents: 162
diff changeset
596 assert os.path.isfile(po_file)
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
597 self.assertEqual(
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
598 r"""# English (United States) translations for TestProject.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
599 # Copyright (C) 2007 FooBar, Inc.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
600 # This file is distributed under the same license as the TestProject
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
601 # project.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
602 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
603 #
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
604 #, fuzzy
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
605 msgid ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
606 msgstr ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
607 "Project-Id-Version: TestProject 0.1\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
608 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
609 "POT-Creation-Date: 2007-04-01 15:30+0200\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
610 "PO-Revision-Date: %(date)s\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
611 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
612 "Language-Team: en_US <LL@li.org>\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
613 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
614 "MIME-Version: 1.0\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
615 "Content-Type: text/plain; charset=utf-8\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
616 "Content-Transfer-Encoding: 8bit\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
617 "Generated-By: Babel %(version)s\n"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
618
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
619 #. This will be a translator coment,
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
620 #. that will include several lines
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
621 #: project/file1.py:8
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
622 msgid "bar"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
623 msgstr ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
624
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
625 #: project/file2.py:9
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
626 msgid "foobar"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
627 msgid_plural "foobars"
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
628 msgstr[0] ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
629 msgstr[1] ""
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
630
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
631 """ % {'version': VERSION,
136
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
632 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
9e3d2b227ec3 More fixes for Windows compatibility:
cmlenz
parents: 130
diff changeset
633 tzinfo=LOCALTZ, locale='en')},
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
634 open(po_file, 'U').read())
179
6138ea7ef7a8 * 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: 178
diff changeset
635
178
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
636 def test_compile_catalog(self):
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
637 po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE',
178
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
638 'LC_MESSAGES', 'messages.po')
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
639 mo_file = po_file.replace('.po', '.mo')
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
640 self.cli.run(sys.argv + ['compile',
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
641 '--locale', 'de_DE',
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
642 '-d', os.path.join(self.datadir, 'project', 'i18n')])
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
643 assert not os.path.isfile(mo_file), 'Expected no file at %r' % mo_file
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
644 self.assertEqual("""\
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
645 catalog %r is marked as fuzzy, skipping
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
646 """ % (po_file), sys.stderr.getvalue())
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
647
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
648 def test_compile_fuzzy_catalog(self):
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
649 po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE',
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
650 'LC_MESSAGES', 'messages.po')
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
651 mo_file = po_file.replace('.po', '.mo')
178
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
652 try:
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
653 self.cli.run(sys.argv + ['compile',
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
654 '--locale', 'de_DE', '--use-fuzzy',
178
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
655 '-d', os.path.join(self.datadir, 'project', 'i18n')])
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
656 assert os.path.isfile(mo_file)
178
51fffa0a51ac Added tests for the `compile` command of `babel` binary and `messages_non_fuzzy.pot` to further test `read_po` fuzzy bit header parsing.
palgarvio
parents: 173
diff changeset
657 self.assertEqual("""\
179
6138ea7ef7a8 * 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: 178
diff changeset
658 compiling catalog %r to %r
234
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
659 """ % (po_file, mo_file), sys.stderr.getvalue())
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
660 finally:
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
661 if os.path.isfile(mo_file):
541b6d630575 Use logging module for output from CLI frontend.
cmlenz
parents: 187
diff changeset
662 os.unlink(mo_file)
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
663
179
6138ea7ef7a8 * 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: 178
diff changeset
664
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
665 def suite():
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
666 suite = unittest.TestSuite()
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
667 suite.addTest(doctest.DocTestSuite(frontend))
162
661cb602781d Add MO file generation. Closes #21.
cmlenz
parents: 137
diff changeset
668 suite.addTest(unittest.makeSuite(CompileCatalogTestCase))
119
c84f629da9de Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 117
diff changeset
669 suite.addTest(unittest.makeSuite(ExtractMessagesTestCase))
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
670 suite.addTest(unittest.makeSuite(InitCatalogTestCase))
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 179
diff changeset
671 suite.addTest(unittest.makeSuite(InitCatalogNonFuzzyTestCase))
129
d6aef0675953 Add a couple of CLI tests.
cmlenz
parents: 123
diff changeset
672 suite.addTest(unittest.makeSuite(CommandLineInterfaceTestCase))
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
673 return suite
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
674
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
675 if __name__ == '__main__':
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
676 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software