1
# Copyright (C) 2006 by Canonical Ltd
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.
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.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for the test trees used by the tree_implementations tests."""
19
from bzrlib import inventory
20
from bzrlib.tests.tree_implementations import TestCaseWithTree
23
class TestTreeShapes(TestCaseWithTree):
25
def test_empty_tree_no_parents(self):
26
tree = self.make_branch_and_tree('.')
27
tree = self.get_tree_no_parents_no_content(tree)
28
self.assertEqual([], tree.get_parent_ids())
29
self.assertEqual([], tree.conflicts())
30
self.assertEqual([], list(tree.unknowns()))
31
self.assertEqual([inventory.ROOT_ID], list(iter(tree)))
33
[('', inventory.ROOT_ID)],
34
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
36
def test_abc_tree_no_parents(self):
37
tree = self.make_branch_and_tree('.')
38
tree = self.get_tree_no_parents_abc_content(tree)
39
self.assertEqual([], tree.get_parent_ids())
40
self.assertEqual([], tree.conflicts())
41
self.assertEqual([], list(tree.unknowns()))
42
# __iter__ has no strongly defined order
44
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
47
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
48
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
49
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
50
self.assertFalse(tree.is_executable('c-id'))
52
def test_abc_tree_content_2_no_parents(self):
53
tree = self.make_branch_and_tree('.')
54
tree = self.get_tree_no_parents_abc_content_2(tree)
55
self.assertEqual([], tree.get_parent_ids())
56
self.assertEqual([], tree.conflicts())
57
self.assertEqual([], list(tree.unknowns()))
58
# __iter__ has no strongly defined order
60
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
63
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
64
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
65
self.assertEqualDiff('foobar\n', tree.get_file_text('a-id'))
66
self.assertFalse(tree.is_executable('c-id'))
68
def test_abc_tree_content_3_no_parents(self):
69
tree = self.make_branch_and_tree('.')
70
tree = self.get_tree_no_parents_abc_content_3(tree)
71
self.assertEqual([], tree.get_parent_ids())
72
self.assertEqual([], tree.conflicts())
73
self.assertEqual([], list(tree.unknowns()))
74
# __iter__ has no strongly defined order
76
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
79
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
80
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
81
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
82
self.assertTrue(tree.is_executable('c-id'))
84
def test_abc_tree_content_4_no_parents(self):
85
tree = self.make_branch_and_tree('.')
86
tree = self.get_tree_no_parents_abc_content_4(tree)
87
self.assertEqual([], tree.get_parent_ids())
88
self.assertEqual([], tree.conflicts())
89
self.assertEqual([], list(tree.unknowns()))
90
# __iter__ has no strongly defined order
92
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
95
[('', inventory.ROOT_ID), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
96
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
97
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
98
self.assertFalse(tree.is_executable('c-id'))
100
def test_abc_tree_content_5_no_parents(self):
101
tree = self.make_branch_and_tree('.')
102
tree = self.get_tree_no_parents_abc_content_5(tree)
103
self.assertEqual([], tree.get_parent_ids())
104
self.assertEqual([], tree.conflicts())
105
self.assertEqual([], list(tree.unknowns()))
106
# __iter__ has no strongly defined order
108
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
111
[('', inventory.ROOT_ID), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
112
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
113
self.assertEqualDiff('bar\n', tree.get_file_text('a-id'))
114
self.assertFalse(tree.is_executable('c-id'))
116
def test_abc_tree_content_6_no_parents(self):
117
tree = self.make_branch_and_tree('.')
118
tree = self.get_tree_no_parents_abc_content_6(tree)
119
self.assertEqual([], tree.get_parent_ids())
120
self.assertEqual([], tree.conflicts())
121
self.assertEqual([], list(tree.unknowns()))
122
# __iter__ has no strongly defined order
124
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
127
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('e', 'c-id')],
128
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
129
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
130
self.assertTrue(tree.is_executable('c-id'))