~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-20 05:08:48 UTC
  • mfrom: (4171.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090320050848-c1wdgzf5kkfdt1ys
Content filters (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
        out, err = self.run_bzr_subprocess(['cat', url])
127
127
        self.assertEqual('contents of README\n', out)
128
128
 
 
129
    def test_cat_filters(self):
 
130
        wt = self.make_branch_and_tree('.')
 
131
        self.build_tree(['README'])
 
132
        wt.add('README')
 
133
        wt.commit('Making sure there is a basis_tree available')
 
134
        url = self.get_readonly_url() + '/README'
 
135
 
 
136
        # Test unfiltered output
 
137
        out, err = self.run_bzr_subprocess(['cat', url])
 
138
        self.assertEqual('contents of README\n', out)
 
139
 
 
140
        # Test --filters option is legal but has no impact if no filters
 
141
        out, err = self.run_bzr_subprocess(['cat', '--filters', url])
 
142
        self.assertEqual('contents of README\n', out)
 
143
 
 
144
    def test_cat_filters_applied(self):
 
145
        # Test filtering applied to output. This is tricky to do in a
 
146
        # subprocess because we really need to patch in a plugin that
 
147
        # registers the filters. Instead, we patch in a custom
 
148
        # filter_stack and use run_bzr() ...
 
149
        from cStringIO import StringIO
 
150
        from bzrlib.commands import run_bzr
 
151
        from bzrlib.tests.test_filters import _stack_2
 
152
        from bzrlib.trace import mutter
 
153
        from bzrlib.tree import Tree
 
154
        wt = self.make_branch_and_tree('.')
 
155
        self.build_tree_contents([
 
156
            ('README', "junk\nline 1 of README\nline 2 of README\n"),
 
157
            ])
 
158
        wt.add('README')
 
159
        wt.commit('Making sure there is a basis_tree available')
 
160
        url = self.get_readonly_url() + '/README'
 
161
        real_content_filter_stack = Tree._content_filter_stack
 
162
        def _custom_content_filter_stack(tree, path=None, file_id=None):
 
163
            return _stack_2
 
164
        Tree._content_filter_stack = _custom_content_filter_stack
 
165
        try:
 
166
            out, err = self.run_bzr(['cat', url, '--filters'])
 
167
            # The filter stack will remove the first line and swapcase the rest
 
168
            self.assertEqual('LINE 1 OF readme\nLINE 2 OF readme\n', out)
 
169
            self.assertEqual('', err)
 
170
        finally:
 
171
            Tree._content_filter_stack = real_content_filter_stack
 
172
 
129
173
    def test_cat_no_working_tree(self):
130
174
        wt = self.make_branch_and_tree('.')
131
175
        self.build_tree(['README'])