annotate babel/messages/tests/frontend.py @ 134:60565dc8495d

More fixes for Windows compatibility: * normalize path segment separator to "/" * use `dates.format_date` also to set the expected date-strings in the frontend tests.
author cmlenz
date Tue, 19 Jun 2007 12:13:46 +0000
parents 7b807415c3ff
children f22177653f86
rev   line source
12
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
2 #
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
3 # Copyright (C) 2007 Edgewall Software
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
4 # All rights reserved.
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
5 #
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
9 #
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
13
134
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
14 from datetime import datetime
117
41506e62701f 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
41506e62701f 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
41506e62701f 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
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
18 import doctest
117
41506e62701f 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
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
20 import shutil
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
21 from StringIO import StringIO
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
22 import sys
117
41506e62701f 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
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
24 import unittest
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
25
114
5ec3364f250a 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
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
27 from babel.dates import format_datetime
117
41506e62701f 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
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
29 from babel.util import LOCALTZ
114
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
30
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
31
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
32 class ExtractMessagesTestCase(unittest.TestCase):
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
33
114
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
34 def setUp(self):
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
35 self.olddir = os.getcwd()
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
36 self.datadir = os.path.join(os.path.dirname(__file__), 'data')
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
37 os.chdir(self.datadir)
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
38 _global_log.threshold = 5 # shut up distutils logging
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
39
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
40 self.dist = Distribution(dict(
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
41 name='TestProject',
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
42 version='0.1',
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
43 packages=['project']
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
44 ))
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
45 self.cmd = frontend.extract_messages(self.dist)
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
46 self.cmd.initialize_options()
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
47
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
48 def tearDown(self):
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
49 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
50 if os.path.isfile(pot_file):
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
51 os.unlink(pot_file)
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
52
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
53 os.chdir(self.olddir)
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
54
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
55 def test_neither_default_nor_custom_keywords(self):
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
56 self.cmd.output_file = 'dummy'
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
57 self.cmd.no_default_keywords = True
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
58 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
59
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
60 def test_no_output_file_specified(self):
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
61 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
62
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
63 def test_both_sort_output_and_sort_by_file(self):
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
64 self.cmd.output_file = 'dummy'
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
65 self.cmd.sort_output = True
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
66 self.cmd.sort_by_file = True
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
67 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
68
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
69 def test_extraction_with_default_mapping(self):
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
70 self.cmd.copyright_holder = 'FooBar, Inc.'
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
71 self.cmd.msgid_bugs_address = 'bugs.address@email.tld'
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
72 self.cmd.output_file = 'project/i18n/temp.pot'
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
73 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:'
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
74
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
75 self.cmd.finalize_options()
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
76 self.cmd.run()
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
77
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
78 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
79 assert os.path.isfile(pot_file)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
80
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
81 self.assertEqual(
114
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
82 r"""# Translations template for TestProject.
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
83 # Copyright (C) %(year)s FooBar, Inc.
114
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
84 # This file is distributed under the same license as the TestProject
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
85 # project.
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
86 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
87 #
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
88 #, fuzzy
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
89 msgid ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
90 msgstr ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
91 "Project-Id-Version: TestProject 0.1\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
92 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
93 "POT-Creation-Date: %(date)s\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
94 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
95 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
96 "Language-Team: LANGUAGE <LL@li.org>\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
97 "MIME-Version: 1.0\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
98 "Content-Type: text/plain; charset=utf-8\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
99 "Content-Transfer-Encoding: 8bit\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
100 "Generated-By: Babel %(version)s\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
101
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
102 #. This will be a translator coment,
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
103 #. that will include several lines
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
104 #: project/file1.py:8
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
105 msgid "bar"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
106 msgstr ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
107
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
108 #: project/file2.py:9
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
109 msgid "foobar"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
110 msgid_plural "foobars"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
111 msgstr[0] ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
112 msgstr[1] ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
113
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
114 #: project/CVS/this_wont_normally_be_here.py:11
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
115 msgid "FooBar"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
116 msgid_plural "FooBars"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
117 msgstr[0] ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
118 msgstr[1] ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
119
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
120 """ % {'version': VERSION,
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
121 'year': time.strftime('%Y'),
134
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
122 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
123 tzinfo=LOCALTZ, locale='en')},
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
124 open(pot_file, 'U').read())
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
125
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
126 def test_extraction_with_mapping_file(self):
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
127 self.cmd.copyright_holder = 'FooBar, Inc.'
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
128 self.cmd.msgid_bugs_address = 'bugs.address@email.tld'
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
129 self.cmd.mapping_file = 'mapping.cfg'
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
130 self.cmd.output_file = 'project/i18n/temp.pot'
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
131 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:'
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
132
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
133 self.cmd.finalize_options()
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
134 self.cmd.run()
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
135
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
136 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
137 assert os.path.isfile(pot_file)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
138
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
139 self.assertEqual(
114
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
140 r"""# Translations template for TestProject.
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
141 # Copyright (C) %(year)s FooBar, Inc.
114
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
142 # This file is distributed under the same license as the TestProject
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
143 # project.
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
144 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
145 #
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
146 #, fuzzy
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
147 msgid ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
148 msgstr ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
149 "Project-Id-Version: TestProject 0.1\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
150 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
151 "POT-Creation-Date: %(date)s\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
152 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
153 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
154 "Language-Team: LANGUAGE <LL@li.org>\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
155 "MIME-Version: 1.0\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
156 "Content-Type: text/plain; charset=utf-8\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
157 "Content-Transfer-Encoding: 8bit\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
158 "Generated-By: Babel %(version)s\n"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
159
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
160 #. This will be a translator coment,
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
161 #. that will include several lines
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
162 #: project/file1.py:8
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
163 msgid "bar"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
164 msgstr ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
165
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
166 #: project/file2.py:9
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
167 msgid "foobar"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
168 msgid_plural "foobars"
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
169 msgstr[0] ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
170 msgstr[1] ""
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
171
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
172 """ % {'version': VERSION,
5ec3364f250a Added some minor distutils frontend tests, corrected and moved mapping.cfg to the appropriate place.
palgarvio
parents: 54
diff changeset
173 'year': time.strftime('%Y'),
134
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
174 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
175 tzinfo=LOCALTZ, locale='en')},
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
176 open(pot_file, 'U').read())
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
177
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
178 def test_extraction_with_mapping_dict(self):
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
179 self.dist.message_extractors = {
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
180 'project': [
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
181 ('**/CVS/**.*', 'ignore', None),
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
182 ('**.py', 'python', None),
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
183 ]
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
184 }
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
185 self.cmd.copyright_holder = 'FooBar, Inc.'
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
186 self.cmd.msgid_bugs_address = 'bugs.address@email.tld'
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
187 self.cmd.output_file = 'project/i18n/temp.pot'
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
188 self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:'
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
189
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
190 self.cmd.finalize_options()
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
191 self.cmd.run()
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
192
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
193 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
194 assert os.path.isfile(pot_file)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
195
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
196 self.assertEqual(
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
197 r"""# Translations template for TestProject.
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
198 # Copyright (C) %(year)s FooBar, Inc.
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
199 # This file is distributed under the same license as the TestProject
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
200 # project.
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
201 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
202 #
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
203 #, fuzzy
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
204 msgid ""
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
205 msgstr ""
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
206 "Project-Id-Version: TestProject 0.1\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
207 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
208 "POT-Creation-Date: %(date)s\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
209 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
210 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
211 "Language-Team: LANGUAGE <LL@li.org>\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
212 "MIME-Version: 1.0\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
213 "Content-Type: text/plain; charset=utf-8\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
214 "Content-Transfer-Encoding: 8bit\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
215 "Generated-By: Babel %(version)s\n"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
216
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
217 #. This will be a translator coment,
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
218 #. that will include several lines
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
219 #: project/file1.py:8
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
220 msgid "bar"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
221 msgstr ""
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
222
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
223 #: project/file2.py:9
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
224 msgid "foobar"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
225 msgid_plural "foobars"
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
226 msgstr[0] ""
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
227 msgstr[1] ""
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
228
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
229 """ % {'version': VERSION,
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
230 'year': time.strftime('%Y'),
134
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
231 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
232 tzinfo=LOCALTZ, locale='en')},
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
233 open(pot_file, 'U').read())
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
234
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
235
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
236 class NewCatalogTestCase(unittest.TestCase):
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
237
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
238 def setUp(self):
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
239 self.olddir = os.getcwd()
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
240 self.datadir = os.path.join(os.path.dirname(__file__), 'data')
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
241 os.chdir(self.datadir)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
242 _global_log.threshold = 5 # shut up distutils logging
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
243
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
244 self.dist = Distribution(dict(
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
245 name='TestProject',
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
246 version='0.1',
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
247 packages=['project']
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
248 ))
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
249 self.cmd = frontend.new_catalog(self.dist)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
250 self.cmd.initialize_options()
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
251
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
252 def tearDown(self):
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
253 locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US')
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
254 if os.path.isdir(locale_dir):
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
255 shutil.rmtree(locale_dir)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
256
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
257 os.chdir(self.olddir)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
258
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
259 def test_no_input_file(self):
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
260 self.cmd.locale = 'en_US'
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
261 self.cmd.output_file = 'dummy'
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
262 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
263
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
264 def test_no_locale(self):
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
265 self.cmd.input_file = 'dummy'
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
266 self.cmd.output_file = 'dummy'
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
267 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
268
121
78a9033b6839 Fix parsing of timezone in POT creation date.
cmlenz
parents: 120
diff changeset
269 def test_with_output_dir(self):
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
270 self.cmd.input_file = 'project/i18n/messages.pot'
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
271 self.cmd.locale = 'en_US'
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
272 self.cmd.output_dir = 'project/i18n'
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
273
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
274 self.cmd.finalize_options()
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
275 self.cmd.run()
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
276
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
277 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US',
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
278 'LC_MESSAGES', 'messages.po')
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
279 assert os.path.isfile(po_file)
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
280
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
281 self.assertEqual(
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
282 r"""# English (United States) translations for TestProject.
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
283 # Copyright (C) 2007 FooBar, Inc.
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
284 # This file is distributed under the same license as the TestProject
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
285 # project.
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
286 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
287 #
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
288 #, fuzzy
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
289 msgid ""
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
290 msgstr ""
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
291 "Project-Id-Version: TestProject 0.1\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
292 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
293 "POT-Creation-Date: 2007-04-01 15:30+0200\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
294 "PO-Revision-Date: %(date)s\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
295 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
296 "Language-Team: en_US <LL@li.org>\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
297 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
298 "MIME-Version: 1.0\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
299 "Content-Type: text/plain; charset=utf-8\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
300 "Content-Transfer-Encoding: 8bit\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
301 "Generated-By: Babel %(version)s\n"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
302
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
303 #. This will be a translator coment,
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
304 #. that will include several lines
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
305 #: project/file1.py:8
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
306 msgid "bar"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
307 msgstr ""
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
308
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
309 #: project/file2.py:9
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
310 msgid "foobar"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
311 msgid_plural "foobars"
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
312 msgstr[0] ""
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
313 msgstr[1] ""
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
314
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
315 """ % {'version': VERSION,
134
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
316 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
317 tzinfo=LOCALTZ, locale='en')},
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
318 open(po_file, 'U').read())
12
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
319
115
9703a0ad56bd Added new logo.
cmlenz
parents: 114
diff changeset
320
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
321 class CommandLineInterfaceTestCase(unittest.TestCase):
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
322
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
323 def setUp(self):
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
324 self.datadir = os.path.join(os.path.dirname(__file__), 'data')
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
325 self.orig_argv = sys.argv
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
326 self.orig_stdout = sys.stdout
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
327 self.orig_stderr = sys.stderr
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
328 sys.argv = ['babel']
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
329 sys.stdout = StringIO()
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
330 sys.stderr = StringIO()
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
331 self.cli = frontend.CommandLineInterface()
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
332
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
333 def tearDown(self):
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
334 sys.argv = self.orig_argv
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
335 sys.stdout = self.orig_stdout
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
336 sys.stderr = self.orig_stderr
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
337
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
338 def test_usage(self):
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
339 try:
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
340 self.cli.run(sys.argv)
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
341 self.fail('Expected SystemExit')
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
342 except SystemExit, e:
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
343 self.assertEqual(2, e.code)
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
344 self.assertEqual("""\
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
345 usage: babel command [options] [args]
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
346
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
347 babel: error: incorrect number of arguments
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
348 """, sys.stderr.getvalue())
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
349
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
350 def test_help(self):
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
351 try:
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
352 self.cli.run(sys.argv + ['--help'])
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
353 self.fail('Expected SystemExit')
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
354 except SystemExit, e:
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
355 self.assertEqual(0, e.code)
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
356 self.assertEqual("""\
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
357 usage: babel command [options] [args]
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
358
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
359 options:
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
360 --version show program's version number and exit
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
361 -h, --help show this help message and exit
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
362
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
363 commands:
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
364 extract extract messages from source files and generate a POT file
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
365 init create new message catalogs from a template
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
366 """, sys.stdout.getvalue())
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
367
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
368 def test_extract_with_default_mapping(self):
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
369 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
370 try:
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
371 self.cli.run(sys.argv + ['extract',
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
372 '--copyright-holder', 'FooBar, Inc.',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
373 '--msgid-bugs-address', 'bugs.address@email.tld',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
374 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
375 '-o', pot_file, os.path.join(self.datadir, 'project')])
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
376 except SystemExit, e:
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
377 self.assertEqual(0, e.code)
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
378 assert os.path.isfile(pot_file)
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
379 self.assertEqual(
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
380 r"""# Translations template for TestProject.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
381 # Copyright (C) %(year)s FooBar, Inc.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
382 # This file is distributed under the same license as the TestProject
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
383 # project.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
384 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
385 #
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
386 #, fuzzy
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
387 msgid ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
388 msgstr ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
389 "Project-Id-Version: TestProject 0.1\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
390 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
391 "POT-Creation-Date: %(date)s\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
392 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
393 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
394 "Language-Team: LANGUAGE <LL@li.org>\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
395 "MIME-Version: 1.0\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
396 "Content-Type: text/plain; charset=utf-8\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
397 "Content-Transfer-Encoding: 8bit\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
398 "Generated-By: Babel %(version)s\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
399
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
400 #. This will be a translator coment,
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
401 #. that will include several lines
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
402 #: project/file1.py:8
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
403 msgid "bar"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
404 msgstr ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
405
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
406 #: project/file2.py:9
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
407 msgid "foobar"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
408 msgid_plural "foobars"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
409 msgstr[0] ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
410 msgstr[1] ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
411
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
412 #: project/CVS/this_wont_normally_be_here.py:11
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
413 msgid "FooBar"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
414 msgid_plural "FooBars"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
415 msgstr[0] ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
416 msgstr[1] ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
417
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
418 """ % {'version': VERSION,
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
419 'year': time.strftime('%Y'),
134
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
420 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
421 tzinfo=LOCALTZ, locale='en')},
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
422 open(pot_file, 'U').read())
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
423
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
424 def test_extract_with_mapping_file(self):
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
425 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot')
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
426 try:
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
427 self.cli.run(sys.argv + ['extract',
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
428 '--copyright-holder', 'FooBar, Inc.',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
429 '--msgid-bugs-address', 'bugs.address@email.tld',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
430 '--mapping', os.path.join(self.datadir, 'mapping.cfg'),
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
431 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
432 '-o', pot_file, os.path.join(self.datadir, 'project')])
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
433 except SystemExit, e:
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
434 self.assertEqual(0, e.code)
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
435 assert os.path.isfile(pot_file)
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
436 self.assertEqual(
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
437 r"""# Translations template for TestProject.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
438 # Copyright (C) %(year)s FooBar, Inc.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
439 # This file is distributed under the same license as the TestProject
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
440 # project.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
441 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
442 #
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
443 #, fuzzy
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
444 msgid ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
445 msgstr ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
446 "Project-Id-Version: TestProject 0.1\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
447 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
448 "POT-Creation-Date: %(date)s\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
449 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
450 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
451 "Language-Team: LANGUAGE <LL@li.org>\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
452 "MIME-Version: 1.0\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
453 "Content-Type: text/plain; charset=utf-8\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
454 "Content-Transfer-Encoding: 8bit\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
455 "Generated-By: Babel %(version)s\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
456
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
457 #. This will be a translator coment,
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
458 #. that will include several lines
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
459 #: project/file1.py:8
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
460 msgid "bar"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
461 msgstr ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
462
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
463 #: project/file2.py:9
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
464 msgid "foobar"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
465 msgid_plural "foobars"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
466 msgstr[0] ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
467 msgstr[1] ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
468
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
469 """ % {'version': VERSION,
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
470 'year': time.strftime('%Y'),
134
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
471 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
472 tzinfo=LOCALTZ, locale='en')},
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
473 open(pot_file, 'U').read())
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
474
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
475 def test_init_with_output_dir(self):
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
476 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
477 'LC_MESSAGES', 'messages.po')
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
478 try:
128
7b807415c3ff Fake `sys.argv` for CLI tests.
cmlenz
parents: 127
diff changeset
479 self.cli.run(sys.argv + ['init',
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
480 '--locale', 'en_US',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
481 '-d', os.path.join(self.datadir, 'project', 'i18n'),
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
482 '-i', os.path.join(self.datadir, 'project', 'i18n',
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
483 'messages.pot')])
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
484 except SystemExit, e:
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
485 self.assertEqual(0, e.code)
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
486 assert os.path.isfile(pot_file)
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
487 self.assertEqual(
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
488 r"""# English (United States) translations for TestProject.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
489 # Copyright (C) 2007 FooBar, Inc.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
490 # This file is distributed under the same license as the TestProject
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
491 # project.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
492 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
493 #
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
494 #, fuzzy
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
495 msgid ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
496 msgstr ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
497 "Project-Id-Version: TestProject 0.1\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
498 "Report-Msgid-Bugs-To: bugs.address@email.tld\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
499 "POT-Creation-Date: 2007-04-01 15:30+0200\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
500 "PO-Revision-Date: %(date)s\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
501 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
502 "Language-Team: en_US <LL@li.org>\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
503 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
504 "MIME-Version: 1.0\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
505 "Content-Type: text/plain; charset=utf-8\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
506 "Content-Transfer-Encoding: 8bit\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
507 "Generated-By: Babel %(version)s\n"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
508
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
509 #. This will be a translator coment,
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
510 #. that will include several lines
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
511 #: project/file1.py:8
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
512 msgid "bar"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
513 msgstr ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
514
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
515 #: project/file2.py:9
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
516 msgid "foobar"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
517 msgid_plural "foobars"
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
518 msgstr[0] ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
519 msgstr[1] ""
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
520
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
521 """ % {'version': VERSION,
134
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
522 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
60565dc8495d More fixes for Windows compatibility:
cmlenz
parents: 128
diff changeset
523 tzinfo=LOCALTZ, locale='en')},
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
524 open(po_file, 'U').read())
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
525
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
526
12
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
527 def suite():
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
528 suite = unittest.TestSuite()
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
529 suite.addTest(doctest.DocTestSuite(frontend))
117
41506e62701f Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents: 115
diff changeset
530 suite.addTest(unittest.makeSuite(ExtractMessagesTestCase))
120
733cca7ff6a5 Added tests for `new_catalog` distutils command.
cmlenz
parents: 117
diff changeset
531 suite.addTest(unittest.makeSuite(NewCatalogTestCase))
127
0f3a08b1c7ae Add a couple of CLI tests.
cmlenz
parents: 121
diff changeset
532 suite.addTest(unittest.makeSuite(CommandLineInterfaceTestCase))
12
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
533 return suite
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
534
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
535 if __name__ == '__main__':
a2c54ef107c2 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff changeset
536 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software