/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_cat.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 cat.
21
21
 
22
22
import os
23
23
 
24
 
from bzrlib import tests
25
 
from bzrlib.transport import memory
26
 
 
27
 
 
28
 
class TestCat(tests.TestCaseWithTransport):
 
24
from bzrlib.tests.blackbox import TestCaseWithTransport
 
25
 
 
26
class TestCat(TestCaseWithTransport):
29
27
 
30
28
    def test_cat(self):
31
29
        tree = self.make_branch_and_tree('branch')
69
67
 
70
68
    def test_cat_different_id(self):
71
69
        """'cat' works with old and new files"""
72
 
        self.disable_missing_extensions_warning()
73
70
        tree = self.make_branch_and_tree('.')
74
71
        # the files are named after their path in the revision and
75
72
        # current trees later in the test case
76
73
        # a-rev-tree is special because it appears in both the revision
77
74
        # tree and the working tree
78
75
        self.build_tree_contents([('a-rev-tree', 'foo\n'),
79
 
            ('c-rev', 'baz\n'), ('d-rev', 'bar\n'), ('e-rev', 'qux\n')])
 
76
            ('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
80
77
        tree.lock_write()
81
78
        try:
82
 
            tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
83
 
            tree.commit('add test files', rev_id='first')
84
 
            # remove currently uses self._write_inventory -
 
79
            tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
 
80
            tree.commit('add test files')
 
81
            # remove currently uses self._write_inventory - 
85
82
            # work around that for now.
86
83
            tree.flush()
87
84
            tree.remove(['d-rev'])
88
85
            tree.rename_one('a-rev-tree', 'b-tree')
89
86
            tree.rename_one('c-rev', 'a-rev-tree')
90
 
            tree.rename_one('e-rev', 'old-rev')
91
 
            self.build_tree_contents([('e-rev', 'new\n')])
92
 
            tree.add(['e-rev'])
93
87
        finally:
94
88
            # calling bzr as another process require free lock on win32
95
89
            tree.unlock()
113
107
        self.assertEqual('baz\n', out)
114
108
        self.assertEqual('', err)
115
109
 
116
 
        # the actual file-id for e-rev doesn't exist in the old tree
117
 
        out, err = self.run_bzr_subprocess('cat e-rev -rrevid:first')
118
 
        self.assertEqual('qux\n', out)
119
 
        self.assertEqual('', err)
120
 
 
121
110
    def test_remote_cat(self):
122
111
        wt = self.make_branch_and_tree('.')
123
112
        self.build_tree(['README'])
128
117
        out, err = self.run_bzr_subprocess(['cat', url])
129
118
        self.assertEqual('contents of README\n', out)
130
119
 
131
 
    def test_cat_branch_revspec(self):
132
 
        wt = self.make_branch_and_tree('a')
133
 
        self.build_tree(['a/README'])
134
 
        wt.add('README')
135
 
        wt.commit('Making sure there is a basis_tree available')
136
 
        wt = self.make_branch_and_tree('b')
137
 
        os.chdir('b')
138
 
 
139
 
        out, err = self.run_bzr_subprocess(
140
 
            ['cat', '-r', 'branch:../a', 'README'])
141
 
        self.assertEqual('contents of a/README\n', out)
142
 
 
143
 
    def test_cat_filters(self):
144
 
        wt = self.make_branch_and_tree('.')
145
 
        self.build_tree(['README'])
146
 
        wt.add('README')
147
 
        wt.commit('Making sure there is a basis_tree available')
148
 
        url = self.get_readonly_url() + '/README'
149
 
 
150
 
        # Test unfiltered output
151
 
        out, err = self.run_bzr_subprocess(['cat', url])
152
 
        self.assertEqual('contents of README\n', out)
153
 
 
154
 
        # Test --filters option is legal but has no impact if no filters
155
 
        out, err = self.run_bzr_subprocess(['cat', '--filters', url])
156
 
        self.assertEqual('contents of README\n', out)
157
 
 
158
 
    def test_cat_filters_applied(self):
159
 
        # Test filtering applied to output. This is tricky to do in a
160
 
        # subprocess because we really need to patch in a plugin that
161
 
        # registers the filters. Instead, we patch in a custom
162
 
        # filter_stack and use run_bzr() ...
163
 
        from cStringIO import StringIO
164
 
        from bzrlib.commands import run_bzr
165
 
        from bzrlib.tests.test_filters import _stack_2
166
 
        from bzrlib.trace import mutter
167
 
        from bzrlib.tree import Tree
168
 
        wt = self.make_branch_and_tree('.')
169
 
        self.build_tree_contents([
170
 
            ('README', "junk\nline 1 of README\nline 2 of README\n"),
171
 
            ])
172
 
        wt.add('README')
173
 
        wt.commit('Making sure there is a basis_tree available')
174
 
        url = self.get_readonly_url() + '/README'
175
 
        real_content_filter_stack = Tree._content_filter_stack
176
 
        def _custom_content_filter_stack(tree, path=None, file_id=None):
177
 
            return _stack_2
178
 
        Tree._content_filter_stack = _custom_content_filter_stack
179
 
        try:
180
 
            out, err = self.run_bzr(['cat', url, '--filters'])
181
 
            # The filter stack will remove the first line and swapcase the rest
182
 
            self.assertEqual('LINE 1 OF readme\nLINE 2 OF readme\n', out)
183
 
            self.assertEqual('', err)
184
 
        finally:
185
 
            Tree._content_filter_stack = real_content_filter_stack
186
 
 
187
120
    def test_cat_no_working_tree(self):
188
121
        wt = self.make_branch_and_tree('.')
189
122
        self.build_tree(['README'])
195
128
        out, err = self.run_bzr_subprocess(['cat', url])
196
129
        self.assertEqual('contents of README\n', out)
197
130
 
198
 
    def test_cat_nonexistent_branch(self):
199
 
        self.vfs_transport_factory = memory.MemoryServer
200
 
        self.run_bzr_error(['^bzr: ERROR: Not a branch'],
201
 
                           ['cat', self.get_url()])