Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / test / gettext / POInit / UserExamples.py
bloba701851f73232ab0d619e2bc1ade0978ddf0c145
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Make sure, that the examples given in user guide all work.
29 """
31 import TestSCons
33 test = TestSCons.TestSCons()
35 if not test.where_is('msginit'):
36 test.skip_test("Could not find 'msginit'; skipping test(s)\n")
38 pot_contents = """\
39 # SOME DESCRIPTIVE TITLE.
40 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
41 # This file is distributed under the same license as the PACKAGE package.
42 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
44 #, fuzzy
45 msgid ""
46 msgstr ""
47 "Project-Id-Version: PACKAGE VERSION\\n"
48 "Report-Msgid-Bugs-To: \\n"
49 "POT-Creation-Date: 2012-05-27 00:35+0200\\n"
50 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
51 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
52 "Language-Team: LANGUAGE <LL@li.org>\\n"
53 "Language: \\n"
54 "MIME-Version: 1.0\\n"
55 "Content-Type: text/plain; charset=CHARSET\\n"
56 "Content-Transfer-Encoding: 8bit\\n"
58 #: a.cpp:1
59 msgid "Hello from a.cpp"
60 msgstr ""
61 """
63 ###############################################################################
64 # POInit: Example 1
65 ###############################################################################
66 test.subdir(['ex1'])
67 test.write( ['ex1', 'SConstruct'],
68 """
69 env = Environment( tools = ["default", "msginit"] )
70 env['POAUTOINIT'] = 1
71 env.POInit(['en','pl']) # messages.pot --&gt; [en.po, pl.po]
72 """)
74 test.write(['ex1', 'messages.pot'], pot_contents)
76 # NOTE: msginit(1) prints all its messages to stderr, we must ignore them,
77 # So, stderr=None is crucial here. It is no point to match stderr to some
78 # specific valuse; the messages are internationalized :) ).
79 test.run(arguments = 'po-create', chdir = 'ex1', stderr = None)
80 test.must_exist( ['ex1', 'en.po'] )
81 test.must_exist( ['ex1', 'pl.po'] )
82 test.must_contain( ['ex1', 'en.po'], "Hello from a.cpp", mode='r')
83 test.must_contain( ['ex1', 'pl.po'], "Hello from a.cpp", mode='r')
86 ###############################################################################
87 # POInit: Example 2
88 ###############################################################################
89 test.subdir(['ex2'])
90 test.write( ['ex2', 'SConstruct'],
91 """
92 env = Environment( tools = ["default", "msginit"] )
93 env['POAUTOINIT'] = 1
94 env.POInit(['en','pl'], ['foo']) # foo.pot --&gt; [en.po, pl.po]
95 """)
97 test.write(['ex2', 'foo.pot'], pot_contents)
99 # NOTE: msginit(1) prints all its messages to stderr, we must ignore them,
100 # So, stderr=None is crucial here. It is no point to match stderr to some
101 # specific valuse; the messages are internationalized :) ).
102 test.run(arguments = 'po-create', chdir = 'ex2', stderr = None)
103 test.must_exist( ['ex2', 'en.po'] )
104 test.must_exist( ['ex2', 'pl.po'] )
105 test.must_contain( ['ex2', 'en.po'], "Hello from a.cpp", mode='r' )
106 test.must_contain( ['ex2', 'pl.po'], "Hello from a.cpp", mode='r' )
108 ###############################################################################
109 # POInit: Example 3
110 ###############################################################################
111 test.subdir(['ex3'])
112 test.write( ['ex3', 'SConstruct'],
114 env = Environment( tools = ["default", "msginit"] )
115 env['POAUTOINIT'] = 1
116 env.POInit(['en','pl'], POTDOMAIN='foo') # foo.pot --&gt; [en.po, pl.po]
117 """)
119 test.write(['ex3', 'foo.pot'], pot_contents)
121 # NOTE: msginit(1) prints all its messages to stderr, we must ignore them,
122 # So, stderr=None is crucial here. It is no point to match stderr to some
123 # specific valuse; the messages are internationalized :) ).
124 test.run(arguments = 'po-create', chdir = 'ex3', stderr = None)
125 test.must_exist( ['ex3', 'en.po'] )
126 test.must_exist( ['ex3', 'pl.po'] )
127 test.must_contain( ['ex3', 'en.po'], "Hello from a.cpp", mode='r')
128 test.must_contain( ['ex3', 'pl.po'], "Hello from a.cpp", mode='r')
130 ###############################################################################
131 # POInit: Example 4
132 ###############################################################################
133 test.subdir(['ex4'])
134 test.write( ['ex4', 'SConstruct'],
136 env = Environment( tools = ["default", "msginit"] )
137 env['POAUTOINIT'] = 1
138 env.POInit(LINGUAS_FILE = 1) # needs 'LINGUAS' file
139 """)
140 test.write(['ex4', 'LINGUAS'],"""
143 """)
145 test.write(['ex4', 'messages.pot'], pot_contents)
147 # NOTE: msginit(1) prints all its messages to stderr, we must ignore them,
148 # So, stderr=None is crucial here. It is no point to match stderr to some
149 # specific valuse; the messages are internationalized :) ).
150 test.run(arguments = 'po-create', chdir = 'ex4', stderr = None)
151 test.must_exist( ['ex4', 'en.po'] )
152 test.must_exist( ['ex4', 'pl.po'] )
153 test.must_contain( ['ex4', 'en.po'], "Hello from a.cpp", mode='r')
154 test.must_contain( ['ex4', 'pl.po'], "Hello from a.cpp", mode='r')
156 ###############################################################################
157 # POInit: Example 5
158 ###############################################################################
159 test.subdir(['ex5'])
160 test.write( ['ex5', 'SConstruct'],
162 env = Environment( tools = ["default", "msginit"] )
163 env['POAUTOINIT'] = 1
164 env.POInit(['en', 'pl'], LINGUAS_FILE = 1) # needs 'LINGUAS' file
165 """)
166 test.write(['ex5', 'LINGUAS'],"""
169 """)
171 test.write(['ex5', 'messages.pot'], pot_contents)
173 # NOTE: msginit(1) prints all its messages to stderr, we must ignore them,
174 # So, stderr=None is crucial here. It is no point to match stderr to some
175 # specific valuse; the messages are internationalized :) ).
176 test.run(arguments = 'po-create', chdir = 'ex5', stderr = None)
177 test.must_exist( ['ex5', 'en.po'] )
178 test.must_exist( ['ex5', 'pl.po'] )
179 test.must_exist( ['ex5', 'de.po'] )
180 test.must_exist( ['ex5', 'fr.po'] )
181 test.must_contain( ['ex5', 'en.po'], "Hello from a.cpp", mode='r')
182 test.must_contain( ['ex5', 'pl.po'], "Hello from a.cpp", mode='r')
183 test.must_contain( ['ex5', 'de.po'], "Hello from a.cpp", mode='r')
184 test.must_contain( ['ex5', 'fr.po'], "Hello from a.cpp", mode='r')
186 ###############################################################################
187 # POInit: Example 6
188 ###############################################################################
189 test.subdir(['ex6'])
190 test.write( ['ex6', 'SConstruct'],
192 env = Environment( tools = ["default", "msginit"] )
193 env['POAUTOINIT'] = 1
194 env['LINGUAS_FILE'] = 1
195 env['POTDOMAIN'] = 'foo'
196 env.POInit()
197 """)
198 test.write(['ex6', 'LINGUAS'],"""
201 """)
203 test.write(['ex6', 'foo.pot'], pot_contents)
205 # NOTE: msginit(1) prints all its messages to stderr, we must ignore them,
206 # So, stderr=None is crucial here. It is no point to match stderr to some
207 # specific valuse; the messages are internationalized :) ).
208 test.run(arguments = 'po-create', chdir = 'ex6', stderr = None)
209 test.must_exist( ['ex6', 'en.po'] )
210 test.must_exist( ['ex6', 'pl.po'] )
211 test.must_contain( ['ex6', 'en.po'], "Hello from a.cpp", mode='r')
212 test.must_contain( ['ex6', 'pl.po'], "Hello from a.cpp", mode='r')
214 test.pass_test()
217 # Local Variables:
218 # tab-width:4
219 # indent-tabs-mode:nil
220 # End:
221 # vim: set expandtab tabstop=4 shiftwidth=4: