~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/po_merge/tests/test_po_merge.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8
2
 
# Copyright (C) 2011 by Canonical Ltd
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 
 
18
 
import os
19
 
 
20
 
from bzrlib import (
21
 
    merge,
22
 
    tests,
23
 
    )
24
 
from bzrlib.tests import (
25
 
    features,
26
 
    script,
27
 
    )
28
 
 
29
 
from bzrlib.plugins import po_merge
30
 
 
31
 
class BlackboxTestPoMerger(script.TestCaseWithTransportAndScript):
32
 
 
33
 
    _test_needs_features = [features.msgmerge_feature]
34
 
 
35
 
    def setUp(self):
36
 
        super(BlackboxTestPoMerger, self).setUp()
37
 
        self.builder = make_adduser_branch(self, 'adduser')
38
 
        # We need to install our hook as the test framework cleared it as part
39
 
        # of the initialization
40
 
        merge.Merger.hooks.install_named_hook(
41
 
            "merge_file_content", po_merge.po_merge_hook, ".po file merge")
42
 
 
43
 
    def test_merge_with_hook_gives_unexpected_results(self):
44
 
        # Since the conflicts in .pot are not seen *during* the merge, the .po
45
 
        # merge triggers the hook and creates no conflicts for fr.po. But the
46
 
        # .pot used is the one present in the tree *before* the merge.
47
 
        self.run_script("""\
48
 
$ bzr branch adduser -rrevid:this work
49
 
2>Branched 2 revisions.
50
 
$ cd work
51
 
$ bzr merge ../adduser -rrevid:other
52
 
2> M  po/adduser.pot
53
 
2> M  po/fr.po
54
 
2>Text conflict in po/adduser.pot
55
 
2>1 conflicts encountered.
56
 
""")
57
 
 
58
 
    def test_called_on_remerge(self):
59
 
        # Merge with no config for the hook to create the conflicts
60
 
        self.run_script("""\
61
 
$ bzr branch adduser -rrevid:this work
62
 
2>Branched 2 revisions.
63
 
$ cd work
64
 
# set po_dirs to an empty list
65
 
$ bzr merge ../adduser -rrevid:other -Opo_merge.po_dirs=
66
 
2> M  po/adduser.pot
67
 
2> M  po/fr.po
68
 
2>Text conflict in po/adduser.pot
69
 
2>Text conflict in po/fr.po
70
 
2>2 conflicts encountered.
71
 
""")
72
 
        # Fix the conflicts in the .pot file
73
 
        with open('po/adduser.pot', 'w') as f:
74
 
            f.write(_Adduser['resolved_pot'])
75
 
        # Tell bzr the conflict is resolved
76
 
        self.run_script("""\
77
 
$ bzr resolve po/adduser.pot
78
 
2>1 conflict resolved, 1 remaining
79
 
# Use remerge to trigger the hook, we use the default config options here
80
 
$ bzr remerge po/*.po
81
 
2>All changes applied successfully.
82
 
# There should be no conflicts anymore
83
 
$ bzr conflicts
84
 
""")
85
 
 
86
 
 
87
 
def make_adduser_branch(test, relpath):
88
 
    """Helper for po_merge blackbox tests.
89
 
 
90
 
    This creates a branch containing the needed base revisions so tests can
91
 
    attempt merges and conflict resolutions.
92
 
    """
93
 
    builder = test.make_branch_builder(relpath)
94
 
    builder.start_series()
95
 
    builder.build_snapshot('base', None,
96
 
                           [('add', ('', 'root-id', 'directory', '')),
97
 
                            # Create empty files
98
 
                            ('add', ('po', 'dir-id', 'directory', None),),
99
 
                            ('add', ('po/adduser.pot', 'pot-id', 'file',
100
 
                                     _Adduser['base_pot'])),
101
 
                            ('add', ('po/fr.po', 'po-id', 'file',
102
 
                                     _Adduser['base_po'])),
103
 
            ])
104
 
    # The 'other' branch
105
 
    builder.build_snapshot('other', ['base'],
106
 
                           [('modify', ('pot-id',
107
 
                                        _Adduser['other_pot'])),
108
 
                            ('modify', ('po-id',
109
 
                                        _Adduser['other_po'])),
110
 
                            ])
111
 
    # The 'this' branch
112
 
    builder.build_snapshot('this', ['base'],
113
 
                           [('modify', ('pot-id', _Adduser['this_pot'])),
114
 
                            ('modify', ('po-id', _Adduser['this_po'])),
115
 
                            ])
116
 
    # builder.get_branch() tip is now 'this'
117
 
    builder.finish_series()
118
 
    return builder
119
 
 
120
 
 
121
 
class TestAdduserBranch(script.TestCaseWithTransportAndScript):
122
 
    """Sanity checks on the adduser branch content."""
123
 
 
124
 
    def setUp(self):
125
 
        super(TestAdduserBranch, self).setUp()
126
 
        self.builder = make_adduser_branch(self, 'adduser')
127
 
 
128
 
    def assertAdduserBranchContent(self, revid):
129
 
        env = dict(revid=revid, branch_name=revid)
130
 
        self.run_script("""\
131
 
$ bzr branch adduser -rrevid:%(revid)s %(branch_name)s
132
 
""" % env, null_output_matches_anything=True)
133
 
        self.assertFileEqual(_Adduser['%(revid)s_pot' % env],
134
 
                             '%(branch_name)s/po/adduser.pot' % env)
135
 
        self.assertFileEqual(_Adduser['%(revid)s_po' % env],
136
 
                             '%(branch_name)s/po/fr.po' % env )
137
 
 
138
 
    def test_base(self):
139
 
        self.assertAdduserBranchContent('base')
140
 
 
141
 
    def test_this(self):
142
 
        self.assertAdduserBranchContent('this')
143
 
 
144
 
    def test_other(self):
145
 
        self.assertAdduserBranchContent('other')
146
 
 
147
 
 
148
 
# Real content from the adduser package so we don't have to guess about format
149
 
# details. This is declared at the end of the file to avoid cluttering the
150
 
# beginning of the file.
151
 
 
152
 
_Adduser = dict(
153
 
    base_pot = r"""# SOME DESCRIPTIVE TITLE.
154
 
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
155
 
# This file is distributed under the same license as the PACKAGE package.
156
 
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
157
 
#
158
 
#, fuzzy
159
 
msgid ""
160
 
msgstr ""
161
 
"Project-Id-Version: PACKAGE VERSION\n"
162
 
"Report-Msgid-Bugs-To: adduser-devel@example.com\n"
163
 
"POT-Creation-Date: 2007-01-17 21:50+0100\n"
164
 
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
165
 
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
166
 
"Language-Team: LANGUAGE <LL@example.com>\n"
167
 
"MIME-Version: 1.0\n"
168
 
"Content-Type: text/plain; charset=CHARSET\n"
169
 
"Content-Transfer-Encoding: 8bit\n"
170
 
 
171
 
#. everyone can issue "--help" and "--version", but only root can go on
172
 
#: ../adduser:135
173
 
msgid "Only root may add a user or group to the system.\n"
174
 
msgstr ""
175
 
 
176
 
#: ../adduser:188
177
 
msgid "Warning: The home dir you specified already exists.\n"
178
 
msgstr ""
179
 
 
180
 
""",
181
 
    this_pot = r"""# SOME DESCRIPTIVE TITLE.
182
 
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
183
 
# This file is distributed under the same license as the PACKAGE package.
184
 
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
185
 
#
186
 
#, fuzzy
187
 
msgid ""
188
 
msgstr ""
189
 
"Project-Id-Version: PACKAGE VERSION\n"
190
 
"Report-Msgid-Bugs-To: adduser-devel@example.com\n"
191
 
"POT-Creation-Date: 2011-01-06 21:06+0000\n"
192
 
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
193
 
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
194
 
"Language-Team: LANGUAGE <LL@example.com>\n"
195
 
"Language: \n"
196
 
"MIME-Version: 1.0\n"
197
 
"Content-Type: text/plain; charset=CHARSET\n"
198
 
"Content-Transfer-Encoding: 8bit\n"
199
 
 
200
 
#. everyone can issue "--help" and "--version", but only root can go on
201
 
#: ../adduser:152
202
 
msgid "Only root may add a user or group to the system.\n"
203
 
msgstr ""
204
 
 
205
 
#: ../adduser:208
206
 
#, perl-format
207
 
msgid "Warning: The home dir %s you specified already exists.\n"
208
 
msgstr ""
209
 
 
210
 
#: ../adduser:210
211
 
#, perl-format
212
 
msgid "Warning: The home dir %s you specified can't be accessed: %s\n"
213
 
msgstr ""
214
 
 
215
 
""",
216
 
    other_pot = r"""# SOME DESCRIPTIVE TITLE.
217
 
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
218
 
# This file is distributed under the same license as the PACKAGE package.
219
 
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
220
 
#
221
 
#, fuzzy
222
 
msgid ""
223
 
msgstr ""
224
 
"Project-Id-Version: PACKAGE VERSION\n"
225
 
"Report-Msgid-Bugs-To: adduser-devel@example.com\n"
226
 
"POT-Creation-Date: 2010-11-21 17:13-0400\n"
227
 
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
228
 
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
229
 
"Language-Team: LANGUAGE <LL@example.com>\n"
230
 
"Language: \n"
231
 
"MIME-Version: 1.0\n"
232
 
"Content-Type: text/plain; charset=CHARSET\n"
233
 
"Content-Transfer-Encoding: 8bit\n"
234
 
 
235
 
#. everyone can issue "--help" and "--version", but only root can go on
236
 
#: ../adduser:150
237
 
msgid "Only root may add a user or group to the system.\n"
238
 
msgstr ""
239
 
 
240
 
#: ../adduser:206
241
 
#, perl-format
242
 
msgid "Warning: The home dir %s you specified already exists.\n"
243
 
msgstr ""
244
 
 
245
 
#: ../adduser:208
246
 
#, perl-format
247
 
msgid "Warning: The home dir %s you specified can't be accessed: %s\n"
248
 
msgstr ""
249
 
 
250
 
""",
251
 
    resolved_pot = r"""# SOME DESCRIPTIVE TITLE.
252
 
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
253
 
# This file is distributed under the same license as the PACKAGE package.
254
 
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
255
 
#
256
 
#, fuzzy
257
 
msgid ""
258
 
msgstr ""
259
 
"Project-Id-Version: PACKAGE VERSION\n"
260
 
"Report-Msgid-Bugs-To: adduser-devel@example.com\n"
261
 
"POT-Creation-Date: 2011-10-19 12:50-0700\n"
262
 
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
263
 
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
264
 
"Language-Team: LANGUAGE <LL@example.com>\n"
265
 
"Language: \n"
266
 
"MIME-Version: 1.0\n"
267
 
"Content-Type: text/plain; charset=CHARSET\n"
268
 
"Content-Transfer-Encoding: 8bit\n"
269
 
 
270
 
#. everyone can issue "--help" and "--version", but only root can go on
271
 
#: ../adduser:152
272
 
msgid "Only root may add a user or group to the system.\n"
273
 
msgstr ""
274
 
 
275
 
#: ../adduser:208
276
 
#, perl-format
277
 
msgid "Warning: The home dir %s you specified already exists.\n"
278
 
msgstr ""
279
 
 
280
 
#: ../adduser:210
281
 
#, perl-format
282
 
msgid "Warning: The home dir %s you specified can't be accessed: %s\n"
283
 
msgstr ""
284
 
 
285
 
""",
286
 
    base_po = r"""# adduser's manpages translation to French
287
 
# Copyright (C) 2004 Software in the Public Interest
288
 
# This file is distributed under the same license as the adduser package
289
 
#
290
 
# Translators:
291
 
# Jean-Baka Domelevo Entfellner <domelevo@example.com>, 2009.
292
 
#
293
 
msgid ""
294
 
msgstr ""
295
 
"Project-Id-Version: adduser 3.111\n"
296
 
"Report-Msgid-Bugs-To: adduser-devel@example.com\n"
297
 
"POT-Creation-Date: 2007-01-17 21:50+0100\n"
298
 
"PO-Revision-Date: 2010-01-21 10:36+0100\n"
299
 
"Last-Translator: Jean-Baka Domelevo Entfellner <domelevo@example.com>\n"
300
 
"Language-Team: Debian French Team <debian-l10n-french@example.com>\n"
301
 
"Language: \n"
302
 
"MIME-Version: 1.0\n"
303
 
"Content-Type: text/plain; charset=UTF-8\n"
304
 
"Content-Transfer-Encoding: 8bit\n"
305
 
"X-Poedit-Language: French\n"
306
 
"X-Poedit-Country: FRANCE\n"
307
 
 
308
 
# type: Plain text
309
 
#. everyone can issue "--help" and "--version", but only root can go on
310
 
#: ../adduser:135
311
 
msgid "Only root may add a user or group to the system.\n"
312
 
msgstr ""
313
 
"Seul le superutilisateur est autorisé à ajouter un utilisateur ou un groupe "
314
 
"au système.\n"
315
 
 
316
 
#: ../adduser:188
317
 
msgid "Warning: The home dir you specified already exists.\n"
318
 
msgstr ""
319
 
"Attention ! Le répertoire personnel que vous avez indiqué existe déjà.\n"
320
 
 
321
 
""",
322
 
    this_po = r"""# adduser's manpages translation to French
323
 
# Copyright (C) 2004 Software in the Public Interest
324
 
# This file is distributed under the same license as the adduser package
325
 
#
326
 
# Translators:
327
 
# Jean-Baka Domelevo Entfellner <domelevo@example.com>, 2009.
328
 
#
329
 
msgid ""
330
 
msgstr ""
331
 
"Project-Id-Version: adduser 3.111\n"
332
 
"Report-Msgid-Bugs-To: adduser-devel@example.com\n"
333
 
"POT-Creation-Date: 2010-10-12 15:48+0200\n"
334
 
"PO-Revision-Date: 2010-01-21 10:36+0100\n"
335
 
"Last-Translator: Jean-Baka Domelevo Entfellner <domelevo@example.com>\n"
336
 
"Language-Team: Debian French Team <debian-l10n-french@example.com>\n"
337
 
"Language: \n"
338
 
"MIME-Version: 1.0\n"
339
 
"Content-Type: text/plain; charset=UTF-8\n"
340
 
"Content-Transfer-Encoding: 8bit\n"
341
 
"X-Poedit-Language: French\n"
342
 
"X-Poedit-Country: FRANCE\n"
343
 
 
344
 
# type: Plain text
345
 
#. everyone can issue "--help" and "--version", but only root can go on
346
 
#: ../adduser:152
347
 
msgid "Only root may add a user or group to the system.\n"
348
 
msgstr ""
349
 
"Seul le superutilisateur est autorisé à ajouter un utilisateur ou un groupe "
350
 
"au système.\n"
351
 
 
352
 
#: ../adduser:208
353
 
#, fuzzy, perl-format
354
 
msgid "Warning: The home dir %s you specified already exists.\n"
355
 
msgstr ""
356
 
"Attention ! Le répertoire personnel que vous avez indiqué existe déjà.\n"
357
 
 
358
 
#: ../adduser:210
359
 
#, fuzzy, perl-format
360
 
msgid "Warning: The home dir %s you specified can't be accessed: %s\n"
361
 
msgstr ""
362
 
"Attention ! Le répertoire personnel que vous avez indiqué existe déjà.\n"
363
 
 
364
 
""",
365
 
    other_po = r"""# adduser's manpages translation to French
366
 
# Copyright (C) 2004 Software in the Public Interest
367
 
# This file is distributed under the same license as the adduser package
368
 
#
369
 
# Translators:
370
 
# Jean-Baka Domelevo Entfellner <domelevo@example.com>, 2009, 2010.
371
 
#
372
 
msgid ""
373
 
msgstr ""
374
 
"Project-Id-Version: adduser 3.112+nmu2\n"
375
 
"Report-Msgid-Bugs-To: adduser-devel@example.com\n"
376
 
"POT-Creation-Date: 2010-11-21 17:13-0400\n"
377
 
"PO-Revision-Date: 2010-11-10 11:08+0100\n"
378
 
"Last-Translator: Jean-Baka Domelevo-Entfellner <domelevo@example.com>\n"
379
 
"Language-Team: Debian French Team <debian-l10n-french@example.com>\n"
380
 
"Language: \n"
381
 
"MIME-Version: 1.0\n"
382
 
"Content-Type: text/plain; charset=UTF-8\n"
383
 
"Content-Transfer-Encoding: 8bit\n"
384
 
"X-Poedit-Country: FRANCE\n"
385
 
 
386
 
# type: Plain text
387
 
#. everyone can issue "--help" and "--version", but only root can go on
388
 
#: ../adduser:150
389
 
msgid "Only root may add a user or group to the system.\n"
390
 
msgstr ""
391
 
"Seul le superutilisateur est autorisé à ajouter un utilisateur ou un groupe "
392
 
"au système.\n"
393
 
 
394
 
#: ../adduser:206
395
 
#, perl-format
396
 
msgid "Warning: The home dir %s you specified already exists.\n"
397
 
msgstr ""
398
 
"Attention ! Le répertoire personnel que vous avez indiqué (%s) existe déjà.\n"
399
 
 
400
 
#: ../adduser:208
401
 
#, perl-format
402
 
msgid "Warning: The home dir %s you specified can't be accessed: %s\n"
403
 
msgstr ""
404
 
"Attention ! Impossible d'accéder au répertoire personnel que vous avez "
405
 
"indiqué (%s) : %s.\n"
406
 
 
407
 
""",
408
 
    resolved_po = r"""# adduser's manpages translation to French
409
 
# Copyright (C) 2004 Software in the Public Interest
410
 
# This file is distributed under the same license as the adduser package
411
 
#
412
 
# Translators:
413
 
# Jean-Baka Domelevo Entfellner <domelevo@example.com>, 2009, 2010.
414
 
#
415
 
msgid ""
416
 
msgstr ""
417
 
"Project-Id-Version: adduser 3.112+nmu2\n"
418
 
"Report-Msgid-Bugs-To: adduser-devel@example.com\n"
419
 
"POT-Creation-Date: 2011-10-19 12:50-0700\n"
420
 
"PO-Revision-Date: 2010-11-10 11:08+0100\n"
421
 
"Last-Translator: Jean-Baka Domelevo-Entfellner <domelevo@example.com>\n"
422
 
"Language-Team: Debian French Team <debian-l10n-french@example.com>\n"
423
 
"Language: \n"
424
 
"MIME-Version: 1.0\n"
425
 
"Content-Type: text/plain; charset=UTF-8\n"
426
 
"Content-Transfer-Encoding: 8bit\n"
427
 
"X-Poedit-Country: FRANCE\n"
428
 
 
429
 
# type: Plain text
430
 
#. everyone can issue "--help" and "--version", but only root can go on
431
 
#: ../adduser:152
432
 
msgid "Only root may add a user or group to the system.\n"
433
 
msgstr ""
434
 
"Seul le superutilisateur est autorisé à ajouter un utilisateur ou un groupe "
435
 
"au système.\n"
436
 
 
437
 
#: ../adduser:208
438
 
#, perl-format
439
 
msgid "Warning: The home dir %s you specified already exists.\n"
440
 
msgstr ""
441
 
"Attention ! Le répertoire personnel que vous avez indiqué (%s) existe déjà.\n"
442
 
 
443
 
#: ../adduser:210
444
 
#, perl-format
445
 
msgid "Warning: The home dir %s you specified can't be accessed: %s\n"
446
 
msgstr ""
447
 
"Attention ! Impossible d'accéder au répertoire personnel que vous avez "
448
 
"indiqué (%s) : %s.\n"
449
 
 
450
 
""",
451
 
)