~bzr-pqm/bzr/bzr.dev

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)
1852.6.1 by Robert Collins
Start tree implementation tests.
27
        self.assertEqual([], tree.get_parent_ids())
28
        self.assertEqual([], tree.conflicts())
29
        self.assertEqual([], list(tree.unknowns()))
1731.1.33 by Aaron Bentley
Revert no-special-root changes
30
        self.assertEqual(['empty-root-id'], list(iter(tree)))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
31
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
32
            [('', 'empty-root-id')],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
33
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
34
35
    def test_abc_tree_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
36
        tree = self.make_branch_and_tree('.')
37
        tree = self.get_tree_no_parents_abc_content(tree)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
38
        self.assertEqual([], tree.get_parent_ids())
39
        self.assertEqual([], tree.conflicts())
40
        self.assertEqual([], list(tree.unknowns()))
41
        # __iter__ has no strongly defined order
42
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
43
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
44
            set(iter(tree)))
45
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
46
            [('', '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.
47
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
48
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
49
        self.assertFalse(tree.is_executable('c-id'))
50
51
    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.
52
        tree = self.make_branch_and_tree('.')
53
        tree = self.get_tree_no_parents_abc_content_2(tree)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
54
        self.assertEqual([], tree.get_parent_ids())
55
        self.assertEqual([], tree.conflicts())
56
        self.assertEqual([], list(tree.unknowns()))
57
        # __iter__ has no strongly defined order
58
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
59
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
60
            set(iter(tree)))
61
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
62
            [('', '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.
63
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
64
        self.assertEqualDiff('foobar\n', tree.get_file_text('a-id'))
65
        self.assertFalse(tree.is_executable('c-id'))
66
        
67
    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.
68
        tree = self.make_branch_and_tree('.')
69
        tree = self.get_tree_no_parents_abc_content_3(tree)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
70
        self.assertEqual([], tree.get_parent_ids())
71
        self.assertEqual([], tree.conflicts())
72
        self.assertEqual([], list(tree.unknowns()))
73
        # __iter__ has no strongly defined order
74
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
75
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
76
            set(iter(tree)))
77
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
78
            [('', '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.
79
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
80
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
81
        self.assertTrue(tree.is_executable('c-id'))
82
        
83
    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.
84
        tree = self.make_branch_and_tree('.')
85
        tree = self.get_tree_no_parents_abc_content_4(tree)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
86
        self.assertEqual([], tree.get_parent_ids())
87
        self.assertEqual([], tree.conflicts())
88
        self.assertEqual([], list(tree.unknowns()))
89
        # __iter__ has no strongly defined order
90
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
91
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
92
            set(iter(tree)))
93
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
94
            [('', '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.
95
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
96
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
97
        self.assertFalse(tree.is_executable('c-id'))
98
        
99
    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.
100
        tree = self.make_branch_and_tree('.')
101
        tree = self.get_tree_no_parents_abc_content_5(tree)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
102
        self.assertEqual([], tree.get_parent_ids())
103
        self.assertEqual([], tree.conflicts())
104
        self.assertEqual([], list(tree.unknowns()))
105
        # __iter__ has no strongly defined order
106
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
107
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
108
            set(iter(tree)))
109
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
110
            [('', '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.
111
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
112
        self.assertEqualDiff('bar\n', tree.get_file_text('a-id'))
113
        self.assertFalse(tree.is_executable('c-id'))
114
        
115
    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.
116
        tree = self.make_branch_and_tree('.')
117
        tree = self.get_tree_no_parents_abc_content_6(tree)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
118
        self.assertEqual([], tree.get_parent_ids())
119
        self.assertEqual([], tree.conflicts())
120
        self.assertEqual([], list(tree.unknowns()))
121
        # __iter__ has no strongly defined order
122
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
123
            set(['root-id', 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
124
            set(iter(tree)))
125
        self.assertEqual(
1731.1.33 by Aaron Bentley
Revert no-special-root changes
126
            [('', '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.
127
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
128
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
129
        self.assertTrue(tree.is_executable('c-id'))