bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
1 |
# Copyright (C) 2006 Canonical Ltd
|
2 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
|
3 |
#
|
|
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.
|
|
8 |
#
|
|
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.
|
|
13 |
#
|
|
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
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
17 |
|
18 |
"""Tests for the MemoryTree class."""
|
|
19 |
||
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
20 |
from .. import errors |
21 |
from ..memorytree import MemoryTree |
|
22 |
from . import TestCaseWithTransport |
|
23 |
from ..treebuilder import TreeBuilder |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
24 |
|
25 |
||
26 |
class TestMemoryTree(TestCaseWithTransport): |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
27 |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
28 |
def test_create_on_branch(self): |
29 |
"""Creating a mutable tree on a trivial branch works.""" |
|
30 |
branch = self.make_branch('branch') |
|
31 |
tree = MemoryTree.create_on_branch(branch) |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
32 |
self.assertEqual(branch.controldir, tree.controldir) |
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
33 |
self.assertEqual(branch, tree.branch) |
34 |
self.assertEqual([], tree.get_parent_ids()) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
35 |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
36 |
def test_create_on_branch_with_content(self): |
37 |
"""Creating a mutable tree on a non-trivial branch works.""" |
|
38 |
branch = self.make_branch('branch') |
|
39 |
tree = MemoryTree.create_on_branch(branch) |
|
40 |
# build some content
|
|
41 |
tree.lock_write() |
|
42 |
builder = TreeBuilder() |
|
43 |
builder.start_tree(tree) |
|
44 |
builder.build(['foo']) |
|
45 |
builder.finish_tree() |
|
46 |
rev_id = tree.commit('first post') |
|
47 |
tree.unlock() |
|
48 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
49 |
with tree.lock_read(): |
50 |
self.assertEqual([rev_id], tree.get_parent_ids()) |
|
51 |
with tree.get_file('foo') as f: |
|
52 |
self.assertEqual(b'contents of foo\n', f.read()) |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
53 |
|
2946.3.5
by John Arbash Meinel
MemoryTree is not tested under the tree_implementations tests. |
54 |
def test_get_root_id(self): |
55 |
branch = self.make_branch('branch') |
|
56 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.1
by Jelmer Vernooij
Support symlinks in memorytree. |
57 |
with tree.lock_write(): |
2946.3.5
by John Arbash Meinel
MemoryTree is not tested under the tree_implementations tests. |
58 |
tree.add(['']) |
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
59 |
self.assertIsNot(None, tree.path2id('')) |
2946.3.5
by John Arbash Meinel
MemoryTree is not tested under the tree_implementations tests. |
60 |
|
1986.1.8
by Robert Collins
Update to bzr.dev, which involves adding lock_tree_write to MutableTree and MemoryTree. |
61 |
def test_lock_tree_write(self): |
62 |
"""Check we can lock_tree_write and unlock MemoryTrees.""" |
|
63 |
branch = self.make_branch('branch') |
|
64 |
tree = MemoryTree.create_on_branch(branch) |
|
65 |
tree.lock_tree_write() |
|
66 |
tree.unlock() |
|
67 |
||
68 |
def test_lock_tree_write_after_read_fails(self): |
|
69 |
"""Check that we error when trying to upgrade a read lock to write.""" |
|
70 |
branch = self.make_branch('branch') |
|
71 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
72 |
with tree.lock_read(): |
73 |
self.assertRaises(errors.ReadOnlyError, tree.lock_tree_write) |
|
1986.1.8
by Robert Collins
Update to bzr.dev, which involves adding lock_tree_write to MutableTree and MemoryTree. |
74 |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
75 |
def test_lock_write(self): |
76 |
"""Check we can lock_write and unlock MemoryTrees.""" |
|
77 |
branch = self.make_branch('branch') |
|
78 |
tree = MemoryTree.create_on_branch(branch) |
|
79 |
tree.lock_write() |
|
80 |
tree.unlock() |
|
81 |
||
82 |
def test_lock_write_after_read_fails(self): |
|
83 |
"""Check that we error when trying to upgrade a read lock to write.""" |
|
84 |
branch = self.make_branch('branch') |
|
85 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
86 |
with tree.lock_read(): |
87 |
self.assertRaises(errors.ReadOnlyError, tree.lock_write) |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
88 |
|
89 |
def test_add_with_kind(self): |
|
90 |
branch = self.make_branch('branch') |
|
91 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.1
by Jelmer Vernooij
Support symlinks in memorytree. |
92 |
with tree.lock_write(): |
93 |
tree.add(['', 'afile', 'adir'], None, |
|
94 |
['directory', 'file', 'directory']) |
|
95 |
self.assertEqual('afile', tree.id2path(tree.path2id('afile'))) |
|
96 |
self.assertEqual('adir', tree.id2path(tree.path2id('adir'))) |
|
97 |
self.assertFalse(tree.has_filename('afile')) |
|
98 |
self.assertFalse(tree.has_filename('adir')) |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
99 |
|
100 |
def test_put_new_file(self): |
|
101 |
branch = self.make_branch('branch') |
|
102 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.1
by Jelmer Vernooij
Support symlinks in memorytree. |
103 |
with tree.lock_write(): |
104 |
tree.add(['', 'foo'], ids=[b'root-id', b'foo-id'], |
|
7058.6.2
by Jelmer Vernooij
Merge lp:brz. |
105 |
kinds=['directory', 'file']) |
7058.6.1
by Jelmer Vernooij
Support symlinks in memorytree. |
106 |
tree.put_file_bytes_non_atomic('foo', b'barshoom') |
7058.6.2
by Jelmer Vernooij
Merge lp:brz. |
107 |
with tree.get_file('foo') as f: |
108 |
self.assertEqual(b'barshoom', f.read()) |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
109 |
|
110 |
def test_put_existing_file(self): |
|
111 |
branch = self.make_branch('branch') |
|
112 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.1
by Jelmer Vernooij
Support symlinks in memorytree. |
113 |
with tree.lock_write(): |
114 |
tree.add(['', 'foo'], ids=[b'root-id', b'foo-id'], |
|
115 |
kinds=['directory', 'file']) |
|
116 |
tree.put_file_bytes_non_atomic('foo', b'first-content') |
|
117 |
tree.put_file_bytes_non_atomic('foo', b'barshoom') |
|
118 |
self.assertEqual(b'barshoom', tree.get_file('foo').read()) |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
119 |
|
3567.4.5
by John Arbash Meinel
MemoryTree.add(directory) will now create a directory node in the Transport |
120 |
def test_add_in_subdir(self): |
121 |
branch = self.make_branch('branch') |
|
122 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
123 |
with tree.lock_write(): |
124 |
tree.add([''], [b'root-id'], ['directory']) |
|
125 |
# Unfortunately, the only way to 'mkdir' is to call 'tree.mkdir', but
|
|
126 |
# that *always* adds the directory as well. So if you want to create a
|
|
127 |
# file in a subdirectory, you have to split out the 'mkdir()' calls
|
|
128 |
# from the add and put_file_bytes_non_atomic calls. :(
|
|
129 |
tree.mkdir('adir', b'dir-id') |
|
130 |
tree.add(['adir/afile'], [b'file-id'], ['file']) |
|
131 |
self.assertEqual('adir/afile', tree.id2path(b'file-id')) |
|
132 |
self.assertEqual('adir', tree.id2path(b'dir-id')) |
|
133 |
tree.put_file_bytes_non_atomic('adir/afile', b'barshoom') |
|
3567.4.5
by John Arbash Meinel
MemoryTree.add(directory) will now create a directory node in the Transport |
134 |
|
7058.6.1
by Jelmer Vernooij
Support symlinks in memorytree. |
135 |
def test_add_symlink(self): |
136 |
branch = self.make_branch('branch') |
|
137 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
138 |
with tree.lock_write(): |
139 |
tree._file_transport.symlink('bar', 'foo') |
|
140 |
tree.add(['', 'foo']) |
|
141 |
self.assertEqual('symlink', tree.kind('foo')) |
|
142 |
self.assertEqual('bar', tree.get_symlink_target('foo')) |
|
7058.6.1
by Jelmer Vernooij
Support symlinks in memorytree. |
143 |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
144 |
def test_commit_trivial(self): |
145 |
"""Smoke test for commit on a MemoryTree. |
|
146 |
||
147 |
Becamse of commits design and layering, if this works, all commit
|
|
148 |
logic should work quite reliably.
|
|
149 |
"""
|
|
150 |
branch = self.make_branch('branch') |
|
151 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
152 |
with tree.lock_write(): |
153 |
tree.add(['', 'foo'], ids=[b'root-id', b'foo-id'], |
|
154 |
kinds=['directory', 'file']) |
|
155 |
tree.put_file_bytes_non_atomic('foo', b'barshoom') |
|
156 |
revision_id = tree.commit('message baby') |
|
157 |
# the parents list for the tree should have changed.
|
|
158 |
self.assertEqual([revision_id], tree.get_parent_ids()) |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
159 |
# and we should have a revision that is accessible outside the tree lock
|
160 |
revtree = tree.branch.repository.revision_tree(revision_id) |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
161 |
with revtree.lock_read(), revtree.get_file('foo') as f: |
6973.6.3
by Jelmer Vernooij
More fixes. |
162 |
self.assertEqual(b'barshoom', f.read()) |
1986.1.3
by Robert Collins
Merge bzr.dev. |
163 |
|
164 |
def test_unversion(self): |
|
165 |
"""Some test for unversion of a memory tree.""" |
|
166 |
branch = self.make_branch('branch') |
|
167 |
tree = MemoryTree.create_on_branch(branch) |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
168 |
with tree.lock_write(): |
169 |
tree.add(['', 'foo'], ids=[b'root-id', b'foo-id'], |
|
170 |
kinds=['directory', 'file']) |
|
171 |
tree.unversion(['foo']) |
|
172 |
self.assertFalse(tree.is_versioned('foo')) |
|
7397.4.7
by Jelmer Vernooij
Remove Tree.has_id. |
173 |
self.assertRaises(errors.NoSuchId, tree.id2path, b'foo-id') |
1986.4.1
by Robert Collins
Merge MemoryTree branch. |
174 |
|
175 |
def test_last_revision(self): |
|
176 |
"""There should be a last revision method we can call.""" |
|
177 |
tree = self.make_branch_and_memory_tree('branch') |
|
7058.6.3
by Jelmer Vernooij
Fix tests. |
178 |
with tree.lock_write(): |
179 |
tree.add('') |
|
180 |
rev_id = tree.commit('first post') |
|
1986.4.1
by Robert Collins
Merge MemoryTree branch. |
181 |
self.assertEqual(rev_id, tree.last_revision()) |
3567.5.1
by John Arbash Meinel
Implement rename_one on MemoryTree, and expose that in the Branch Builder |
182 |
|
183 |
def test_rename_file(self): |
|
184 |
tree = self.make_branch_and_memory_tree('branch') |
|
185 |
tree.lock_write() |
|
186 |
self.addCleanup(tree.unlock) |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
187 |
tree.add(['', 'foo'], [b'root-id', b'foo-id'], ['directory', 'file']) |
6973.6.3
by Jelmer Vernooij
More fixes. |
188 |
tree.put_file_bytes_non_atomic('foo', b'content\n') |
6855.4.1
by Jelmer Vernooij
Yet more bees. |
189 |
tree.commit('one', rev_id=b'rev-one') |
3567.5.1
by John Arbash Meinel
Implement rename_one on MemoryTree, and expose that in the Branch Builder |
190 |
tree.rename_one('foo', 'bar') |
6855.4.1
by Jelmer Vernooij
Yet more bees. |
191 |
self.assertEqual('bar', tree.id2path(b'foo-id')) |
7045.1.1
by Jelmer Vernooij
Fix another 300 tests. |
192 |
self.assertEqual(b'content\n', tree._file_transport.get_bytes('bar')) |
3567.5.1
by John Arbash Meinel
Implement rename_one on MemoryTree, and expose that in the Branch Builder |
193 |
self.assertRaises(errors.NoSuchFile, |
194 |
tree._file_transport.get_bytes, 'foo') |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
195 |
tree.commit('two', rev_id=b'rev-two') |
6973.6.3
by Jelmer Vernooij
More fixes. |
196 |
self.assertEqual(b'content\n', tree._file_transport.get_bytes('bar')) |
3567.5.1
by John Arbash Meinel
Implement rename_one on MemoryTree, and expose that in the Branch Builder |
197 |
self.assertRaises(errors.NoSuchFile, |
198 |
tree._file_transport.get_bytes, 'foo') |
|
199 |
||
6855.4.1
by Jelmer Vernooij
Yet more bees. |
200 |
rev_tree2 = tree.branch.repository.revision_tree(b'rev-two') |
201 |
self.assertEqual('bar', rev_tree2.id2path(b'foo-id')) |
|
6973.6.3
by Jelmer Vernooij
More fixes. |
202 |
self.assertEqual(b'content\n', rev_tree2.get_file_text('bar')) |
3567.5.1
by John Arbash Meinel
Implement rename_one on MemoryTree, and expose that in the Branch Builder |
203 |
|
204 |
def test_rename_file_to_subdir(self): |
|
205 |
tree = self.make_branch_and_memory_tree('branch') |
|
206 |
tree.lock_write() |
|
207 |
self.addCleanup(tree.unlock) |
|
208 |
tree.add('') |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
209 |
tree.mkdir('subdir', b'subdir-id') |
210 |
tree.add('foo', b'foo-id', 'file') |
|
6973.6.3
by Jelmer Vernooij
More fixes. |
211 |
tree.put_file_bytes_non_atomic('foo', b'content\n') |
6855.4.1
by Jelmer Vernooij
Yet more bees. |
212 |
tree.commit('one', rev_id=b'rev-one') |
3567.5.1
by John Arbash Meinel
Implement rename_one on MemoryTree, and expose that in the Branch Builder |
213 |
|
214 |
tree.rename_one('foo', 'subdir/bar') |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
215 |
self.assertEqual('subdir/bar', tree.id2path(b'foo-id')) |
7045.1.1
by Jelmer Vernooij
Fix another 300 tests. |
216 |
self.assertEqual(b'content\n', |
3567.5.1
by John Arbash Meinel
Implement rename_one on MemoryTree, and expose that in the Branch Builder |
217 |
tree._file_transport.get_bytes('subdir/bar')) |
6855.4.1
by Jelmer Vernooij
Yet more bees. |
218 |
tree.commit('two', rev_id=b'rev-two') |
219 |
rev_tree2 = tree.branch.repository.revision_tree(b'rev-two') |
|
220 |
self.assertEqual('subdir/bar', rev_tree2.id2path(b'foo-id')) |