/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
1
# Copyright (C) 2007 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
16
17
"""Test that WorkingTree.basis_tree() yields a valid tree."""
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
20
21
22
class TestBasisTree(TestCaseWithWorkingTree):
23
24
    def test_emtpy_tree(self):
25
        """A working tree with no parents."""
26
        tree = self.make_branch_and_tree('tree')
27
        basis_tree = tree.basis_tree()
28
7143.19.1 by Jelmer Vernooij
Drop superfluous kind and file_id return values from Tree.list_files.
29
        with basis_tree.lock_read():
7143.15.2 by Jelmer Vernooij
Run autopep8.
30
            self.assertEqual(
31
                [], list(basis_tree.list_files(include_root=True)))
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
32
33
    def test_same_tree(self):
34
        """Test basis_tree when working tree hasn't been modified."""
35
        tree = self.make_branch_and_tree('.')
36
        self.build_tree(['file', 'dir/', 'dir/subfile'])
37
        tree.add(['file', 'dir', 'dir/subfile'])
38
        revision_id = tree.commit('initial tree')
39
40
        basis_tree = tree.basis_tree()
7143.19.1 by Jelmer Vernooij
Drop superfluous kind and file_id return values from Tree.list_files.
41
        with basis_tree.lock_read():
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
42
            self.assertEqual(revision_id, basis_tree.get_revision_id())
43
            # list_files() may return in either dirblock or sorted order
44
            # TODO: jam 20070215 Should list_files have an explicit order?
7143.19.7 by Jelmer Vernooij
merge trunk
45
            self.assertEqual(
46
                ['', 'dir', 'dir/subfile', 'file'],
47
                sorted(info[0] for info in basis_tree.list_files(True)))
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
48
49
    def test_altered_tree(self):
50
        """Test basis really is basis after working has been modified."""
51
        tree = self.make_branch_and_tree('.')
52
        self.build_tree(['file', 'dir/', 'dir/subfile'])
53
        tree.add(['file', 'dir', 'dir/subfile'])
54
        revision_id = tree.commit('initial tree')
55
56
        self.build_tree(['new file', 'new dir/'])
57
        tree.rename_one('file', 'dir/new file')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
58
        tree.unversion(['dir/subfile'])
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
59
        tree.add(['new file', 'new dir'])
60
61
        basis_tree = tree.basis_tree()
7143.19.1 by Jelmer Vernooij
Drop superfluous kind and file_id return values from Tree.list_files.
62
        with basis_tree.lock_read():
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
63
            self.assertEqual(revision_id, basis_tree.get_revision_id())
64
            # list_files() may return in either dirblock or sorted order
65
            # TODO: jam 20070215 Should list_files have an explicit order?
7143.19.7 by Jelmer Vernooij
merge trunk
66
            self.assertEqual(
67
                ['', 'dir', 'dir/subfile', 'file'],
68
                sorted(info[0] for info in basis_tree.list_files(True)))