1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# Copyright (C) 2006 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests for the test trees used by the tree_implementations tests."""
from bzrlib.tests.tree_implementations import TestCaseWithTree
class TestTreeShapes(TestCaseWithTree):
def test_empty_tree_no_parents(self):
tree = self.make_branch_and_tree('.')
tree = self.get_tree_no_parents_no_content(tree)
self.assertEqual([], tree.get_parent_ids())
self.assertEqual([], tree.conflicts())
self.assertEqual([], list(tree.unknowns()))
self.assertEqual(['empty-root-id'], list(iter(tree)))
self.assertEqual(
[('', 'empty-root-id')],
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
def test_abc_tree_no_parents(self):
tree = self.make_branch_and_tree('.')
tree = self.get_tree_no_parents_abc_content(tree)
self.assertEqual([], tree.get_parent_ids())
self.assertEqual([], tree.conflicts())
self.assertEqual([], list(tree.unknowns()))
# __iter__ has no strongly defined order
self.assertEqual(
set(['root-id', 'a-id', 'b-id', 'c-id']),
set(iter(tree)))
self.assertEqual(
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
self.assertFalse(tree.is_executable('c-id'))
def test_abc_tree_content_2_no_parents(self):
tree = self.make_branch_and_tree('.')
tree = self.get_tree_no_parents_abc_content_2(tree)
self.assertEqual([], tree.get_parent_ids())
self.assertEqual([], tree.conflicts())
self.assertEqual([], list(tree.unknowns()))
# __iter__ has no strongly defined order
self.assertEqual(
set(['root-id', 'a-id', 'b-id', 'c-id']),
set(iter(tree)))
self.assertEqual(
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
self.assertEqualDiff('foobar\n', tree.get_file_text('a-id'))
self.assertFalse(tree.is_executable('c-id'))
def test_abc_tree_content_3_no_parents(self):
tree = self.make_branch_and_tree('.')
tree = self.get_tree_no_parents_abc_content_3(tree)
self.assertEqual([], tree.get_parent_ids())
self.assertEqual([], tree.conflicts())
self.assertEqual([], list(tree.unknowns()))
# __iter__ has no strongly defined order
self.assertEqual(
set(['root-id', 'a-id', 'b-id', 'c-id']),
set(iter(tree)))
self.assertEqual(
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
self.assertTrue(tree.is_executable('c-id'))
def test_abc_tree_content_4_no_parents(self):
tree = self.make_branch_and_tree('.')
tree = self.get_tree_no_parents_abc_content_4(tree)
self.assertEqual([], tree.get_parent_ids())
self.assertEqual([], tree.conflicts())
self.assertEqual([], list(tree.unknowns()))
# __iter__ has no strongly defined order
self.assertEqual(
set(['root-id', 'a-id', 'b-id', 'c-id']),
set(iter(tree)))
self.assertEqual(
[('', 'root-id'), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
self.assertFalse(tree.is_executable('c-id'))
def test_abc_tree_content_5_no_parents(self):
tree = self.make_branch_and_tree('.')
tree = self.get_tree_no_parents_abc_content_5(tree)
self.assertEqual([], tree.get_parent_ids())
self.assertEqual([], tree.conflicts())
self.assertEqual([], list(tree.unknowns()))
# __iter__ has no strongly defined order
self.assertEqual(
set(['root-id', 'a-id', 'b-id', 'c-id']),
set(iter(tree)))
self.assertEqual(
[('', 'root-id'), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
self.assertEqualDiff('bar\n', tree.get_file_text('a-id'))
self.assertFalse(tree.is_executable('c-id'))
def test_abc_tree_content_6_no_parents(self):
tree = self.make_branch_and_tree('.')
tree = self.get_tree_no_parents_abc_content_6(tree)
self.assertEqual([], tree.get_parent_ids())
self.assertEqual([], tree.conflicts())
self.assertEqual([], list(tree.unknowns()))
# __iter__ has no strongly defined order
self.assertEqual(
set(['root-id', 'a-id', 'b-id', 'c-id']),
set(iter(tree)))
self.assertEqual(
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('e', 'c-id')],
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
self.assertTrue(tree.is_executable('c-id'))
def test_tree_with_subdirs_and_all_content_types(self):
# currently this test tree requires unicode. It might be good
# to have it simply stop having the single unicode file in it
# when dealing with a non-unicode filesystem.
tree = self.get_tree_with_subdirs_and_all_content_types()
self.assertEqual([], tree.get_parent_ids())
self.assertEqual([], tree.conflicts())
self.assertEqual([], list(tree.unknowns()))
# __iter__ has no strongly defined order
self.assertEqual(
set([inventory.ROOT_ID,
'2file',
'1top-dir',
'1file-in-1topdir',
'0dir-in-1topdir',
u'0utf\u1234file',
'symlink',
]),
set(iter(tree)))
# note that the order of the paths and fileids is deliberately
# mismatched to ensure that the result order is path based.
self.assertEqual(
[('', inventory.ROOT_ID, 'directory'),
('0file', '2file', 'file'),
('1top-dir', '1top-dir', 'directory'),
(u'2utf\u1234file', u'0utf\u1234file', 'file'),
('symlink', 'symlink', 'symlink'),
('1top-dir/0file-in-1topdir', '1file-in-1topdir', 'file'),
('1top-dir/1dir-in-1topdir', '0dir-in-1topdir', 'directory')],
[(path, node.file_id, node.kind) for path, node in tree.iter_entries_by_dir()])
|