/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# 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
16
17
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz cat.
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
19
"""
20
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from ... import tests
22
from ..matchers import ContainsNoVfsCalls
23
from ...transport import memory
4695.3.1 by Vincent Ladeuil
Fix test failures with no C extensions loaded.
24
25
26
class TestCat(tests.TestCaseWithTransport):
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
27
28
    def test_cat(self):
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
29
        tree = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
30
        self.build_tree_contents([('branch/a', b'foo\n')])
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
31
        tree.add('a')
6622.1.29 by Jelmer Vernooij
Fix some more tests.
32
        # 'brz cat' without an option should cat the last revision
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
33
        self.run_bzr(['cat', 'a'], retcode=3, working_dir='branch')
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
34
35
        tree.commit(message='1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
36
        self.build_tree_contents([('branch/a', b'baz\n')])
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
37
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
38
        self.assertEqual('foo\n',
7143.15.2 by Jelmer Vernooij
Run autopep8.
39
                         self.run_bzr(['cat', 'a'], working_dir='branch')[0])
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
40
5967.10.2 by Martin Pool
Re-add one out-of-process test for cat on Windows
41
        # On Windows, we used to have a bug where newlines got changed into
42
        # crlf, whereas cat ought to write out the file exactly as it's
43
        # recorded (by default.)  That problem can't be reproduced in-process,
7143.15.2 by Jelmer Vernooij
Run autopep8.
44
        # so we need just one test here that
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
45
        self.assertEqual(b'foo\n',
7143.15.2 by Jelmer Vernooij
Run autopep8.
46
                         self.run_bzr_subprocess(['cat', 'a'],
47
                                                 working_dir='branch')[0])
5967.10.2 by Martin Pool
Re-add one out-of-process test for cat on Windows
48
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
49
        tree.commit(message='2')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
50
        self.assertEqual(
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
51
            'baz\n', self.run_bzr(['cat', 'a'], working_dir='branch')[0])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
52
        self.assertEqual(
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
53
            'foo\n', self.run_bzr(['cat', 'a', '-r', '1'],
54
                                  working_dir='branch')[0])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
55
        self.assertEqual(
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
56
            'baz\n', self.run_bzr(['cat', 'a', '-r', '-1'],
57
                                  working_dir='branch')[0])
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
58
2738.4.1 by Daniel Watkins
Merged original changes and tweaked cat.
59
        rev_id = tree.branch.last_revision()
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
60
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
61
        self.assertEqual(
7045.4.8 by Jelmer Vernooij
Fix another 128 tests on python 3.
62
            'baz\n', self.run_bzr(
63
                ['cat', 'a', '-r', 'revid:%s' % rev_id.decode('utf-8')],
64
                working_dir='branch')[0])
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
65
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
66
        self.assertEqual('foo\n',
7143.15.2 by Jelmer Vernooij
Run autopep8.
67
                         self.run_bzr(['cat', 'branch/a',
68
                                       '-r', 'revno:1:branch'])[0])
2738.4.7 by Martin Pool
Fix up calls to run_bzr from test_cat
69
        self.run_bzr(['cat', 'a'], retcode=3)
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
70
        self.run_bzr(['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
71
                     retcode=3)
2664.13.1 by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate.
72
2073.2.4 by wang
Fix syntax error in test.
73
    def test_cat_different_id(self):
2073.2.1 by wang
``bzr cat`` can look up contents of removed or renamed files. If the
74
        """'cat' works with old and new files"""
4695.3.2 by Vincent Ladeuil
Simplified and claried as per Robert's review.
75
        self.disable_missing_extensions_warning()
2073.2.4 by wang
Fix syntax error in test.
76
        tree = self.make_branch_and_tree('.')
2073.2.3 by wang
Change option name to --name-from-revision. Always make new tree the
77
        # the files are named after their path in the revision and
78
        # current trees later in the test case
79
        # a-rev-tree is special because it appears in both the revision
80
        # tree and the working tree
6855.4.1 by Jelmer Vernooij
Yet more bees.
81
        self.build_tree_contents([('a-rev-tree', b'foo\n'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
82
                                  ('c-rev', b'baz\n'), ('d-rev', b'bar\n'), ('e-rev', b'qux\n')])
6874.2.1 by Jelmer Vernooij
Make Tree.iter_files_bytes() take paths rather than file_ids.
83
        with tree.lock_write():
4112.1.1 by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in
84
            tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
85
            tree.commit('add test files', rev_id=b'first')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
86
            # remove currently uses self._write_inventory -
2255.7.70 by Robert Collins
Workaround WorkingTree4 not having a native remove() in test_cat.
87
            # work around that for now.
88
            tree.flush()
2073.2.3 by wang
Change option name to --name-from-revision. Always make new tree the
89
            tree.remove(['d-rev'])
90
            tree.rename_one('a-rev-tree', 'b-tree')
91
            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
92
            tree.rename_one('e-rev', 'old-rev')
6855.4.1 by Jelmer Vernooij
Yet more bees.
93
            self.build_tree_contents([('e-rev', b'new\n')])
4112.1.1 by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in
94
            tree.add(['e-rev'])
2073.2.3 by wang
Change option name to --name-from-revision. Always make new tree the
95
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
96
        # 'b-tree' is not present in the old tree.
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
97
        self.run_bzr_error(["^brz: ERROR: u?'b-tree' "
98
                            "is not present in revision .+$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
99
                           '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
100
101
        # get to the old file automatically
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
102
        out, err = self.run_bzr('cat d-rev')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
103
        self.assertEqual('', err)
104
        self.assertEqual('bar\n', out)
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
105
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
106
        out, err = \
7143.15.2 by Jelmer Vernooij
Run autopep8.
107
            self.run_bzr('cat a-rev-tree --name-from-revision')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
108
        self.assertEqual('foo\n', out)
109
        self.assertEqual('', err)
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
110
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
111
        out, err = self.run_bzr('cat a-rev-tree')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
112
        self.assertEqual('baz\n', out)
113
        self.assertEqual('', err)
2379.6.1 by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32
114
4112.1.1 by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in
115
        # the actual file-id for e-rev doesn't exist in the old tree
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
116
        out, err = self.run_bzr('cat e-rev -rrevid:first')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
117
        self.assertEqual('qux\n', out)
118
        self.assertEqual('', err)
4112.1.1 by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in
119
2158.1.1 by Wouter van Heyst
Fix #73500 mostly by catching a NotLocalUrl exception in cmd_cat.
120
    def test_remote_cat(self):
121
        wt = self.make_branch_and_tree('.')
2158.1.2 by Wouter van Heyst
Actually check if cat returns the right content.
122
        self.build_tree(['README'])
2158.1.1 by Wouter van Heyst
Fix #73500 mostly by catching a NotLocalUrl exception in cmd_cat.
123
        wt.add('README')
124
        wt.commit('Making sure there is a basis_tree available')
125
126
        url = self.get_readonly_url() + '/README'
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
127
        out, err = self.run_bzr(['cat', url])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
128
        self.assertEqual('contents of README\n', out)
2309.1.1 by James Westby
Allow bzr cat to be used against treeless repositories.
129
4948.4.1 by Andrew Bennetts
Fix ObjectNotLocked error in cmd_cat (and also release locks slightly sooner).
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
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
137
        out, err = self.run_bzr(['cat', '-r', 'branch:../a', 'README'],
138
                                working_dir='b')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
139
        self.assertEqual('contents of a/README\n', out)
4948.4.1 by Andrew Bennetts
Fix ObjectNotLocked error in cmd_cat (and also release locks slightly sooner).
140
3368.2.31 by Ian Clatworthy
add --filters option to cat command
141
    def test_cat_filters(self):
142
        wt = self.make_branch_and_tree('.')
143
        self.build_tree(['README'])
144
        wt.add('README')
145
        wt.commit('Making sure there is a basis_tree available')
146
        url = self.get_readonly_url() + '/README'
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
147
3368.2.31 by Ian Clatworthy
add --filters option to cat command
148
        # Test unfiltered output
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
149
        out, err = self.run_bzr(['cat', url])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
150
        self.assertEqual('contents of README\n', out)
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
151
152
        # Test --filters option is legal but has no impact if no filters
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
153
        out, err = self.run_bzr(['cat', '--filters', url])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
154
        self.assertEqual('contents of README\n', out)
3368.2.31 by Ian Clatworthy
add --filters option to cat command
155
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
156
    def test_cat_filters_applied(self):
157
        # Test filtering applied to output. This is tricky to do in a
158
        # subprocess because we really need to patch in a plugin that
159
        # registers the filters. Instead, we patch in a custom
160
        # filter_stack and use run_bzr() ...
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
161
        from ..test_filters import _stack_2
162
        from ...tree import Tree
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
163
        wt = self.make_branch_and_tree('.')
164
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
165
            ('README', b"junk\nline 1 of README\nline 2 of README\n"),
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
166
            ])
167
        wt.add('README')
168
        wt.commit('Making sure there is a basis_tree available')
169
        url = self.get_readonly_url() + '/README'
170
        real_content_filter_stack = Tree._content_filter_stack
7143.15.2 by Jelmer Vernooij
Run autopep8.
171
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
172
        def _custom_content_filter_stack(tree, path=None, file_id=None):
173
            return _stack_2
174
        Tree._content_filter_stack = _custom_content_filter_stack
175
        try:
176
            out, err = self.run_bzr(['cat', url, '--filters'])
177
            # The filter stack will remove the first line and swapcase the rest
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
178
            self.assertEqual('LINE 1 OF readme\nLINE 2 OF readme\n', out)
179
            self.assertEqual('', err)
3368.2.48 by Ian Clatworthy
apply first round of poolie's review feedback
180
        finally:
181
            Tree._content_filter_stack = real_content_filter_stack
182
2309.1.1 by James Westby
Allow bzr cat to be used against treeless repositories.
183
    def test_cat_no_working_tree(self):
184
        wt = self.make_branch_and_tree('.')
185
        self.build_tree(['README'])
186
        wt.add('README')
187
        wt.commit('Making sure there is a basis_tree available')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
188
        wt.branch.controldir.destroy_workingtree()
2309.1.1 by James Westby
Allow bzr cat to be used against treeless repositories.
189
190
        url = self.get_readonly_url() + '/README'
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
191
        out, err = self.run_bzr(['cat', url])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
192
        self.assertEqual('contents of README\n', out)
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
193
3063.4.2 by John Arbash Meinel
Fix 'nonexistent'
194
    def test_cat_nonexistent_branch(self):
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
195
        self.vfs_transport_factory = memory.MemoryServer
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
196
        self.run_bzr_error(['^brz: ERROR: Not a branch'],
4702.2.1 by Vincent Ladeuil
Remove bogus config imports left in previous tweak
197
                           ['cat', self.get_url()])
5171.3.5 by Martin von Gagern
Add blackbox test for cat --directory.
198
199
    def test_cat_directory(self):
200
        wt = self.make_branch_and_tree('a')
201
        self.build_tree(['a/README'])
202
        wt.add('README')
203
        wt.commit('Making sure there is a basis_tree available')
204
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
205
        out, err = self.run_bzr(['cat', '--directory=a', 'README'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
206
        self.assertEqual('contents of a/README\n', out)
5171.3.5 by Martin von Gagern
Add blackbox test for cat --directory.
207
208
    def test_cat_remote_directory(self):
209
        wt = self.make_branch_and_tree('a')
210
        self.build_tree(['a/README'])
211
        wt.add('README')
212
        wt.commit('Making sure there is a basis_tree available')
213
214
        url = self.get_readonly_url() + '/a'
5967.10.1 by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine
215
        out, err = self.run_bzr(['cat', '-d', url, 'README'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
216
        self.assertEqual('contents of a/README\n', out)
6283.1.1 by Jelmer Vernooij
Add hpss call count test for 'bzr cat'.
217
218
219
class TestSmartServerCat(tests.TestCaseWithTransport):
220
221
    def test_simple_branch_cat(self):
222
        self.setup_smart_server_with_call_log()
223
        t = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
224
        self.build_tree_contents([('branch/foo', b'thecontents')])
6283.1.1 by Jelmer Vernooij
Add hpss call count test for 'bzr cat'.
225
        t.add("foo")
226
        t.commit("message")
227
        self.reset_smart_call_log()
228
        out, err = self.run_bzr(['cat', "%s/foo" % self.get_url('branch')])
229
        # This figure represent the amount of work to perform this use case. It
230
        # is entirely ok to reduce this number if a test fails due to rpc_count
231
        # being too low. If rpc_count increases, more network roundtrips have
232
        # become necessary for this use case. Please do not adjust this number
233
        # upwards without agreement from bzr's network support maintainers.
6282.6.11 by Jelmer Vernooij
Adjust some call counts.
234
        self.assertLength(9, self.hpss_calls)
6366.1.1 by Jelmer Vernooij
Add test for cat connection count.
235
        self.assertLength(1, self.hpss_connections)
6282.6.42 by Jelmer Vernooij
merge hpss-get-checkout-format.
236
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)