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. |
1 |
# Copyright (C) 2005-2012 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 |
||
18 |
"""Black-box tests for bzr cat.
|
|
19 |
"""
|
|
20 |
||
4702.2.1
by Vincent Ladeuil
Remove bogus config imports left in previous tweak |
21 |
from bzrlib import tests |
6352.2.3
by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/. |
22 |
from bzrlib.tests.matchers import ContainsNoVfsCalls |
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. |
23 |
from bzrlib.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') |
30 |
self.build_tree_contents([('branch/a', 'foo\n')]) |
|
31 |
tree.add('a') |
|
1185.50.9
by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision |
32 |
# 'bzr 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') |
|
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. |
36 |
self.build_tree_contents([('branch/a', 'baz\n')]) |
2664.13.1
by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate. |
37 |
|
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. |
38 |
self.assertEquals('foo\n', |
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,
|
|
44 |
# so we need just one test here that
|
|
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. |
45 |
self.assertEquals('foo\n', |
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') |
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. |
50 |
self.assertEquals( |
51 |
'baz\n', self.run_bzr(['cat', 'a'], working_dir='branch')[0]) |
|
52 |
self.assertEquals( |
|
53 |
'foo\n', self.run_bzr(['cat', 'a', '-r', '1'], |
|
54 |
working_dir='branch')[0]) |
|
55 |
self.assertEquals( |
|
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 |
|
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. |
61 |
self.assertEquals( |
62 |
'baz\n', self.run_bzr(['cat', 'a', '-r', 'revid:%s' % rev_id], |
|
63 |
working_dir='branch')[0]) |
|
64 |
||
65 |
self.assertEquals('foo\n', |
|
66 |
self.run_bzr(['cat', 'branch/a', |
|
67 |
'-r', 'revno:1:branch'])[0]) |
|
2738.4.7
by Martin Pool
Fix up calls to run_bzr from test_cat |
68 |
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. |
69 |
self.run_bzr(['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'], |
70 |
retcode=3) |
|
2664.13.1
by Daniel Watkins
tests.blackbox.test_cat now uses internals where appropriate. |
71 |
|
2073.2.4
by wang
Fix syntax error in test. |
72 |
def test_cat_different_id(self): |
2073.2.1
by wang
``bzr cat`` can look up contents of removed or renamed files. If the |
73 |
"""'cat' works with old and new files"""
|
4695.3.2
by Vincent Ladeuil
Simplified and claried as per Robert's review. |
74 |
self.disable_missing_extensions_warning() |
2073.2.4
by wang
Fix syntax error in test. |
75 |
tree = self.make_branch_and_tree('.') |
2073.2.3
by wang
Change option name to --name-from-revision. Always make new tree the |
76 |
# the files are named after their path in the revision and
|
77 |
# current trees later in the test case
|
|
78 |
# a-rev-tree is special because it appears in both the revision
|
|
79 |
# tree and the working tree
|
|
80 |
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 |
81 |
('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 |
82 |
tree.lock_write() |
83 |
try: |
|
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']) |
85 |
tree.commit('add test files', rev_id='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') |
93 |
self.build_tree_contents([('e-rev', 'new\n')]) |
|
94 |
tree.add(['e-rev']) |
|
2073.2.3
by wang
Change option name to --name-from-revision. Always make new tree the |
95 |
finally: |
2379.6.1
by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32 |
96 |
# 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 |
97 |
tree.unlock() |
98 |
||
2379.6.1
by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32 |
99 |
# 'b-tree' is not present in the old tree.
|
100 |
self.run_bzr_error(["^bzr: ERROR: u?'b-tree' " |
|
101 |
"is not present in revision .+$"], |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
102 |
'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 |
103 |
|
104 |
# 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 |
105 |
out, err = self.run_bzr('cat d-rev') |
2379.6.1
by Alexander Belchenko
blackbox: test_cat_different_id: calling bzr as another process require free lock on win32 |
106 |
self.assertEqual('bar\n', out) |
107 |
self.assertEqual('', err) |
|
108 |
||
2738.4.6
by Daniel Watkins
Rewrapped lines longer than 79 characters. |
109 |
out, err = \ |
5967.10.1
by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine |
110 |
self.run_bzr('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 |
111 |
self.assertEqual('foo\n', out) |
112 |
self.assertEqual('', err) |
|
113 |
||
5967.10.1
by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine |
114 |
out, err = self.run_bzr('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 |
115 |
self.assertEqual('baz\n', out) |
116 |
self.assertEqual('', err) |
|
117 |
||
4112.1.1
by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in |
118 |
# 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 |
119 |
out, err = self.run_bzr('cat e-rev -rrevid:first') |
4112.1.1
by Vincent Ladeuil
Fallback to old revision id if the current one doesn't exist in |
120 |
self.assertEqual('qux\n', out) |
121 |
self.assertEqual('', err) |
|
122 |
||
2158.1.1
by Wouter van Heyst
Fix #73500 mostly by catching a NotLocalUrl exception in cmd_cat. |
123 |
def test_remote_cat(self): |
124 |
wt = self.make_branch_and_tree('.') |
|
2158.1.2
by Wouter van Heyst
Actually check if cat returns the right content. |
125 |
self.build_tree(['README']) |
2158.1.1
by Wouter van Heyst
Fix #73500 mostly by catching a NotLocalUrl exception in cmd_cat. |
126 |
wt.add('README') |
127 |
wt.commit('Making sure there is a basis_tree available') |
|
128 |
||
129 |
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 |
130 |
out, err = self.run_bzr(['cat', url]) |
2158.1.2
by Wouter van Heyst
Actually check if cat returns the right content. |
131 |
self.assertEqual('contents of README\n', out) |
2309.1.1
by James Westby
Allow bzr cat to be used against treeless repositories. |
132 |
|
4948.4.1
by Andrew Bennetts
Fix ObjectNotLocked error in cmd_cat (and also release locks slightly sooner). |
133 |
def test_cat_branch_revspec(self): |
134 |
wt = self.make_branch_and_tree('a') |
|
135 |
self.build_tree(['a/README']) |
|
136 |
wt.add('README') |
|
137 |
wt.commit('Making sure there is a basis_tree available') |
|
138 |
wt = self.make_branch_and_tree('b') |
|
139 |
||
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. |
140 |
out, err = self.run_bzr(['cat', '-r', 'branch:../a', 'README'], |
141 |
working_dir='b') |
|
4948.4.1
by Andrew Bennetts
Fix ObjectNotLocked error in cmd_cat (and also release locks slightly sooner). |
142 |
self.assertEqual('contents of a/README\n', out) |
143 |
||
3368.2.31
by Ian Clatworthy
add --filters option to cat command |
144 |
def test_cat_filters(self): |
145 |
wt = self.make_branch_and_tree('.') |
|
146 |
self.build_tree(['README']) |
|
147 |
wt.add('README') |
|
148 |
wt.commit('Making sure there is a basis_tree available') |
|
149 |
url = self.get_readonly_url() + '/README' |
|
3368.2.48
by Ian Clatworthy
apply first round of poolie's review feedback |
150 |
|
3368.2.31
by Ian Clatworthy
add --filters option to cat command |
151 |
# Test unfiltered output
|
5967.10.1
by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine |
152 |
out, err = self.run_bzr(['cat', url]) |
3368.2.31
by Ian Clatworthy
add --filters option to cat command |
153 |
self.assertEqual('contents of README\n', out) |
3368.2.48
by Ian Clatworthy
apply first round of poolie's review feedback |
154 |
|
155 |
# 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 |
156 |
out, err = self.run_bzr(['cat', '--filters', url]) |
3368.2.31
by Ian Clatworthy
add --filters option to cat command |
157 |
self.assertEqual('contents of README\n', out) |
158 |
||
3368.2.48
by Ian Clatworthy
apply first round of poolie's review feedback |
159 |
def test_cat_filters_applied(self): |
160 |
# Test filtering applied to output. This is tricky to do in a
|
|
161 |
# subprocess because we really need to patch in a plugin that
|
|
162 |
# registers the filters. Instead, we patch in a custom
|
|
163 |
# filter_stack and use run_bzr() ...
|
|
164 |
from cStringIO import StringIO |
|
165 |
from bzrlib.commands import run_bzr |
|
166 |
from bzrlib.tests.test_filters import _stack_2 |
|
167 |
from bzrlib.trace import mutter |
|
168 |
from bzrlib.tree import Tree |
|
169 |
wt = self.make_branch_and_tree('.') |
|
170 |
self.build_tree_contents([ |
|
171 |
('README', "junk\nline 1 of README\nline 2 of README\n"), |
|
172 |
])
|
|
173 |
wt.add('README') |
|
174 |
wt.commit('Making sure there is a basis_tree available') |
|
175 |
url = self.get_readonly_url() + '/README' |
|
176 |
real_content_filter_stack = Tree._content_filter_stack |
|
177 |
def _custom_content_filter_stack(tree, path=None, file_id=None): |
|
178 |
return _stack_2 |
|
179 |
Tree._content_filter_stack = _custom_content_filter_stack |
|
180 |
try: |
|
181 |
out, err = self.run_bzr(['cat', url, '--filters']) |
|
182 |
# The filter stack will remove the first line and swapcase the rest
|
|
183 |
self.assertEqual('LINE 1 OF readme\nLINE 2 OF readme\n', out) |
|
184 |
self.assertEqual('', err) |
|
185 |
finally: |
|
186 |
Tree._content_filter_stack = real_content_filter_stack |
|
187 |
||
2309.1.1
by James Westby
Allow bzr cat to be used against treeless repositories. |
188 |
def test_cat_no_working_tree(self): |
189 |
wt = self.make_branch_and_tree('.') |
|
190 |
self.build_tree(['README']) |
|
191 |
wt.add('README') |
|
192 |
wt.commit('Making sure there is a basis_tree available') |
|
193 |
wt.branch.bzrdir.destroy_workingtree() |
|
194 |
||
195 |
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 |
196 |
out, err = self.run_bzr(['cat', url]) |
2309.1.1
by James Westby
Allow bzr cat to be used against treeless repositories. |
197 |
self.assertEqual('contents of README\n', out) |
2738.4.6
by Daniel Watkins
Rewrapped lines longer than 79 characters. |
198 |
|
3063.4.2
by John Arbash Meinel
Fix 'nonexistent' |
199 |
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. |
200 |
self.vfs_transport_factory = memory.MemoryServer |
4702.2.1
by Vincent Ladeuil
Remove bogus config imports left in previous tweak |
201 |
self.run_bzr_error(['^bzr: ERROR: Not a branch'], |
202 |
['cat', self.get_url()]) |
|
5171.3.5
by Martin von Gagern
Add blackbox test for cat --directory. |
203 |
|
204 |
def test_cat_directory(self): |
|
205 |
wt = self.make_branch_and_tree('a') |
|
206 |
self.build_tree(['a/README']) |
|
207 |
wt.add('README') |
|
208 |
wt.commit('Making sure there is a basis_tree available') |
|
209 |
||
5967.10.1
by Martin Pool
Stop unnecessary use of subprocesses in blackbox.test_cat: about 7x faster on wine |
210 |
out, err = self.run_bzr(['cat', '--directory=a', 'README']) |
5171.3.5
by Martin von Gagern
Add blackbox test for cat --directory. |
211 |
self.assertEqual('contents of a/README\n', out) |
212 |
||
213 |
def test_cat_remote_directory(self): |
|
214 |
wt = self.make_branch_and_tree('a') |
|
215 |
self.build_tree(['a/README']) |
|
216 |
wt.add('README') |
|
217 |
wt.commit('Making sure there is a basis_tree available') |
|
218 |
||
219 |
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 |
220 |
out, err = self.run_bzr(['cat', '-d', url, 'README']) |
5171.3.5
by Martin von Gagern
Add blackbox test for cat --directory. |
221 |
self.assertEqual('contents of a/README\n', out) |
6283.1.1
by Jelmer Vernooij
Add hpss call count test for 'bzr cat'. |
222 |
|
223 |
||
224 |
class TestSmartServerCat(tests.TestCaseWithTransport): |
|
225 |
||
226 |
def test_simple_branch_cat(self): |
|
227 |
self.setup_smart_server_with_call_log() |
|
228 |
t = self.make_branch_and_tree('branch') |
|
229 |
self.build_tree_contents([('branch/foo', 'thecontents')]) |
|
230 |
t.add("foo") |
|
231 |
t.commit("message") |
|
232 |
self.reset_smart_call_log() |
|
233 |
out, err = self.run_bzr(['cat', "%s/foo" % self.get_url('branch')]) |
|
234 |
# This figure represent the amount of work to perform this use case. It
|
|
235 |
# is entirely ok to reduce this number if a test fails due to rpc_count
|
|
236 |
# being too low. If rpc_count increases, more network roundtrips have
|
|
237 |
# become necessary for this use case. Please do not adjust this number
|
|
238 |
# upwards without agreement from bzr's network support maintainers.
|
|
6282.6.11
by Jelmer Vernooij
Adjust some call counts. |
239 |
self.assertLength(9, self.hpss_calls) |
6366.1.1
by Jelmer Vernooij
Add test for cat connection count. |
240 |
self.assertLength(1, self.hpss_connections) |
6282.6.42
by Jelmer Vernooij
merge hpss-get-checkout-format. |
241 |
self.assertThat(self.hpss_calls, ContainsNoVfsCalls) |