/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1852.6.1 by Robert Collins
Start tree implementation tests.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for the test trees used by the tree_implementations tests."""
18
19
from bzrlib.tests.tree_implementations import TestCaseWithTree
20
21
22
class TestTreeShapes(TestCaseWithTree):
23
24
    def test_empty_tree_no_parents(self):
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
25
        tree = self.make_branch_and_tree('.')
26
        tree = self.get_tree_no_parents_no_content(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
27
        tree.lock_read()
28
        self.addCleanup(tree.unlock)
1852.6.1 by Robert Collins
Start tree implementation tests.
29
        self.assertEqual([], tree.get_parent_ids())
30
        self.assertEqual([], tree.conflicts())
31
        self.assertEqual([], list(tree.unknowns()))
1731.1.33 by Aaron Bentley
Revert no-special-root changes
32
        self.assertEqual(['empty-root-id'], list(iter(tree)))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
33
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
34
            [('', 'empty-root-id')],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
35
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
36
37
    def test_abc_tree_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
38
        tree = self.make_branch_and_tree('.')
39
        tree = self.get_tree_no_parents_abc_content(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
40
        tree.lock_read()
41
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
42
        self.assertEqual([], tree.get_parent_ids())
43
        self.assertEqual([], tree.conflicts())
44
        self.assertEqual([], list(tree.unknowns()))
45
        # __iter__ has no strongly defined order
46
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
47
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
48
            set(iter(tree)))
49
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
50
            [('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
51
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
52
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
53
        self.assertFalse(tree.is_executable('c-id'))
54
55
    def test_abc_tree_content_2_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
56
        tree = self.make_branch_and_tree('.')
57
        tree = self.get_tree_no_parents_abc_content_2(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
58
        tree.lock_read()
59
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
60
        self.assertEqual([], tree.get_parent_ids())
61
        self.assertEqual([], tree.conflicts())
62
        self.assertEqual([], list(tree.unknowns()))
63
        # __iter__ has no strongly defined order
64
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
65
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
66
            set(iter(tree)))
67
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
68
            [('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
69
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
70
        self.assertEqualDiff('foobar\n', tree.get_file_text('a-id'))
71
        self.assertFalse(tree.is_executable('c-id'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
72
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
73
    def test_abc_tree_content_3_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
74
        tree = self.make_branch_and_tree('.')
75
        tree = self.get_tree_no_parents_abc_content_3(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
76
        tree.lock_read()
77
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
78
        self.assertEqual([], tree.get_parent_ids())
79
        self.assertEqual([], tree.conflicts())
80
        self.assertEqual([], list(tree.unknowns()))
81
        # __iter__ has no strongly defined order
82
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
83
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
84
            set(iter(tree)))
85
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
86
            [('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
87
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
88
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
89
        self.assertTrue(tree.is_executable('c-id'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
90
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
91
    def test_abc_tree_content_4_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
92
        tree = self.make_branch_and_tree('.')
93
        tree = self.get_tree_no_parents_abc_content_4(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
94
        tree.lock_read()
95
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
96
        self.assertEqual([], tree.get_parent_ids())
97
        self.assertEqual([], tree.conflicts())
98
        self.assertEqual([], list(tree.unknowns()))
99
        # __iter__ has no strongly defined order
100
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
101
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
102
            set(iter(tree)))
103
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
104
            [('', 'root-id'), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
105
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
106
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
107
        self.assertFalse(tree.is_executable('c-id'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
108
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
109
    def test_abc_tree_content_5_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
110
        tree = self.make_branch_and_tree('.')
111
        tree = self.get_tree_no_parents_abc_content_5(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
112
        tree.lock_read()
113
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
114
        self.assertEqual([], tree.get_parent_ids())
115
        self.assertEqual([], tree.conflicts())
116
        self.assertEqual([], list(tree.unknowns()))
117
        # __iter__ has no strongly defined order
118
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
119
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
120
            set(iter(tree)))
121
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
122
            [('', 'root-id'), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
123
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
124
        self.assertEqualDiff('bar\n', tree.get_file_text('a-id'))
125
        self.assertFalse(tree.is_executable('c-id'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
126
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
127
    def test_abc_tree_content_6_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
128
        tree = self.make_branch_and_tree('.')
129
        tree = self.get_tree_no_parents_abc_content_6(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
130
        tree.lock_read()
131
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
132
        self.assertEqual([], tree.get_parent_ids())
133
        self.assertEqual([], tree.conflicts())
134
        self.assertEqual([], list(tree.unknowns()))
135
        # __iter__ has no strongly defined order
136
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
137
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
138
            set(iter(tree)))
139
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
140
            [('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('e', 'c-id')],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
141
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
142
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
143
        self.assertTrue(tree.is_executable('c-id'))
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
144
145
    def test_tree_with_subdirs_and_all_content_types(self):
146
        # currently this test tree requires unicode. It might be good
147
        # to have it simply stop having the single unicode file in it
148
        # when dealing with a non-unicode filesystem.
149
        tree = self.get_tree_with_subdirs_and_all_content_types()
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
150
        tree.lock_read()
151
        self.addCleanup(tree.unlock)
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
152
        self.assertEqual([], tree.get_parent_ids())
153
        self.assertEqual([], tree.conflicts())
154
        self.assertEqual([], list(tree.unknowns()))
155
        # __iter__ has no strongly defined order
2255.2.17 by Robert Collins
tweaks - finishes off all the test_test_trees tests for dirstate.
156
        tree_root = tree.path2id('')
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
157
        self.assertEqual(
2255.2.17 by Robert Collins
tweaks - finishes off all the test_test_trees tests for dirstate.
158
            set([tree_root,
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
159
                '2file',
160
                '1top-dir',
161
                '1file-in-1topdir',
162
                '0dir-in-1topdir',
163
                 u'0utf\u1234file',
164
                'symlink',
165
                 ]),
166
            set(iter(tree)))
167
        # note that the order of the paths and fileids is deliberately 
168
        # mismatched to ensure that the result order is path based.
169
        self.assertEqual(
2255.2.17 by Robert Collins
tweaks - finishes off all the test_test_trees tests for dirstate.
170
            [('', tree_root, 'directory'),
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
171
             ('0file', '2file', 'file'),
172
             ('1top-dir', '1top-dir', 'directory'),
173
             (u'2utf\u1234file', u'0utf\u1234file', 'file'),
174
             ('symlink', 'symlink', 'symlink'),
175
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir', 'file'),
176
             ('1top-dir/1dir-in-1topdir', '0dir-in-1topdir', 'directory')],
177
            [(path, node.file_id, node.kind) for path, node in tree.iter_entries_by_dir()])