~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-16 21:31:35 UTC
  • mfrom: (3363.19.4 fix-iter-changes)
  • Revision ID: pqm@pqm.ubuntu.com-20081016213135-0115pw9c95l2dyxq
PreviewTree.iter_changes accepts all standard parameters (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
"""Black-box tests for bzr.
 
20
 
 
21
These check that it behaves properly when it's invoked through the regular
 
22
command-line interface. This doesn't actually run a new interpreter but 
 
23
rather starts again from the run_bzr function.
 
24
"""
 
25
 
 
26
 
 
27
import os
 
28
 
 
29
from bzrlib.branch import Branch
 
30
from bzrlib.config import extract_email_address
 
31
from bzrlib.tests import TestCaseWithTransport
 
32
 
 
33
 
 
34
class TestAnnotate(TestCaseWithTransport):
 
35
 
 
36
    def setUp(self):
 
37
        super(TestAnnotate, self).setUp()
 
38
        wt = self.make_branch_and_tree('.')
 
39
        b = wt.branch
 
40
        self.build_tree_contents([('hello.txt', 'my helicopter\n'),
 
41
                                  ('nomail.txt', 'nomail\n')])
 
42
        wt.add(['hello.txt'])
 
43
        self.revision_id_1 = wt.commit('add hello',
 
44
                              committer='test@user',
 
45
                              timestamp=1165960000.00, timezone=0)
 
46
        wt.add(['nomail.txt'])
 
47
        self.revision_id_2 = wt.commit('add nomail',
 
48
                              committer='no mail',
 
49
                              timestamp=1165970000.00, timezone=0)
 
50
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
 
51
                                                'your helicopter\n')])
 
52
        self.revision_id_3 = wt.commit('mod hello',
 
53
                              committer='user@test',
 
54
                              timestamp=1166040000.00, timezone=0)
 
55
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
 
56
                                                'your helicopter\n'
 
57
                                                'all of\n'
 
58
                                                'our helicopters\n'
 
59
                                  )])
 
60
        self.revision_id_4 = wt.commit('mod hello',
 
61
                              committer='user@test',
 
62
                              timestamp=1166050000.00, timezone=0)
 
63
 
 
64
    def test_help_annotate(self):
 
65
        """Annotate command exists"""
 
66
        out, err = self.run_bzr('--no-plugins annotate --help')
 
67
 
 
68
    def test_annotate_cmd(self):
 
69
        out, err = self.run_bzr('annotate hello.txt')
 
70
        self.assertEqual('', err)
 
71
        self.assertEqualDiff('''\
 
72
1   test@us | my helicopter
 
73
3   user@te | your helicopter
 
74
4   user@te | all of
 
75
            | our helicopters
 
76
''', out)
 
77
 
 
78
    def test_annotate_cmd_full(self):
 
79
        out, err = self.run_bzr('annotate hello.txt --all')
 
80
        self.assertEqual('', err)
 
81
        self.assertEqualDiff('''\
 
82
1   test@us | my helicopter
 
83
3   user@te | your helicopter
 
84
4   user@te | all of
 
85
4   user@te | our helicopters
 
86
''', out)
 
87
 
 
88
    def test_annotate_cmd_long(self):
 
89
        out, err = self.run_bzr('annotate hello.txt --long')
 
90
        self.assertEqual('', err)
 
91
        self.assertEqualDiff('''\
 
92
1   test@user 20061212 | my helicopter
 
93
3   user@test 20061213 | your helicopter
 
94
4   user@test 20061213 | all of
 
95
                       | our helicopters
 
96
''', out)
 
97
 
 
98
    def test_annotate_cmd_show_ids(self):
 
99
        out, err = self.run_bzr('annotate hello.txt --show-ids')
 
100
        max_len = max([len(self.revision_id_1),
 
101
                       len(self.revision_id_3),
 
102
                       len(self.revision_id_4)])
 
103
        self.assertEqual('', err)
 
104
        self.assertEqualDiff('''\
 
105
%*s | my helicopter
 
106
%*s | your helicopter
 
107
%*s | all of
 
108
%*s | our helicopters
 
109
''' % (max_len, self.revision_id_1,
 
110
       max_len, self.revision_id_3,
 
111
       max_len, self.revision_id_4,
 
112
       max_len, '',
 
113
      )
 
114
, out)
 
115
 
 
116
    def test_no_mail(self):
 
117
        out, err = self.run_bzr('annotate nomail.txt')
 
118
        self.assertEqual('', err)
 
119
        self.assertEqualDiff('''\
 
120
2   no mail | nomail
 
121
''', out)
 
122
 
 
123
    def test_annotate_cmd_revision(self):
 
124
        out, err = self.run_bzr('annotate hello.txt -r1')
 
125
        self.assertEqual('', err)
 
126
        self.assertEqualDiff('''\
 
127
1   test@us | my helicopter
 
128
''', out)
 
129
 
 
130
    def test_annotate_cmd_revision3(self):
 
131
        out, err = self.run_bzr('annotate hello.txt -r3')
 
132
        self.assertEqual('', err)
 
133
        self.assertEqualDiff('''\
 
134
1   test@us | my helicopter
 
135
3   user@te | your helicopter
 
136
''', out)
 
137
 
 
138
    def test_annotate_cmd_unknown_revision(self):
 
139
        out, err = self.run_bzr('annotate hello.txt -r 10',
 
140
                                retcode=3)
 
141
        self.assertEqual('', out)
 
142
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
 
143
 
 
144
    def test_annotate_cmd_two_revisions(self):
 
145
        out, err = self.run_bzr('annotate hello.txt -r1..2',
 
146
                                retcode=3)
 
147
        self.assertEqual('', out)
 
148
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
 
149
                         ' exactly one revision identifier\n',
 
150
                         err)
 
151
 
 
152
 
 
153
class TestSimpleAnnotate(TestCaseWithTransport):
 
154
    """Annotate tests with no complex setup."""
 
155
 
 
156
    def _setup_edited_file(self):
 
157
        """Create a tree with a locally edited file."""
 
158
        tree = self.make_branch_and_tree('.')
 
159
        self.build_tree_contents([('file', 'foo\ngam\n')])
 
160
        tree.add('file')
 
161
        tree.commit('add file', committer="test@host", rev_id="rev1")
 
162
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
 
163
        tree.branch.get_config().set_user_option('email', 'current@host2')
 
164
 
 
165
    def test_annotate_edited_file(self):
 
166
        tree = self._setup_edited_file()
 
167
        out, err = self.run_bzr('annotate file')
 
168
        self.assertEqual(
 
169
            '1   test@ho | foo\n'
 
170
            '2?  current | bar\n'
 
171
            '1   test@ho | gam\n',
 
172
            out)
 
173
 
 
174
    def test_annotate_edited_file_show_ids(self):
 
175
        tree = self._setup_edited_file()
 
176
        out, err = self.run_bzr('annotate file --show-ids')
 
177
        self.assertEqual(
 
178
            '    rev1 | foo\n'
 
179
            'current: | bar\n'
 
180
            '    rev1 | gam\n',
 
181
            out)
 
182
 
 
183
    def _create_merged_file(self):
 
184
        """Create a file with a pending merge and local edit."""
 
185
        tree = self.make_branch_and_tree('.')
 
186
        self.build_tree_contents([('file', 'foo\ngam\n')])
 
187
        tree.add('file')
 
188
        tree.commit('add file', rev_id="rev1", committer="test@host")
 
189
        # right side
 
190
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
 
191
        tree.commit("right", rev_id="rev1.1.1", committer="test@host")
 
192
        tree.pull(tree.branch, True, "rev1")
 
193
        # left side
 
194
        self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
 
195
        tree.commit("left", rev_id="rev2", committer="test@host")
 
196
        # merge
 
197
        tree.merge_from_branch(tree.branch, "rev1.1.1")
 
198
        # edit the file to be 'resolved' and have a further local edit
 
199
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
 
200
 
 
201
    def test_annotated_edited_merged_file_revnos(self):
 
202
        self._create_merged_file()
 
203
        out, err = self.run_bzr('annotate file')
 
204
        email = extract_email_address(Branch.open('.').get_config().username())
 
205
        self.assertEqual(
 
206
            '3?    %-7s | local\n'
 
207
            '1     test@ho | foo\n'
 
208
            '1.1.1 test@ho | bar\n'
 
209
            '2     test@ho | baz\n'
 
210
            '1     test@ho | gam\n' % email[:7],
 
211
            out)
 
212
 
 
213
    def test_annotated_edited_merged_file_ids(self):
 
214
        self._create_merged_file()
 
215
        out, err = self.run_bzr('annotate file --show-ids')
 
216
        self.assertEqual(
 
217
            'current: | local\n'
 
218
            '    rev1 | foo\n'
 
219
            'rev1.1.1 | bar\n'
 
220
            '    rev2 | baz\n'
 
221
            '    rev1 | gam\n',
 
222
            out)
 
223
 
 
224
    def test_annotate_empty_file(self):
 
225
        tree = self.make_branch_and_tree('tree')
 
226
        self.build_tree_contents([('tree/empty', '')])
 
227
        tree.add('empty')
 
228
        tree.commit('add empty file')
 
229
 
 
230
        os.chdir('tree')
 
231
        out, err = self.run_bzr('annotate empty')
 
232
        self.assertEqual('', out)
 
233
 
 
234
    def test_annotate_nonexistant_file(self):
 
235
        tree = self.make_branch_and_tree('tree')
 
236
        self.build_tree(['tree/file'])
 
237
        tree.add(['file'])
 
238
        tree.commit('add a file')
 
239
 
 
240
        os.chdir('tree')
 
241
        out, err = self.run_bzr("annotate doesnotexist", retcode=3)
 
242
        self.assertEqual('', out)
 
243
        self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
 
244
 
 
245
    def test_annotate_without_workingtree(self):
 
246
        tree = self.make_branch_and_tree('branch')
 
247
        self.build_tree_contents([('branch/empty', '')])
 
248
        tree.add('empty')
 
249
        tree.commit('add empty file')
 
250
        bzrdir = tree.branch.bzrdir
 
251
        bzrdir.destroy_workingtree()
 
252
        self.assertFalse(bzrdir.has_workingtree())
 
253
 
 
254
        os.chdir('branch')
 
255
        out, err = self.run_bzr('annotate empty')
 
256
        self.assertEqual('', out)