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