/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
29
        basis_tree.lock_read()
30
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
31
            self.assertEqual(
32
                [], list(basis_tree.list_files(include_root=True)))
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
33
        finally:
34
            basis_tree.unlock()
35
36
    def test_same_tree(self):
37
        """Test basis_tree when working tree hasn't been modified."""
38
        tree = self.make_branch_and_tree('.')
39
        self.build_tree(['file', 'dir/', 'dir/subfile'])
40
        tree.add(['file', 'dir', 'dir/subfile'])
41
        revision_id = tree.commit('initial tree')
42
43
        basis_tree = tree.basis_tree()
44
        basis_tree.lock_read()
45
        try:
46
            self.assertEqual(revision_id, basis_tree.get_revision_id())
47
            # list_files() may return in either dirblock or sorted order
48
            # TODO: jam 20070215 Should list_files have an explicit order?
49
            self.assertEqual(['', 'dir', 'dir/subfile', 'file'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
50
                             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()
51
        finally:
52
            basis_tree.unlock()
53
54
    def test_altered_tree(self):
55
        """Test basis really is basis after working has been modified."""
56
        tree = self.make_branch_and_tree('.')
57
        self.build_tree(['file', 'dir/', 'dir/subfile'])
58
        tree.add(['file', 'dir', 'dir/subfile'])
59
        revision_id = tree.commit('initial tree')
60
61
        self.build_tree(['new file', 'new dir/'])
62
        tree.rename_one('file', 'dir/new file')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
63
        tree.unversion(['dir/subfile'])
2255.2.72 by John Arbash Meinel
Add some tests for WorkingTree.basis_tree()
64
        tree.add(['new file', 'new dir'])
65
66
        basis_tree = tree.basis_tree()
67
        basis_tree.lock_read()
68
        try:
69
            self.assertEqual(revision_id, basis_tree.get_revision_id())
70
            # list_files() may return in either dirblock or sorted order
71
            # TODO: jam 20070215 Should list_files have an explicit order?
72
            self.assertEqual(['', 'dir', 'dir/subfile', 'file'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
73
                             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()
74
        finally:
75
            basis_tree.unlock()