/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_annotate.py

  • Committer: Martin Pool
  • Date: 2007-10-03 08:06:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071003080644-oivy0gkg98sex0ed
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).

Add new LockFailed, which doesn't imply that we failed to get it because of
contention.  Raise this if we fail to create the pending or lock directories
because of Transport errors.

UnlockableTransport is not an internal error.

ReadOnlyLockError has a message which didn't match its name or usage; it's now
deprecated and callers are updated to use LockFailed which is more appropriate.

Add zero_ninetytwo deprecation symbol.

Unify assertMatchesRe with TestCase.assertContainsRe.

When the constructor is deprecated, just say that the class is deprecated, not
the __init__ method - this works better with applyDeprecated in tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
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
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
19
"""Black-box tests for bzr.
20
20
 
21
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
 
22
command-line interface. This doesn't actually run a new interpreter but 
23
23
rather starts again from the run_bzr function.
24
24
"""
25
25
 
26
26
 
27
27
import os
28
28
 
29
 
from bzrlib.branch import Branch
30
 
from bzrlib.config import extract_email_address
31
29
from bzrlib.tests import TestCaseWithTransport
32
 
from bzrlib.urlutils import joinpath
33
30
 
34
31
 
35
32
class TestAnnotate(TestCaseWithTransport):
140
137
        out, err = self.run_bzr('annotate hello.txt -r 10',
141
138
                                retcode=3)
142
139
        self.assertEqual('', out)
143
 
        self.assertContainsRe(err, "Requested revision: '10' does not exist")
 
140
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
144
141
 
145
142
    def test_annotate_cmd_two_revisions(self):
146
143
        out, err = self.run_bzr('annotate hello.txt -r1..2',
147
144
                                retcode=3)
148
145
        self.assertEqual('', out)
149
146
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
150
 
                         ' exactly one revision identifier\n',
 
147
                         ' exactly 1 argument\n',
151
148
                         err)
152
149
 
153
 
 
154
 
class TestSimpleAnnotate(TestCaseWithTransport):
155
 
    """Annotate tests with no complex setup."""
156
 
 
157
 
    def _setup_edited_file(self, relpath='.'):
158
 
        """Create a tree with a locally edited file."""
159
 
        tree = self.make_branch_and_tree(relpath)
160
 
        file_relpath = joinpath(relpath, 'file')
161
 
        self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
162
 
        tree.add('file')
163
 
        tree.commit('add file', committer="test@host", rev_id="rev1")
164
 
        self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
165
 
        tree.branch.get_config().set_user_option('email', 'current@host2')
166
 
        return tree
167
 
 
168
 
    def test_annotate_cmd_revspec_branch(self):
169
 
        tree = self._setup_edited_file('trunk')
170
 
        tree.branch.create_checkout(self.get_url('work'), lightweight=True)
171
 
        os.chdir('work')
172
 
        out, err = self.run_bzr('annotate file -r branch:../trunk')
173
 
        self.assertEqual('', err)
174
 
        self.assertEqual(
175
 
            '1   test@ho | foo\n'
176
 
            '            | gam\n',
177
 
            out)
178
 
 
179
 
    def test_annotate_edited_file(self):
180
 
        tree = self._setup_edited_file()
181
 
        out, err = self.run_bzr('annotate file')
182
 
        self.assertEqual(
183
 
            '1   test@ho | foo\n'
184
 
            '2?  current | bar\n'
185
 
            '1   test@ho | gam\n',
186
 
            out)
187
 
 
188
 
    def test_annotate_edited_file_show_ids(self):
189
 
        tree = self._setup_edited_file()
190
 
        out, err = self.run_bzr('annotate file --show-ids')
191
 
        self.assertEqual(
192
 
            '    rev1 | foo\n'
193
 
            'current: | bar\n'
194
 
            '    rev1 | gam\n',
195
 
            out)
196
 
 
197
 
    def _create_merged_file(self):
198
 
        """Create a file with a pending merge and local edit."""
199
 
        tree = self.make_branch_and_tree('.')
200
 
        self.build_tree_contents([('file', 'foo\ngam\n')])
201
 
        tree.add('file')
202
 
        tree.commit('add file', rev_id="rev1", committer="test@host")
203
 
        # right side
204
 
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
205
 
        tree.commit("right", rev_id="rev1.1.1", committer="test@host")
206
 
        tree.pull(tree.branch, True, "rev1")
207
 
        # left side
208
 
        self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
209
 
        tree.commit("left", rev_id="rev2", committer="test@host")
210
 
        # merge
211
 
        tree.merge_from_branch(tree.branch, "rev1.1.1")
212
 
        # edit the file to be 'resolved' and have a further local edit
213
 
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
214
 
 
215
 
    def test_annotated_edited_merged_file_revnos(self):
216
 
        self._create_merged_file()
217
 
        out, err = self.run_bzr('annotate file')
218
 
        email = extract_email_address(Branch.open('.').get_config().username())
219
 
        self.assertEqual(
220
 
            '3?    %-7s | local\n'
221
 
            '1     test@ho | foo\n'
222
 
            '1.1.1 test@ho | bar\n'
223
 
            '2     test@ho | baz\n'
224
 
            '1     test@ho | gam\n' % email[:7],
225
 
            out)
226
 
 
227
 
    def test_annotated_edited_merged_file_ids(self):
228
 
        self._create_merged_file()
229
 
        out, err = self.run_bzr('annotate file --show-ids')
230
 
        self.assertEqual(
231
 
            'current: | local\n'
232
 
            '    rev1 | foo\n'
233
 
            'rev1.1.1 | bar\n'
234
 
            '    rev2 | baz\n'
235
 
            '    rev1 | gam\n',
236
 
            out)
237
 
 
238
150
    def test_annotate_empty_file(self):
239
151
        tree = self.make_branch_and_tree('tree')
240
152
        self.build_tree_contents([('tree/empty', '')])
245
157
        out, err = self.run_bzr('annotate empty')
246
158
        self.assertEqual('', out)
247
159
 
248
 
    def test_annotate_empty_file_show_ids(self):
249
 
        tree = self.make_branch_and_tree('tree')
250
 
        self.build_tree_contents([('tree/empty', '')])
251
 
        tree.add('empty')
252
 
        tree.commit('add empty file')
253
 
 
254
 
        os.chdir('tree')
255
 
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
256
 
        self.assertEqual('', out)
257
 
 
258
160
    def test_annotate_nonexistant_file(self):
259
161
        tree = self.make_branch_and_tree('tree')
260
162
        self.build_tree(['tree/file'])
265
167
        out, err = self.run_bzr("annotate doesnotexist", retcode=3)
266
168
        self.assertEqual('', out)
267
169
        self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
268
 
 
269
 
    def test_annotate_without_workingtree(self):
270
 
        tree = self.make_branch_and_tree('branch')
271
 
        self.build_tree_contents([('branch/empty', '')])
272
 
        tree.add('empty')
273
 
        tree.commit('add empty file')
274
 
        bzrdir = tree.branch.bzrdir
275
 
        bzrdir.destroy_workingtree()
276
 
        self.assertFalse(bzrdir.has_workingtree())
277
 
 
278
 
        os.chdir('branch')
279
 
        out, err = self.run_bzr('annotate empty')
280
 
        self.assertEqual('', out)