~bzr-pqm/bzr/bzr.dev

1852.6.1 by Robert Collins
Start tree implementation tests.
1
# Copyright (C) 2006 by Canonical Ltd
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
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
19
from bzrlib import inventory 
1852.6.1 by Robert Collins
Start tree implementation tests.
20
from bzrlib.tests.tree_implementations import TestCaseWithTree
21
22
23
class TestTreeShapes(TestCaseWithTree):
24
25
    def test_empty_tree_no_parents(self):
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
26
        tree = self.make_branch_and_tree('.')
27
        tree = self.get_tree_no_parents_no_content(tree)
1852.6.1 by Robert Collins
Start tree implementation tests.
28
        self.assertEqual([], tree.get_parent_ids())
29
        self.assertEqual([], tree.conflicts())
30
        self.assertEqual([], list(tree.unknowns()))
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
31
        self.assertEqual([inventory.ROOT_ID], list(iter(tree)))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
32
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
33
            [('', inventory.ROOT_ID)],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
34
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
35
36
    def test_abc_tree_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
37
        tree = self.make_branch_and_tree('.')
38
        tree = self.get_tree_no_parents_abc_content(tree)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
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
43
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
44
            set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
45
            set(iter(tree)))
46
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
47
            [('', inventory.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.
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'))
51
52
    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.
53
        tree = self.make_branch_and_tree('.')
54
        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.
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
59
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
60
            set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
61
            set(iter(tree)))
62
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
63
            [('', inventory.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.
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'))
67
        
68
    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.
69
        tree = self.make_branch_and_tree('.')
70
        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.
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
75
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
76
            set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
77
            set(iter(tree)))
78
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
79
            [('', inventory.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.
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'))
83
        
84
    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.
85
        tree = self.make_branch_and_tree('.')
86
        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.
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
91
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
92
            set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
93
            set(iter(tree)))
94
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
95
            [('', inventory.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.
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'))
99
        
100
    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.
101
        tree = self.make_branch_and_tree('.')
102
        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.
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
107
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
108
            set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
109
            set(iter(tree)))
110
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
111
            [('', inventory.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.
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'))
115
        
116
    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.
117
        tree = self.make_branch_and_tree('.')
118
        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.
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
123
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
124
            set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
125
            set(iter(tree)))
126
        self.assertEqual(
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
127
            [('', inventory.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.
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'))