~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-27 19:05:43 UTC
  • mto: This revision was merged to the branch mainline in revision 6450.
  • Revision ID: jelmer@samba.org-20120127190543-vk350mv4a0c7aug2
Fix weave test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
 
18
 
import os
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
19
18
import warnings
20
19
 
21
20
from bzrlib import (
 
21
    bugtracker,
22
22
    revision,
23
 
    symbol_versioning,
24
 
    )
25
 
from bzrlib.branch import Branch
26
 
from bzrlib.errors import NoSuchRevision
27
 
from bzrlib.deprecated_graph import Graph
28
 
from bzrlib.revision import (find_present_ancestors,
29
 
                             NULL_REVISION)
30
 
from bzrlib.symbol_versioning import one_three
 
23
    )
 
24
from bzrlib.errors import (
 
25
    InvalidBugStatus,
 
26
    InvalidLineInBugsProperty,
 
27
    )
 
28
from bzrlib.revision import NULL_REVISION
31
29
from bzrlib.tests import TestCase, TestCaseWithTransport
32
 
from bzrlib.trace import mutter
33
 
from bzrlib.workingtree import WorkingTree
 
30
from bzrlib.tests.matchers import MatchesAncestry
34
31
 
35
32
# We're allowed to test deprecated interfaces
36
33
warnings.filterwarnings('ignore',
47
44
 
48
45
    the object graph is
49
46
    B:     A:
50
 
    a..0   a..0 
 
47
    a..0   a..0
51
48
    a..1   a..1
52
49
    a..2   a..2
53
50
    b..3   a..3 merges b..4
60
57
    """
61
58
    tree1 = self.make_branch_and_tree("branch1", format=format)
62
59
    br1 = tree1.branch
63
 
    
 
60
 
64
61
    tree1.commit("Commit one", rev_id="a@u-0-0")
65
62
    tree1.commit("Commit two", rev_id="a@u-0-1")
66
63
    tree1.commit("Commit three", rev_id="a@u-0-2")
67
64
 
68
 
    tree2 = tree1.bzrdir.clone("branch2").open_workingtree()
 
65
    tree2 = tree1.bzrdir.sprout("branch2").open_workingtree()
69
66
    br2 = tree2.branch
70
67
    tree2.commit("Commit four", rev_id="b@u-0-3")
71
68
    tree2.commit("Commit five", rev_id="b@u-0-4")
72
 
    revisions_2 = br2.revision_history()
73
 
    self.assertEquals(revisions_2[-1], 'b@u-0-4')
74
 
    
 
69
    self.assertEquals(br2.last_revision(), 'b@u-0-4')
 
70
 
75
71
    tree1.merge_from_branch(br2)
76
72
    tree1.commit("Commit six", rev_id="a@u-0-3")
77
73
    tree1.commit("Commit seven", rev_id="a@u-0-4")
78
74
    tree2.commit("Commit eight", rev_id="b@u-0-5")
79
 
    self.assertEquals(br2.revision_history()[-1], 'b@u-0-5')
80
 
    
 
75
    self.assertEquals(br2.last_revision(), 'b@u-0-5')
 
76
 
81
77
    tree1.merge_from_branch(br2)
82
78
    tree1.commit("Commit nine", rev_id="a@u-0-5")
83
79
    # DO NOT MERGE HERE - we WANT a GHOST.
84
 
    tree2.add_parent_tree_id(br1.revision_history()[4])
 
80
    br1.lock_read()
 
81
    try:
 
82
        graph = br1.repository.get_graph()
 
83
        revhistory = list(graph.iter_lefthand_ancestry(br1.last_revision(),
 
84
            [revision.NULL_REVISION]))
 
85
        revhistory.reverse()
 
86
    finally:
 
87
        br1.unlock()
 
88
    tree2.add_parent_tree_id(revhistory[4])
85
89
    tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
86
 
    
 
90
 
87
91
    return br1, br2
88
92
 
89
93
 
107
111
             ('a@u-0-5', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
108
112
                          'b@u-0-3', 'b@u-0-4',
109
113
                          'b@u-0-5', 'a@u-0-5']),
110
 
             ('b@u-0-6', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2',
 
114
             ('b@u-0-6', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-4',
111
115
                          'b@u-0-3', 'b@u-0-4',
112
116
                          'b@u-0-5', 'b@u-0-6']),
113
117
             ]
119
123
                    continue
120
124
                if rev_id in br2_only and not branch is br2:
121
125
                    continue
122
 
                mutter('ancestry of {%s}: %r',
123
 
                       rev_id, branch.repository.get_ancestry(rev_id))
124
 
                result = sorted(branch.repository.get_ancestry(rev_id))
125
 
                self.assertEquals(result, [None] + sorted(anc))
126
 
    
 
126
                self.assertThat(anc,
 
127
                    MatchesAncestry(branch.repository, rev_id))
 
128
 
127
129
 
128
130
class TestIntermediateRevisions(TestCaseWithTransport):
129
131
 
142
144
        wt2.merge_from_branch(self.br1)
143
145
        wt2.commit("Commit fifteen", rev_id="b@u-0-10")
144
146
 
145
 
        from bzrlib.revision import MultipleRevisionSources
146
 
        self.sources = self.applyDeprecated(one_three,
147
 
                        MultipleRevisionSources, self.br1.repository,
148
 
                                                 self.br2.repository)
149
 
 
150
 
 
151
147
 
152
148
class MockRevisionSource(object):
153
149
    """A RevisionSource that takes a pregenerated graph.
210
206
        self.assertEqual('a', r.get_summary())
211
207
        r.message = '\na\nb'
212
208
        self.assertEqual('a', r.get_summary())
 
209
        r.message = None
 
210
        self.assertEqual('', r.get_summary())
213
211
 
214
 
    def test_get_apparent_author(self):
 
212
    def test_get_apparent_authors(self):
215
213
        r = revision.Revision('1')
216
214
        r.committer = 'A'
217
 
        self.assertEqual('A', r.get_apparent_author())
 
215
        self.assertEqual(['A'], r.get_apparent_authors())
218
216
        r.properties['author'] = 'B'
219
 
        self.assertEqual('B', r.get_apparent_author())
 
217
        self.assertEqual(['B'], r.get_apparent_authors())
 
218
        r.properties['authors'] = 'C\nD'
 
219
        self.assertEqual(['C', 'D'], r.get_apparent_authors())
 
220
 
 
221
    def test_get_apparent_authors_no_committer(self):
 
222
        r = revision.Revision('1')
 
223
        self.assertEqual([], r.get_apparent_authors())
 
224
 
 
225
 
 
226
class TestRevisionBugs(TestCase):
 
227
    """Tests for getting the bugs that a revision is linked to."""
 
228
 
 
229
    def test_no_bugs(self):
 
230
        r = revision.Revision('1')
 
231
        self.assertEqual([], list(r.iter_bugs()))
 
232
 
 
233
    def test_some_bugs(self):
 
234
        r = revision.Revision(
 
235
            '1', properties={
 
236
                'bugs': bugtracker.encode_fixes_bug_urls(
 
237
                    ['http://example.com/bugs/1',
 
238
                     'http://launchpad.net/bugs/1234'])})
 
239
        self.assertEqual(
 
240
            [('http://example.com/bugs/1', bugtracker.FIXED),
 
241
             ('http://launchpad.net/bugs/1234', bugtracker.FIXED)],
 
242
            list(r.iter_bugs()))
 
243
 
 
244
    def test_no_status(self):
 
245
        r = revision.Revision(
 
246
            '1', properties={'bugs': 'http://example.com/bugs/1'})
 
247
        self.assertRaises(InvalidLineInBugsProperty, list, r.iter_bugs())
 
248
 
 
249
    def test_too_much_information(self):
 
250
        r = revision.Revision(
 
251
            '1', properties={'bugs': 'http://example.com/bugs/1 fixed bar'})
 
252
        self.assertRaises(InvalidLineInBugsProperty, list, r.iter_bugs())
 
253
 
 
254
    def test_invalid_status(self):
 
255
        r = revision.Revision(
 
256
            '1', properties={'bugs': 'http://example.com/bugs/1 faxed'})
 
257
        self.assertRaises(InvalidBugStatus, list, r.iter_bugs())