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.get_tree_no_parents_no_content()
27
self.assertEqual([], tree.get_parent_ids())
28
self.assertEqual([], tree.conflicts())
29
self.assertEqual([], list(tree.unknowns()))
30
self.assertEqual([inventory.ROOT_ID], list(iter(tree)))
32
[('', inventory.ROOT_ID)],
33
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
35
def test_abc_tree_no_parents(self):
36
tree = self.get_tree_no_parents_abc_content()
37
self.assertEqual([], tree.get_parent_ids())
38
self.assertEqual([], tree.conflicts())
39
self.assertEqual([], list(tree.unknowns()))
40
# __iter__ has no strongly defined order
42
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
45
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
46
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
47
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
48
self.assertFalse(tree.is_executable('c-id'))
50
def test_abc_tree_content_2_no_parents(self):
51
tree = self.get_tree_no_parents_abc_content_2()
52
self.assertEqual([], tree.get_parent_ids())
53
self.assertEqual([], tree.conflicts())
54
self.assertEqual([], list(tree.unknowns()))
55
# __iter__ has no strongly defined order
57
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
60
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
61
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
62
self.assertEqualDiff('foobar\n', tree.get_file_text('a-id'))
63
self.assertFalse(tree.is_executable('c-id'))
65
def test_abc_tree_content_3_no_parents(self):
66
tree = self.get_tree_no_parents_abc_content_3()
67
self.assertEqual([], tree.get_parent_ids())
68
self.assertEqual([], tree.conflicts())
69
self.assertEqual([], list(tree.unknowns()))
70
# __iter__ has no strongly defined order
72
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
75
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
76
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
77
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
78
self.assertTrue(tree.is_executable('c-id'))
80
def test_abc_tree_content_4_no_parents(self):
81
tree = self.get_tree_no_parents_abc_content_4()
82
self.assertEqual([], tree.get_parent_ids())
83
self.assertEqual([], tree.conflicts())
84
self.assertEqual([], list(tree.unknowns()))
85
# __iter__ has no strongly defined order
87
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
90
[('', inventory.ROOT_ID), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
91
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
92
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
93
self.assertFalse(tree.is_executable('c-id'))
95
def test_abc_tree_content_5_no_parents(self):
96
tree = self.get_tree_no_parents_abc_content_5()
97
self.assertEqual([], tree.get_parent_ids())
98
self.assertEqual([], tree.conflicts())
99
self.assertEqual([], list(tree.unknowns()))
100
# __iter__ has no strongly defined order
102
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
105
[('', inventory.ROOT_ID), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
106
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
107
self.assertEqualDiff('bar\n', tree.get_file_text('a-id'))
108
self.assertFalse(tree.is_executable('c-id'))
110
def test_abc_tree_content_6_no_parents(self):
111
tree = self.get_tree_no_parents_abc_content_6()
112
self.assertEqual([], tree.get_parent_ids())
113
self.assertEqual([], tree.conflicts())
114
self.assertEqual([], list(tree.unknowns()))
115
# __iter__ has no strongly defined order
117
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
120
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('e', 'c-id')],
121
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
122
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
123
self.assertTrue(tree.is_executable('c-id'))