~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2010-02-10 15:46:03 UTC
  • mfrom: (4985.3.21 update)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: v.ladeuil+lp@free.fr-20100210154603-k4no1gvfuqpzrw7p
Update performs two merges in a more logical order but stop on conflicts

Show diffs side-by-side

added added

removed removed

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