/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

 added test for function fileid_involved

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import unittest
 
3
 
 
4
from bzrlib.tests import TestCaseInTempDir, TestCase
 
5
from bzrlib.branch import Branch
 
6
from bzrlib.errors import NotBranchError
 
7
from bzrlib.inventory import InventoryFile, Inventory
 
8
from bzrlib.workingtree import WorkingTree
 
9
 
 
10
class TestSmartAdd(TestCaseInTempDir):
 
11
 
 
12
    def test_add_dot_from_root(self):
 
13
        """Test adding . from the root of the tree.""" 
 
14
        from bzrlib.add import smart_add
 
15
        paths = ("original/", "original/file1", "original/file2")
 
16
        self.build_tree(paths)
 
17
        branch = Branch.initialize(u".")
 
18
        smart_add((u".",))
 
19
        for path in paths:
 
20
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
21
 
 
22
    def test_add_dot_from_subdir(self):
 
23
        """Test adding . from a subdir of the tree.""" 
 
24
        from bzrlib.add import smart_add
 
25
        paths = ("original/", "original/file1", "original/file2")
 
26
        self.build_tree(paths)
 
27
        branch = Branch.initialize(u".")
 
28
        os.chdir("original")
 
29
        smart_add((u".",))
 
30
        for path in paths:
 
31
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
32
 
 
33
    def test_add_tree_from_above_tree(self):
 
34
        """Test adding a tree from above the tree.""" 
 
35
        from bzrlib.add import smart_add
 
36
        paths = ("original/", "original/file1", "original/file2")
 
37
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
 
38
                        "branch/original/file2")
 
39
        self.build_tree(branch_paths)
 
40
        branch = Branch.initialize("branch")
 
41
        smart_add(("branch",))
 
42
        for path in paths:
 
43
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
44
 
 
45
    def test_add_above_tree_preserves_tree(self):
 
46
        """Test nested trees are not affect by an add above them."""
 
47
        from bzrlib.add import smart_add
 
48
        paths = ("original/", "original/file1", "original/file2")
 
49
        child_paths = ("path",)
 
50
        full_child_paths = ("original/child", "original/child/path")
 
51
        build_paths = ("original/", "original/file1", "original/file2", 
 
52
                       "original/child/", "original/child/path")
 
53
        
 
54
        self.build_tree(build_paths)
 
55
        branch = Branch.initialize(u".")
 
56
        child_branch = Branch.initialize("original/child")
 
57
        smart_add((u".",))
 
58
        for path in paths:
 
59
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
 
60
                                (path, None))
 
61
        for path in full_child_paths:
 
62
            self.assertEqual((path, branch.working_tree().path2id(path)),
 
63
                             (path, None))
 
64
        for path in child_paths:
 
65
            self.assertEqual(child_branch.working_tree().path2id(path), None)
 
66
 
 
67
    def test_add_paths(self):
 
68
        """Test smart-adding a list of paths."""
 
69
        from bzrlib.add import smart_add
 
70
        paths = ("file1", "file2")
 
71
        self.build_tree(paths)
 
72
        branch = Branch.initialize(u".")
 
73
        smart_add(paths)
 
74
        for path in paths:
 
75
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
76
 
 
77
    def test_add_dry_run(self):
 
78
        """Test a dry run add, make sure nothing is added."""
 
79
        from bzrlib.commands import run_bzr
 
80
        eq = self.assertEqual
 
81
        b = Branch.initialize(u'.')
 
82
        t = b.working_tree()
 
83
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
 
84
        eq(list(t.unknowns()), ['inertiatic'])
 
85
        self.capture('add --dry-run .')
 
86
        eq(list(t.unknowns()), ['inertiatic'])
 
87
 
 
88
class TestSmartAddBranch(TestCaseInTempDir):
 
89
    """Test smart adds with a specified branch."""
 
90
 
 
91
    def test_add_dot_from_root(self):
 
92
        """Test adding . from the root of the tree.""" 
 
93
        from bzrlib.add import smart_add_tree
 
94
        paths = ("original/", "original/file1", "original/file2")
 
95
        self.build_tree(paths)
 
96
        Branch.initialize(u".")
 
97
        tree = WorkingTree()
 
98
        smart_add_tree(tree, (u".",))
 
99
        for path in paths:
 
100
            self.assertNotEqual(tree.path2id(path), None)
 
101
 
 
102
    def test_add_dot_from_subdir(self):
 
103
        """Test adding . from a subdir of the tree.""" 
 
104
        from bzrlib.add import smart_add_tree
 
105
        paths = ("original/", "original/file1", "original/file2")
 
106
        self.build_tree(paths)
 
107
        Branch.initialize(u".")
 
108
        tree = WorkingTree()
 
109
        os.chdir("original")
 
110
        smart_add_tree(tree, (u".",))
 
111
        for path in paths:
 
112
            self.assertNotEqual(tree.path2id(path), None)
 
113
 
 
114
    def test_add_tree_from_above_tree(self):
 
115
        """Test adding a tree from above the tree.""" 
 
116
        from bzrlib.add import smart_add_tree
 
117
        paths = ("original/", "original/file1", "original/file2")
 
118
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
 
119
                        "branch/original/file2")
 
120
        self.build_tree(branch_paths)
 
121
        Branch.initialize("branch")
 
122
        tree = WorkingTree("branch")
 
123
        smart_add_tree(tree, ("branch",))
 
124
        for path in paths:
 
125
            self.assertNotEqual(tree.path2id(path), None)
 
126
 
 
127
    def test_add_above_tree_preserves_tree(self):
 
128
        """Test nested trees are not affect by an add above them."""
 
129
        from bzrlib.add import smart_add_tree
 
130
        paths = ("original/", "original/file1", "original/file2")
 
131
        child_paths = ("path")
 
132
        full_child_paths = ("original/child", "original/child/path")
 
133
        build_paths = ("original/", "original/file1", "original/file2", 
 
134
                       "original/child/", "original/child/path")
 
135
        self.build_tree(build_paths)
 
136
        Branch.initialize(u".")
 
137
        tree = WorkingTree()
 
138
        child_branch = Branch.initialize("original/child")
 
139
        smart_add_tree(tree, (u".",))
 
140
        for path in paths:
 
141
            self.assertNotEqual((path, tree.path2id(path)),
 
142
                                (path, None))
 
143
        for path in full_child_paths:
 
144
            self.assertEqual((path, tree.path2id(path)),
 
145
                             (path, None))
 
146
        for path in child_paths:
 
147
            self.assertEqual(child_branch.working_tree().path2id(path), None)
 
148
 
 
149
    def test_add_paths(self):
 
150
        """Test smart-adding a list of paths."""
 
151
        from bzrlib.add import smart_add_tree
 
152
        paths = ("file1", "file2")
 
153
        self.build_tree(paths)
 
154
        Branch.initialize(u".")
 
155
        tree = WorkingTree()
 
156
        smart_add_tree(tree, paths)
 
157
        for path in paths:
 
158
            self.assertNotEqual(tree.path2id(path), None)
 
159
 
 
160
class TestAddActions(TestCaseInTempDir):
 
161
 
 
162
    def test_null(self):
 
163
        from bzrlib.add import add_action_null
 
164
        self.run_action(add_action_null, "", False)
 
165
 
 
166
    def test_add(self):
 
167
        self.entry = InventoryFile("id", "name", None)
 
168
        from bzrlib.add import add_action_add
 
169
        self.run_action(add_action_add, "", True)
 
170
 
 
171
    def test_add_and_print(self):
 
172
        from bzrlib.add import add_action_add_and_print
 
173
        self.run_action(add_action_add_and_print, "added path\n", True)
 
174
 
 
175
    def test_print(self):
 
176
        from bzrlib.add import add_action_print
 
177
        self.run_action(add_action_print, "added path\n", False)
 
178
 
 
179
    def run_action(self, action, output, should_add):
 
180
        from StringIO import StringIO
 
181
        inv = Inventory()
 
182
        stdout = StringIO()
 
183
 
 
184
        self.apply_redirected(None, stdout, None, action, inv, 'path', 'file')
 
185
        self.assertEqual(stdout.getvalue(), output)
 
186
 
 
187
        if should_add:
 
188
            self.assertNotEqual(inv.path2id('path'), None)
 
189
        else:
 
190
            self.assertEqual(inv.path2id('path'), None)