Mercurial > babel > old > babel-test
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 | 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 | 20 import shutil |
127 | 21 from StringIO import StringIO |
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 | 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 | 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 | 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 | 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 | 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 | 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 | 77 |
78 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
79 assert os.path.isfile(pot_file) | |
80 | |
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 | 122 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
123 tzinfo=LOCALTZ, locale='en')}, | |
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 | 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 | 135 |
136 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
137 assert os.path.isfile(pot_file) | |
138 | |
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 | 174 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
175 tzinfo=LOCALTZ, locale='en')}, | |
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 | 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 | 192 |
193 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
194 assert os.path.isfile(pot_file) | |
195 | |
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 | 231 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
232 tzinfo=LOCALTZ, locale='en')}, | |
233 open(pot_file, 'U').read()) | |
120 | 234 |
235 | |
236 class NewCatalogTestCase(unittest.TestCase): | |
237 | |
238 def setUp(self): | |
239 self.olddir = os.getcwd() | |
240 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | |
241 os.chdir(self.datadir) | |
242 _global_log.threshold = 5 # shut up distutils logging | |
243 | |
244 self.dist = Distribution(dict( | |
245 name='TestProject', | |
246 version='0.1', | |
247 packages=['project'] | |
248 )) | |
249 self.cmd = frontend.new_catalog(self.dist) | |
250 self.cmd.initialize_options() | |
251 | |
252 def tearDown(self): | |
253 locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US') | |
254 if os.path.isdir(locale_dir): | |
255 shutil.rmtree(locale_dir) | |
256 | |
257 os.chdir(self.olddir) | |
258 | |
259 def test_no_input_file(self): | |
260 self.cmd.locale = 'en_US' | |
261 self.cmd.output_file = 'dummy' | |
262 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
263 | |
264 def test_no_locale(self): | |
265 self.cmd.input_file = 'dummy' | |
266 self.cmd.output_file = 'dummy' | |
267 self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) | |
268 | |
121 | 269 def test_with_output_dir(self): |
120 | 270 self.cmd.input_file = 'project/i18n/messages.pot' |
271 self.cmd.locale = 'en_US' | |
272 self.cmd.output_dir = 'project/i18n' | |
273 | |
274 self.cmd.finalize_options() | |
275 self.cmd.run() | |
276 | |
277 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
278 'LC_MESSAGES', 'messages.po') | |
279 assert os.path.isfile(po_file) | |
280 | |
281 self.assertEqual( | |
282 r"""# English (United States) translations for TestProject. | |
283 # Copyright (C) 2007 FooBar, Inc. | |
284 # This file is distributed under the same license as the TestProject | |
285 # project. | |
286 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
287 # | |
288 #, fuzzy | |
289 msgid "" | |
290 msgstr "" | |
291 "Project-Id-Version: TestProject 0.1\n" | |
292 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
293 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
294 "PO-Revision-Date: %(date)s\n" | |
295 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
296 "Language-Team: en_US <LL@li.org>\n" | |
297 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
298 "MIME-Version: 1.0\n" | |
299 "Content-Type: text/plain; charset=utf-8\n" | |
300 "Content-Transfer-Encoding: 8bit\n" | |
301 "Generated-By: Babel %(version)s\n" | |
302 | |
303 #. This will be a translator coment, | |
304 #. that will include several lines | |
305 #: project/file1.py:8 | |
306 msgid "bar" | |
307 msgstr "" | |
308 | |
309 #: project/file2.py:9 | |
310 msgid "foobar" | |
311 msgid_plural "foobars" | |
312 msgstr[0] "" | |
313 msgstr[1] "" | |
314 | |
315 """ % {'version': VERSION, | |
134 | 316 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
317 tzinfo=LOCALTZ, locale='en')}, | |
120 | 318 open(po_file, 'U').read()) |
12
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
diff
changeset
|
319 |
115 | 320 |
127 | 321 class CommandLineInterfaceTestCase(unittest.TestCase): |
322 | |
323 def setUp(self): | |
324 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | |
128 | 325 self.orig_argv = sys.argv |
127 | 326 self.orig_stdout = sys.stdout |
327 self.orig_stderr = sys.stderr | |
128 | 328 sys.argv = ['babel'] |
127 | 329 sys.stdout = StringIO() |
330 sys.stderr = StringIO() | |
331 self.cli = frontend.CommandLineInterface() | |
332 | |
333 def tearDown(self): | |
128 | 334 sys.argv = self.orig_argv |
127 | 335 sys.stdout = self.orig_stdout |
336 sys.stderr = self.orig_stderr | |
337 | |
338 def test_usage(self): | |
339 try: | |
128 | 340 self.cli.run(sys.argv) |
127 | 341 self.fail('Expected SystemExit') |
342 except SystemExit, e: | |
343 self.assertEqual(2, e.code) | |
344 self.assertEqual("""\ | |
128 | 345 usage: babel command [options] [args] |
127 | 346 |
128 | 347 babel: error: incorrect number of arguments |
127 | 348 """, sys.stderr.getvalue()) |
349 | |
350 def test_help(self): | |
351 try: | |
128 | 352 self.cli.run(sys.argv + ['--help']) |
127 | 353 self.fail('Expected SystemExit') |
354 except SystemExit, e: | |
355 self.assertEqual(0, e.code) | |
356 self.assertEqual("""\ | |
128 | 357 usage: babel command [options] [args] |
127 | 358 |
359 options: | |
360 --version show program's version number and exit | |
361 -h, --help show this help message and exit | |
362 | |
363 commands: | |
364 extract extract messages from source files and generate a POT file | |
365 init create new message catalogs from a template | |
366 """, sys.stdout.getvalue()) | |
367 | |
368 def test_extract_with_default_mapping(self): | |
369 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
370 try: | |
128 | 371 self.cli.run(sys.argv + ['extract', |
127 | 372 '--copyright-holder', 'FooBar, Inc.', |
373 '--msgid-bugs-address', 'bugs.address@email.tld', | |
374 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | |
375 '-o', pot_file, os.path.join(self.datadir, 'project')]) | |
376 except SystemExit, e: | |
377 self.assertEqual(0, e.code) | |
378 assert os.path.isfile(pot_file) | |
379 self.assertEqual( | |
380 r"""# Translations template for TestProject. | |
381 # Copyright (C) %(year)s FooBar, Inc. | |
382 # This file is distributed under the same license as the TestProject | |
383 # project. | |
384 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
385 # | |
386 #, fuzzy | |
387 msgid "" | |
388 msgstr "" | |
389 "Project-Id-Version: TestProject 0.1\n" | |
390 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
391 "POT-Creation-Date: %(date)s\n" | |
392 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
393 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
394 "Language-Team: LANGUAGE <LL@li.org>\n" | |
395 "MIME-Version: 1.0\n" | |
396 "Content-Type: text/plain; charset=utf-8\n" | |
397 "Content-Transfer-Encoding: 8bit\n" | |
398 "Generated-By: Babel %(version)s\n" | |
399 | |
400 #. This will be a translator coment, | |
401 #. that will include several lines | |
402 #: project/file1.py:8 | |
403 msgid "bar" | |
404 msgstr "" | |
405 | |
406 #: project/file2.py:9 | |
407 msgid "foobar" | |
408 msgid_plural "foobars" | |
409 msgstr[0] "" | |
410 msgstr[1] "" | |
411 | |
412 #: project/CVS/this_wont_normally_be_here.py:11 | |
413 msgid "FooBar" | |
414 msgid_plural "FooBars" | |
415 msgstr[0] "" | |
416 msgstr[1] "" | |
417 | |
418 """ % {'version': VERSION, | |
419 'year': time.strftime('%Y'), | |
134 | 420 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
421 tzinfo=LOCALTZ, locale='en')}, | |
422 open(pot_file, 'U').read()) | |
127 | 423 |
424 def test_extract_with_mapping_file(self): | |
425 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | |
426 try: | |
128 | 427 self.cli.run(sys.argv + ['extract', |
127 | 428 '--copyright-holder', 'FooBar, Inc.', |
429 '--msgid-bugs-address', 'bugs.address@email.tld', | |
430 '--mapping', os.path.join(self.datadir, 'mapping.cfg'), | |
431 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | |
432 '-o', pot_file, os.path.join(self.datadir, 'project')]) | |
433 except SystemExit, e: | |
434 self.assertEqual(0, e.code) | |
435 assert os.path.isfile(pot_file) | |
436 self.assertEqual( | |
437 r"""# Translations template for TestProject. | |
438 # Copyright (C) %(year)s FooBar, Inc. | |
439 # This file is distributed under the same license as the TestProject | |
440 # project. | |
441 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | |
442 # | |
443 #, fuzzy | |
444 msgid "" | |
445 msgstr "" | |
446 "Project-Id-Version: TestProject 0.1\n" | |
447 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
448 "POT-Creation-Date: %(date)s\n" | |
449 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
450 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
451 "Language-Team: LANGUAGE <LL@li.org>\n" | |
452 "MIME-Version: 1.0\n" | |
453 "Content-Type: text/plain; charset=utf-8\n" | |
454 "Content-Transfer-Encoding: 8bit\n" | |
455 "Generated-By: Babel %(version)s\n" | |
456 | |
457 #. This will be a translator coment, | |
458 #. that will include several lines | |
459 #: project/file1.py:8 | |
460 msgid "bar" | |
461 msgstr "" | |
462 | |
463 #: project/file2.py:9 | |
464 msgid "foobar" | |
465 msgid_plural "foobars" | |
466 msgstr[0] "" | |
467 msgstr[1] "" | |
468 | |
469 """ % {'version': VERSION, | |
470 'year': time.strftime('%Y'), | |
134 | 471 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
472 tzinfo=LOCALTZ, locale='en')}, | |
473 open(pot_file, 'U').read()) | |
127 | 474 |
475 def test_init_with_output_dir(self): | |
476 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
477 'LC_MESSAGES', 'messages.po') | |
478 try: | |
128 | 479 self.cli.run(sys.argv + ['init', |
127 | 480 '--locale', 'en_US', |
481 '-d', os.path.join(self.datadir, 'project', 'i18n'), | |
482 '-i', os.path.join(self.datadir, 'project', 'i18n', | |
483 'messages.pot')]) | |
484 except SystemExit, e: | |
485 self.assertEqual(0, e.code) | |
486 assert os.path.isfile(pot_file) | |
487 self.assertEqual( | |
488 r"""# English (United States) translations for TestProject. | |
489 # Copyright (C) 2007 FooBar, Inc. | |
490 # This file is distributed under the same license as the TestProject | |
491 # project. | |
492 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
493 # | |
494 #, fuzzy | |
495 msgid "" | |
496 msgstr "" | |
497 "Project-Id-Version: TestProject 0.1\n" | |
498 "Report-Msgid-Bugs-To: bugs.address@email.tld\n" | |
499 "POT-Creation-Date: 2007-04-01 15:30+0200\n" | |
500 "PO-Revision-Date: %(date)s\n" | |
501 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
502 "Language-Team: en_US <LL@li.org>\n" | |
503 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
504 "MIME-Version: 1.0\n" | |
505 "Content-Type: text/plain; charset=utf-8\n" | |
506 "Content-Transfer-Encoding: 8bit\n" | |
507 "Generated-By: Babel %(version)s\n" | |
508 | |
509 #. This will be a translator coment, | |
510 #. that will include several lines | |
511 #: project/file1.py:8 | |
512 msgid "bar" | |
513 msgstr "" | |
514 | |
515 #: project/file2.py:9 | |
516 msgid "foobar" | |
517 msgid_plural "foobars" | |
518 msgstr[0] "" | |
519 msgstr[1] "" | |
520 | |
521 """ % {'version': VERSION, | |
134 | 522 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
523 tzinfo=LOCALTZ, locale='en')}, | |
127 | 524 open(po_file, 'U').read()) |
525 | |
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 | 531 suite.addTest(unittest.makeSuite(NewCatalogTestCase)) |
127 | 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') |