~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

[merge] add --dry-run option (mpe)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from bzrlib.tests import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import Branch
6
6
from bzrlib.errors import NotBranchError
7
 
from bzrlib.inventory import InventoryFile
 
7
from bzrlib.inventory import InventoryFile, Inventory
8
8
from bzrlib.workingtree import WorkingTree
9
9
 
10
10
class TestSmartAdd(TestCaseInTempDir):
15
15
        paths = ("original/", "original/file1", "original/file2")
16
16
        self.build_tree(paths)
17
17
        branch = Branch.initialize(u".")
18
 
        smart_add((u".",), recurse=True)
 
18
        smart_add((u".",))
19
19
        for path in paths:
20
20
            self.assertNotEqual(branch.working_tree().path2id(path), None)
21
21
 
26
26
        self.build_tree(paths)
27
27
        branch = Branch.initialize(u".")
28
28
        os.chdir("original")
29
 
        smart_add((u".",), recurse=True)
 
29
        smart_add((u".",))
30
30
        for path in paths:
31
31
            self.assertNotEqual(branch.working_tree().path2id(path), None)
32
32
 
44
44
 
45
45
    def test_add_above_tree_preserves_tree(self):
46
46
        """Test nested trees are not affect by an add above them."""
47
 
        from bzrlib.add import smart_add, add_reporter_null
48
 
        
 
47
        from bzrlib.add import smart_add
49
48
        paths = ("original/", "original/file1", "original/file2")
50
49
        child_paths = ("path",)
51
50
        full_child_paths = ("original/child", "original/child/path")
55
54
        self.build_tree(build_paths)
56
55
        branch = Branch.initialize(u".")
57
56
        child_branch = Branch.initialize("original/child")
58
 
        smart_add((u".",), True, add_reporter_null)
 
57
        smart_add((u".",))
59
58
        for path in paths:
60
59
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
61
60
                                (path, None))
74
73
        smart_add(paths)
75
74
        for path in paths:
76
75
            self.assertNotEqual(branch.working_tree().path2id(path), None)
77
 
            
 
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
 
78
88
class TestSmartAddBranch(TestCaseInTempDir):
79
89
    """Test smart adds with a specified branch."""
80
90
 
147
157
        for path in paths:
148
158
            self.assertNotEqual(tree.path2id(path), None)
149
159
 
150
 
class TestAddCallbacks(TestCaseInTempDir):
151
 
 
152
 
    def setUp(self):
153
 
        super(TestAddCallbacks, self).setUp()
 
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):
154
167
        self.entry = InventoryFile("id", "name", None)
155
 
 
156
 
    def test_null_callback(self):
157
 
        from bzrlib.add import add_reporter_null
158
 
        add_reporter_null('path', 'file', self.entry)
159
 
 
160
 
    def test_print_callback(self):
161
 
        from bzrlib.add import add_reporter_print
 
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):
162
180
        from StringIO import StringIO
 
181
        inv = Inventory()
163
182
        stdout = StringIO()
164
 
        self.apply_redirected(None, stdout, None, add_reporter_print,
165
 
                              'path', 'file', self.entry)
166
 
        self.assertEqual(stdout.getvalue(), "added path\n")
 
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)