/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_log.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
23
23
 
24
24
from bzrlib import (
25
25
    branchbuilder,
26
 
    errors,
27
26
    log,
28
27
    osutils,
29
28
    tests,
78
77
                # Always return our own log formatter
79
78
                return self.log_catcher
80
79
 
 
80
        self.addAttrCleanup(log.log_formatter_registry, 'get_default')
81
81
        def getme(branch):
82
82
                # Always return our own log formatter class hijacking the
83
83
                # default behavior (which requires setting up a config
84
84
                # variable)
85
85
            return MyLogFormatter
86
 
        self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
 
86
        log.log_formatter_registry.get_default = getme
87
87
 
88
88
    def get_captured_revisions(self):
89
89
        return self.log_catcher.revisions
159
159
        self.assertLogRevnos(['-c1'], ['1'])
160
160
 
161
161
 
162
 
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
 
162
class TestBug474807(TestLogWithLogCatcher):
163
163
 
164
164
    def setUp(self):
165
 
        super(TestLogMergedLinearAncestry, self).setUp()
 
165
        super(TestBug474807, self).setUp()
166
166
        # FIXME: Using a MemoryTree would be even better here (but until we
167
167
        # stop calling run_bzr, there is no point) --vila 100118.
168
168
        builder = branchbuilder.BranchBuilder(self.get_transport())
203
203
                             ['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
204
204
 
205
205
 
206
 
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
207
 
 
208
 
    def setUp(self):
209
 
        super(Test_GenerateAllRevisions, self).setUp()
210
 
        builder = self.make_branch_with_many_merges()
211
 
        b = builder.get_branch()
212
 
        b.lock_read()
213
 
        self.addCleanup(b.unlock)
214
 
        self.branch = b
215
 
 
216
 
    def make_branch_with_many_merges(self, path='.', format=None):
217
 
        builder = branchbuilder.BranchBuilder(self.get_transport())
218
 
        builder.start_series()
219
 
        # The graph below may look a bit complicated (and it may be but I've
220
 
        # banged my head enough on it) but the bug requires at least dotted
221
 
        # revnos *and* merged revisions below that.
222
 
        builder.build_snapshot('1', None, [
223
 
            ('add', ('', 'root-id', 'directory', ''))])
224
 
        builder.build_snapshot('2', ['1'], [])
225
 
        builder.build_snapshot('1.1.1', ['1'], [])
226
 
        builder.build_snapshot('2.1.1', ['2'], [])
227
 
        builder.build_snapshot('3', ['2', '1.1.1'], [])
228
 
        builder.build_snapshot('2.1.2', ['2.1.1'], [])
229
 
        builder.build_snapshot('2.2.1', ['2.1.1'], [])
230
 
        builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
231
 
        builder.build_snapshot('4', ['3', '2.1.3'], [])
232
 
        builder.build_snapshot('5', ['4', '2.1.2'], [])
233
 
        builder.finish_series()
234
 
        return builder
235
 
 
236
 
    def test_not_an_ancestor(self):
237
 
        self.assertRaises(errors.BzrCommandError,
238
 
                          log._generate_all_revisions,
239
 
                          self.branch, '1.1.1', '2.1.3', 'reverse',
240
 
                          delayed_graph_generation=True)
241
 
 
242
 
    def test_wrong_order(self):
243
 
        self.assertRaises(errors.BzrCommandError,
244
 
                          log._generate_all_revisions,
245
 
                          self.branch, '5', '2.1.3', 'reverse',
246
 
                          delayed_graph_generation=True)
247
 
 
248
 
    def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
249
 
        revs = log._generate_all_revisions(
250
 
            self.branch, None, '2.1.3',
251
 
            'reverse', delayed_graph_generation=True)
252
 
 
253
 
 
254
206
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
255
207
 
256
208
    def test_log_revno_n_path_wrong_namespace(self):
259
211
        # There is no guarantee that a path exist between two arbitrary
260
212
        # revisions.
261
213
        self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
 
214
        # But may be it's worth trying though ? -- vila 100115
262
215
 
263
216
    def test_log_revno_n_path_correct_order(self):
264
217
        self.make_linear_branch('branch2')
365
318
                            'options are "utc", "original", "local".'],
366
319
                           ['log', '--timezone', 'foo'])
367
320
 
368
 
    def test_log_exclude_ancestry_no_range(self):
369
 
        self.make_linear_branch()
370
 
        self.run_bzr_error(['bzr: ERROR: --exclude-common-ancestry'
371
 
                            ' requires -r with two revisions'],
372
 
                           ['log', '--exclude-common-ancestry'])
373
 
 
374
 
    def test_log_exclude_ancestry_single_revision(self):
375
 
        self.make_merged_branch()
376
 
        self.run_bzr_error(['bzr: ERROR: --exclude-common-ancestry'
377
 
                            ' requires two different revisions'],
378
 
                           ['log', '--exclude-common-ancestry',
379
 
                            '-r1.1.1..1.1.1'])
380
321
 
381
322
class TestLogTags(TestLog):
382
323
 
666
607
 
667
608
    def setUp(self):
668
609
        super(TestLogEncodings, self).setUp()
669
 
        self.overrideAttr(osutils, '_cached_user_encoding')
 
610
        self.addAttrCleanup(osutils, '_cached_user_encoding')
670
611
 
671
612
    def create_branch(self):
672
613
        bzr = self.run_bzr