annotate babel/messages/tests/frontend.py @ 176:7a3073eab108 trunk

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