/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
1
# Copyright (C) 2006 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
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
"""Whitebox tests for annotate functionality."""
18
19
from cStringIO import StringIO
20
21
from bzrlib import (
22
    annotate,
23
    conflicts,
24
    errors,
25
    tests,
26
    trace,
27
    )
28
29
30
class TestAnnotate(tests.TestCaseWithTransport):
31
32
    def create_merged_trees(self):
33
        tree1 = self.make_branch_and_tree('tree1')
34
        self.build_tree_contents([('tree1/a', 'first\n')])
35
        tree1.add(['a'], ['a-id'])
36
        tree1.commit('a', rev_id='rev-1',
37
                     committer="joe@foo.com", timestamp=1166046000.00)
38
39
        tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
40
41
        self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
42
        tree1.commit('b', rev_id='rev-2',
43
                     committer='joe@foo.com', timestamp=1166046001.00)
44
45
        self.build_tree_contents([('tree2/a', 'first\nthird\n')])
46
        tree2.commit('c', rev_id='rev-1_1_1',
47
                     committer="barry@foo.com", timestamp=1166046002.00)
48
49
        num_conflicts = tree1.merge_from_branch(tree2.branch)
50
        self.assertEqual(1, num_conflicts)
51
52
        self.build_tree_contents([('tree1/a',
53
                                 'first\nsecond\nthird\n')])
54
        tree1.set_conflicts(conflicts.ConflictList())
55
        tree1.commit('merge 2', rev_id='rev-3',
56
                     committer='sal@foo.com', timestamp=1166046003.00)
57
        return tree1, tree2
58
59
    def create_deeply_merged_trees(self):
60
        tree1, tree2 = self.create_merged_trees()
61
62
        tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
63
64
        tree2.commit('noop', rev_id='rev-1.1.2')
65
        self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
66
        tree1.commit('noop merge', rev_id='rev-4')
67
68
        self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
69
        tree3.commit('four', rev_id='rev-1_1_1_1_1',
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
70
                     committer='jerry@foo.com', timestamp=1166046003.00)
71
72
        tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
73
74
        tree3.commit('noop', rev_id='rev-1.1.1.1.2',
75
                     committer='jerry@foo.com', timestamp=1166046004.00)
76
        self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
77
        tree1.commit('merge four', rev_id='rev-5')
78
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
79
        self.build_tree_contents([('tree4/a',
80
                                   'first\nthird\nfourth\nfifth\nsixth\n')])
81
        tree4.commit('five and six', rev_id='rev-1_1_1_1_1_1_1',
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
82
                     committer='george@foo.com', timestamp=1166046005.00)
83
        self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
84
        tree1.commit('merge five and six', rev_id='rev-6')
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
85
        return tree1
86
87
    def test_annotate_shows_dotted_revnos(self):
88
        tree1, tree2 = self.create_merged_trees()
89
90
        sio = StringIO()
91
        annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
92
                               to_file=sio)
93
        self.assertEqualDiff('1     joe@foo | first\n'
94
                             '2     joe@foo | second\n'
95
                             '1.1.1 barry@f | third\n',
96
                             sio.getvalue())
97
98
    def test_annotate_limits_dotted_revnos(self):
99
        """Annotate should limit dotted revnos to a depth of 12"""
100
        tree1 = self.create_deeply_merged_trees()
101
102
        sio = StringIO()
103
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
104
                               to_file=sio, verbose=False, full=False)
105
        self.assertEqualDiff('1            joe@foo | first\n'
106
                             '2            joe@foo | second\n'
107
                             '1.1.1        barry@f | third\n'
108
                             '1.1.1.1.1    jerry@f | fourth\n'
109
                             '1.1.1.1.1.1> george@ | fifth\n'
110
                             '                     | sixth\n',
111
                             sio.getvalue())
112
113
        sio = StringIO()
114
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
115
                               to_file=sio, verbose=False, full=True)
116
        self.assertEqualDiff('1            joe@foo | first\n'
117
                             '2            joe@foo | second\n'
118
                             '1.1.1        barry@f | third\n'
119
                             '1.1.1.1.1    jerry@f | fourth\n'
120
                             '1.1.1.1.1.1> george@ | fifth\n'
121
                             '1.1.1.1.1.1> george@ | sixth\n',
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
122
                             sio.getvalue())
123
124
        # verbose=True shows everything, the full revno, user id, and date
125
        sio = StringIO()
126
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
127
                               to_file=sio, verbose=True, full=False)
128
        self.assertEqualDiff('1             joe@foo.com    20061213 | first\n'
129
                             '2             joe@foo.com    20061213 | second\n'
130
                             '1.1.1         barry@foo.com  20061213 | third\n'
131
                             '1.1.1.1.1     jerry@foo.com  20061213 | fourth\n'
132
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
133
                             '                                      | sixth\n',
134
                             sio.getvalue())
135
136
        sio = StringIO()
137
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
138
                               to_file=sio, verbose=True, full=True)
139
        self.assertEqualDiff('1             joe@foo.com    20061213 | first\n'
140
                             '2             joe@foo.com    20061213 | second\n'
141
                             '1.1.1         barry@foo.com  20061213 | third\n'
142
                             '1.1.1.1.1     jerry@foo.com  20061213 | fourth\n'
143
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
144
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | sixth\n',
145
                             sio.getvalue())
146
    
147
    def test_annotate_show_ids(self):
148
        tree1 = self.create_deeply_merged_trees()
149
150
        sio = StringIO()
151
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
152
                               to_file=sio, show_ids=True, full=False)
153
154
        # It looks better with real revision ids :)
155
        self.assertEqualDiff('            rev-1 | first\n'
156
                             '            rev-2 | second\n'
157
                             '        rev-1_1_1 | third\n'
158
                             '    rev-1_1_1_1_1 | fourth\n'
159
                             'rev-1_1_1_1_1_1_1 | fifth\n'
160
                             '                  | sixth\n',
161
                             sio.getvalue())
162
163
        sio = StringIO()
164
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
165
                               to_file=sio, show_ids=True, full=True)
166
167
        self.assertEqualDiff('            rev-1 | first\n'
168
                             '            rev-2 | second\n'
169
                             '        rev-1_1_1 | third\n'
170
                             '    rev-1_1_1_1_1 | fourth\n'
171
                             'rev-1_1_1_1_1_1_1 | fifth\n'
172
                             'rev-1_1_1_1_1_1_1 | sixth\n',
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
173
                             sio.getvalue())