~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_subsume.py

(broken) merge aaron's workingtree format changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 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
from bzrlib import bzrdir, errors, repository, workingtree, tests
 
18
 
 
19
 
 
20
class TestWorkingTree(tests.TestCaseWithTransport):
 
21
 
 
22
    def make_branch_and_tree(self, relpath, format=None):
 
23
        if format is None:
 
24
            format = 'experimental-knit3'
 
25
        return tests.TestCaseWithTransport.make_branch_and_tree(self, relpath, 
 
26
                                                                format)
 
27
 
 
28
    def make_trees(self, format=None, same_root=False):
 
29
        self.build_tree(['tree/', 
 
30
                         'tree/file',
 
31
                         'tree/subtree/',
 
32
                         'tree/subtree/file2'])
 
33
        base_tree = self.make_branch_and_tree('tree', format=format)
 
34
        base_tree.add('file', 'file-id')
 
35
        base_tree.commit('first commit', rev_id='tree-1')
 
36
        sub_tree = self.make_branch_and_tree('tree/subtree', 
 
37
                                             format='experimental-knit3')
 
38
        if same_root is True:
 
39
            sub_tree.set_root_id(base_tree.get_root_id())
 
40
        sub_tree.add('file2', 'file2-id')
 
41
        sub_tree.commit('first commit', rev_id='subtree-1')
 
42
        return base_tree, sub_tree
 
43
 
 
44
    def test_old_knit1_failure(self):
 
45
        """Ensure that BadSubsumeSource is raised.
 
46
 
 
47
        SubsumeTargetNeedsUpgrade must not be raised, because upgrading the
 
48
        target won't help.
 
49
        """
 
50
        base_tree, sub_tree = self.make_trees(format='knit',
 
51
                                              same_root=True)
 
52
        self.assertRaises(errors.BadSubsumeSource, base_tree.subsume, 
 
53
                          sub_tree)
 
54
 
 
55
    def test_knit1_failure(self):
 
56
        base_tree, sub_tree = self.make_trees(format='knit')
 
57
        self.assertRaises(errors.SubsumeTargetNeedsUpgrade, base_tree.subsume, 
 
58
                          sub_tree)
 
59
 
 
60
    def test_subsume_tree(self):
 
61
        base_tree, sub_tree = self.make_trees()
 
62
        assert base_tree.get_root_id() != sub_tree.get_root_id()
 
63
        sub_root_id = sub_tree.get_root_id()
 
64
        base_tree.subsume(sub_tree)
 
65
        self.assertEqual(['tree-1', 'subtree-1'], base_tree.get_parent_ids())
 
66
        self.assertEqual(sub_root_id, base_tree.path2id('subtree'))
 
67
        self.assertEqual('file2-id', base_tree.path2id('subtree/file2'))
 
68
        sub_bzrdir = bzrdir.BzrDir.open('tree/subtree')
 
69
        self.assertRaises(errors.NoWorkingTree, sub_bzrdir.open_workingtree)
 
70
        sub_bzrdir.open_branch()
 
71
        file2 = open('tree/subtree/file2', 'rb')
 
72
        try:
 
73
            file2_contents = file2.read()
 
74
        finally:
 
75
            file2.close()
 
76
        base_tree = workingtree.WorkingTree.open('tree')
 
77
        base_tree.commit('combined', rev_id='combined-1')
 
78
        self.assertEqual('file2-id', base_tree.path2id('subtree/file2'))
 
79
        self.assertEqual('subtree/file2', base_tree.id2path('file2-id'))
 
80
        self.assertEqualDiff(file2_contents, 
 
81
                             base_tree.get_file_text('file2-id'))
 
82
        basis_tree = base_tree.basis_tree()
 
83
        self.assertEqualDiff(file2_contents, 
 
84
                             base_tree.get_file_text('file2-id'))
 
85
        self.assertEqualDiff(file2_contents, 
 
86
                             basis_tree.get_file_text('file2-id'))
 
87
        self.assertEqual('subtree-1', 
 
88
                         basis_tree.inventory['file2-id'].revision)
 
89
        self.assertEqual('combined-1', 
 
90
                         basis_tree.inventory[sub_root_id].revision)
 
91
 
 
92
    def test_subsume_failure(self):
 
93
        base_tree, sub_tree = self.make_trees()
 
94
        if base_tree.get_root_id() == sub_tree.get_root_id():
 
95
            raise tests.TestSkipped('This test requires unique roots')
 
96
        sub_root_id = sub_tree.get_root_id()
 
97
        self.assertRaises(errors.BadSubsumeSource, base_tree.subsume, 
 
98
                          base_tree)
 
99
        self.assertRaises(errors.BadSubsumeSource, sub_tree.subsume, 
 
100
                          base_tree)
 
101
        self.build_tree(['subtree2/'])
 
102
        sub_tree2 = self.make_branch_and_tree('subtree2')
 
103
        self.assertRaises(errors.BadSubsumeSource, sub_tree.subsume, 
 
104
                          sub_tree2)
 
105
        self.build_tree(['tree/subtree/subtree3/'])
 
106
        sub_tree3 = self.make_branch_and_tree('tree/subtree/subtree3')
 
107
        self.assertRaises(errors.BadSubsumeSource, base_tree.subsume,
 
108
                          sub_tree3)