/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005 Canonical Ltd
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
2
# -*- coding: utf-8 -*-
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
3
#
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
8
#
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
13
#
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
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
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
17
18
19
"""Black-box tests for bzr cat.
20
"""
21
22
import os
3063.4.1 by Lukáš Lalinský
Fix UnboundLocalError in cmd_cat.
23
import sys
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
24
4702.2.1 by Vincent Ladeuil
Remove bogus config imports left in previous tweak
25
from bzrlib import tests
4695.3.1 by Vincent Ladeuil
Fix test failures with no C extensions loaded.
26
27
28
class TestCat(tests.TestCaseWithTransport):
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
29
30
    def test_cat(self):
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
31
        tree = self.make_branch_and_tree('branch')
32
        self.build_tree_contents([('branch/a', 'foo\n')])
33
        tree.add('a')
1907.4.3 by Matthieu Moy
bzr cat now works nicely with revno:N:path too
34
        os.chdir('branch')
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
35
        # 'bzr cat' without an option should cat the last revision
2738.4.7 by Martin Pool
Fix up calls to run_bzr from test_cat
36
        self.run_bzr(['cat', 'a'], retcode=3)
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
37
38
        tree.commit(message='1')
39
        self.build_tree_contents([('a', 'baz\n')])
40
2738.4.3 by Daniel Watkins
Converted run_bzr to run_bzr_subprocess where appropriate in cat.
41
        # We use run_bzr_subprocess rather than run_bzr here so that we can
42
        # test mangling of line-endings on Windows.
2738.4.7 by Martin Pool
Fix up calls to run_bzr from test_cat
43
        self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'foo\n')
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
44
45
        tree.commit(message='2')
2738.4.7 by Martin Pool
Fix up calls to run_bzr from test_cat
46
        self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'baz\n')
47
        self.assertEquals(self.run_bzr_subprocess(
48
            ['cat', 'a', '-r', '1'])[0],
49
            'foo\n')
50
        self.assertEquals(self.run_bzr_subprocess(
51
            ['cat', 'a', '-r', '-1'])[0],
52
            'baz\n')
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
53
2738.4.1 by Daniel Watkins
Merged original changes and tweaked cat.
54
        rev_id = tree.branch.last_revision()
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
55
2738.4.7 by Martin Pool
Fix up calls to run_bzr from test_cat
56
        self.assertEquals(self.run_bzr_subprocess(
57
            ['cat', 'a', '-r', 'revid:%s' % rev_id])[0],
58
            'baz\n')
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
59
1907.4.3 by Matthieu Moy
bzr cat now works nicely with revno:N:path too
60
        os.chdir('..')
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
61
2738.4.7 by Martin Pool
Fix up calls to run_bzr from test_cat
62
        self.assertEquals(self.run_bzr_subprocess(
63
            ['cat', 'branch/a', '-r', 'revno:1:branch'])[0],
64
            'foo\n')
65
        self.run_bzr(['cat', 'a'], retcode=3)
66
        self.run_bzr(
67
                ['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
68
                retcode=3)
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
69
2073.2.4 by wang
Fix syntax error in test.
70
    def test_cat_different_id(self):
2073.2.1 by wang
``bzr cat`` can look up contents of removed or renamed files. If the
71
        """'cat' works with old and new files"""
4695.3.2 by Vincent Ladeuil
Simplified and claried as per Robert's review.
72
        self.disable_missing_extensions_warning()
2073.2.4 by wang
Fix syntax error in test.
73
        tree = self.make_branch_and_tree('.')
2073.2.3 by wang
Change option name to --name-from-revision. Always make new tree the
74
        # the files are named after their path in the revision and
75
        # current trees later in the test case
76
        # a-rev-tree is special because it appears in both the revision
77
        # tree and the working tree
78
        self.build_tree_contents([('a-rev-tree', 'foo\n'),
4112.1.1 by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in
79
            ('c-rev', 'baz\n'), ('d-rev', 'bar\n'), ('e-rev', 'qux\n')])
2073.2.3 by wang
Change option name to --name-from-revision. Always make new tree the
80
        tree.lock_write()
81
        try:
4112.1.1 by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in
82
            tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
83
            tree.commit('add test files', rev_id='first')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
84
            # remove currently uses self._write_inventory -
2255.7.70 by Robert Collins
Workaround WorkingTree4 not having a native remove() in test_cat.
85
            # work around that for now.
86
            tree.flush()
2073.2.3 by wang
Change option name to --name-from-revision. Always make new tree the
87
            tree.remove(['d-rev'])
88
            tree.rename_one('a-rev-tree', 'b-tree')
89
            tree.rename_one('c-rev', 'a-rev-tree')
4112.1.1 by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in
90
            tree.rename_one('e-rev', 'old-rev')
91
            self.build_tree_contents([('e-rev', 'new\n')])
92
            tree.add(['e-rev'])
2073.2.3 by wang
Change option name to --name-from-revision. Always make new tree the
93
        finally:
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
94
            # calling bzr as another process require free lock on win32
2073.2.3 by wang
Change option name to --name-from-revision. Always make new tree the
95
            tree.unlock()
96
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
97
        # 'b-tree' is not present in the old tree.
98
        self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
99
                            "is not present in revision .+$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
100
                           'cat b-tree --name-from-revision')
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
101
102
        # get to the old file automatically
2738.4.3 by Daniel Watkins
Converted run_bzr to run_bzr_subprocess where appropriate in cat.
103
        out, err = self.run_bzr_subprocess('cat d-rev')
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
104
        self.assertEqual('bar\n', out)
105
        self.assertEqual('', err)
106
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
107
        out, err = \
108
                self.run_bzr_subprocess('cat a-rev-tree --name-from-revision')
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
109
        self.assertEqual('foo\n', out)
110
        self.assertEqual('', err)
111
2738.4.3 by Daniel Watkins
Converted run_bzr to run_bzr_subprocess where appropriate in cat.
112
        out, err = self.run_bzr_subprocess('cat a-rev-tree')
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
113
        self.assertEqual('baz\n', out)
114
        self.assertEqual('', err)
115
4112.1.1 by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in
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
2158.1.1 by Wouter van Heyst
Fix #73500 mostly by catching a NotLocalUrl exception in cmd_cat.
121
    def test_remote_cat(self):
122
        wt = self.make_branch_and_tree('.')
2158.1.2 by Wouter van Heyst
Actually check if cat returns the right content.
123
        self.build_tree(['README'])
2158.1.1 by Wouter van Heyst
Fix #73500 mostly by catching a NotLocalUrl exception in cmd_cat.
124
        wt.add('README')
125
        wt.commit('Making sure there is a basis_tree available')
126
127
        url = self.get_readonly_url() + '/README'
2738.4.3 by Daniel Watkins
Converted run_bzr to run_bzr_subprocess where appropriate in cat.
128
        out, err = self.run_bzr_subprocess(['cat', url])
2158.1.2 by Wouter van Heyst
Actually check if cat returns the right content.
129
        self.assertEqual('contents of README\n', out)
2309.1.1 by James Westby
Allow bzr cat to be used against treeless repositories.
130
3368.2.31 by Ian Clatworthy
add --filters option to cat command
131
    def test_cat_filters(self):
132
        wt = self.make_branch_and_tree('.')
133
        self.build_tree(['README'])
134
        wt.add('README')
135
        wt.commit('Making sure there is a basis_tree available')
136
        url = self.get_readonly_url() + '/README'
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
137
3368.2.31 by Ian Clatworthy
add --filters option to cat command
138
        # Test unfiltered output
139
        out, err = self.run_bzr_subprocess(['cat', url])
140
        self.assertEqual('contents of README\n', out)
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
141
142
        # Test --filters option is legal but has no impact if no filters
3368.2.31 by Ian Clatworthy
add --filters option to cat command
143
        out, err = self.run_bzr_subprocess(['cat', '--filters', url])
144
        self.assertEqual('contents of README\n', out)
145
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
146
    def test_cat_filters_applied(self):
147
        # Test filtering applied to output. This is tricky to do in a
148
        # subprocess because we really need to patch in a plugin that
149
        # registers the filters. Instead, we patch in a custom
150
        # filter_stack and use run_bzr() ...
151
        from cStringIO import StringIO
152
        from bzrlib.commands import run_bzr
153
        from bzrlib.tests.test_filters import _stack_2
154
        from bzrlib.trace import mutter
155
        from bzrlib.tree import Tree
156
        wt = self.make_branch_and_tree('.')
157
        self.build_tree_contents([
158
            ('README', "junk\nline 1 of README\nline 2 of README\n"),
159
            ])
160
        wt.add('README')
161
        wt.commit('Making sure there is a basis_tree available')
162
        url = self.get_readonly_url() + '/README'
163
        real_content_filter_stack = Tree._content_filter_stack
164
        def _custom_content_filter_stack(tree, path=None, file_id=None):
165
            return _stack_2
166
        Tree._content_filter_stack = _custom_content_filter_stack
167
        try:
168
            out, err = self.run_bzr(['cat', url, '--filters'])
169
            # The filter stack will remove the first line and swapcase the rest
170
            self.assertEqual('LINE 1 OF readme\nLINE 2 OF readme\n', out)
171
            self.assertEqual('', err)
172
        finally:
173
            Tree._content_filter_stack = real_content_filter_stack
174
2309.1.1 by James Westby
Allow bzr cat to be used against treeless repositories.
175
    def test_cat_no_working_tree(self):
176
        wt = self.make_branch_and_tree('.')
177
        self.build_tree(['README'])
178
        wt.add('README')
179
        wt.commit('Making sure there is a basis_tree available')
180
        wt.branch.bzrdir.destroy_workingtree()
181
182
        url = self.get_readonly_url() + '/README'
2738.4.3 by Daniel Watkins
Converted run_bzr to run_bzr_subprocess where appropriate in cat.
183
        out, err = self.run_bzr_subprocess(['cat', url])
2309.1.1 by James Westby
Allow bzr cat to be used against treeless repositories.
184
        self.assertEqual('contents of README\n', out)
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
185
3063.4.2 by John Arbash Meinel
Fix 'nonexistent'
186
    def test_cat_nonexistent_branch(self):
4702.2.1 by Vincent Ladeuil
Remove bogus config imports left in previous tweak
187
        self.vfs_transport_factory = tests.MemoryServer
188
        self.run_bzr_error(['^bzr: ERROR: Not a branch'],
189
                           ['cat', self.get_url()])