2255.2.72
by John Arbash Meinel
Add some tests for WorkingTree.basis_tree() |
1 |
# Copyright (C) 2007 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
2255.2.72
by John Arbash Meinel
Add some tests for WorkingTree.basis_tree() |
16 |
|
17 |
"""Test that WorkingTree.basis_tree() yields a valid tree."""
|
|
18 |
||
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
19 |
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree |
2255.2.72
by John Arbash Meinel
Add some tests for WorkingTree.basis_tree() |
20 |
|
21 |
||
22 |
class TestBasisTree(TestCaseWithWorkingTree): |
|
23 |
||
24 |
def test_emtpy_tree(self): |
|
25 |
"""A working tree with no parents."""
|
|
26 |
tree = self.make_branch_and_tree('tree') |
|
27 |
basis_tree = tree.basis_tree() |
|
28 |
||
29 |
basis_tree.lock_read() |
|
30 |
try: |
|
31 |
self.assertEqual([], list(basis_tree.list_files(include_root=True))) |
|
32 |
finally: |
|
33 |
basis_tree.unlock() |
|
34 |
||
35 |
def test_same_tree(self): |
|
36 |
"""Test basis_tree when working tree hasn't been modified."""
|
|
37 |
tree = self.make_branch_and_tree('.') |
|
38 |
self.build_tree(['file', 'dir/', 'dir/subfile']) |
|
39 |
tree.add(['file', 'dir', 'dir/subfile']) |
|
40 |
revision_id = tree.commit('initial tree') |
|
41 |
||
42 |
basis_tree = tree.basis_tree() |
|
43 |
basis_tree.lock_read() |
|
44 |
try: |
|
45 |
self.assertEqual(revision_id, basis_tree.get_revision_id()) |
|
46 |
# list_files() may return in either dirblock or sorted order
|
|
47 |
# TODO: jam 20070215 Should list_files have an explicit order?
|
|
48 |
self.assertEqual(['', 'dir', 'dir/subfile', 'file'], |
|
49 |
sorted(info[0] for info in basis_tree.list_files(True))) |
|
50 |
finally: |
|
51 |
basis_tree.unlock() |
|
52 |
||
53 |
def test_altered_tree(self): |
|
54 |
"""Test basis really is basis after working has been modified."""
|
|
55 |
tree = self.make_branch_and_tree('.') |
|
56 |
self.build_tree(['file', 'dir/', 'dir/subfile']) |
|
57 |
tree.add(['file', 'dir', 'dir/subfile']) |
|
58 |
revision_id = tree.commit('initial tree') |
|
59 |
||
60 |
self.build_tree(['new file', 'new dir/']) |
|
61 |
tree.rename_one('file', 'dir/new file') |
|
62 |
tree.unversion([tree.path2id('dir/subfile')]) |
|
63 |
tree.add(['new file', 'new dir']) |
|
64 |
||
65 |
basis_tree = tree.basis_tree() |
|
66 |
basis_tree.lock_read() |
|
67 |
try: |
|
68 |
self.assertEqual(revision_id, basis_tree.get_revision_id()) |
|
69 |
# list_files() may return in either dirblock or sorted order
|
|
70 |
# TODO: jam 20070215 Should list_files have an explicit order?
|
|
71 |
self.assertEqual(['', 'dir', 'dir/subfile', 'file'], |
|
72 |
sorted(info[0] for info in basis_tree.list_files(True))) |
|
73 |
finally: |
|
74 |
basis_tree.unlock() |