~michael-ellerman/bzr/mpe

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        wt = self.make_branch_and_tree('.')
60
60
        branch = wt.branch
61
61
        child_tree = self.make_branch_and_tree('original/child')
62
 
        smart_add_tree(wt, (u".",))
 
62
        smart_add_tree(wt, (".",))
63
63
        for path in paths:
64
64
            self.assertNotEqual((path, wt.path2id(path)),
65
65
                                (path, None))
75
75
        paths = ("file1", "file2")
76
76
        self.build_tree(paths)
77
77
        wt = self.make_branch_and_tree('.')
78
 
        branch = wt.branch
79
78
        smart_add_tree(wt, paths)
80
79
        for path in paths:
81
80
            self.assertNotEqual(wt.path2id(path), None)
 
81
    
 
82
    def test_add_ignored_nested_paths(self):
 
83
        """Test smart-adding a list of paths which includes ignored ones."""
 
84
        wt = self.make_branch_and_tree('.')
 
85
        tree_shape = ("adir/", "adir/CVS/", "adir/CVS/afile", "adir/CVS/afile2")
 
86
        add_paths = ("adir/CVS", "adir/CVS/afile", "adir")
 
87
        expected_paths = ("adir", "adir/CVS", "adir/CVS/afile", "adir/CVS/afile2")
 
88
        self.build_tree(tree_shape)
 
89
        smart_add_tree(wt, add_paths)
 
90
        for path in expected_paths:
 
91
            self.assertNotEqual(wt.path2id(path), None, "No id added for %s" % path)
 
92
 
 
93
    def test_save_false(self):
 
94
        """Test smart-adding a path with save set to false."""
 
95
        wt = self.make_branch_and_tree('.')
 
96
        self.build_tree(['file'])
 
97
        smart_add_tree(wt, ['file'], save=False)
 
98
        self.assertNotEqual(wt.path2id('file'), None, "No id added for 'file'")
 
99
        wt.read_working_inventory()
 
100
        self.assertEqual(wt.path2id('file'), None)
82
101
 
83
102
    def test_add_dry_run(self):
84
103
        """Test a dry run add, make sure nothing is added."""
186
205
 
187
206
class TestAddActions(TestCase):
188
207
 
189
 
    def test_null(self):
190
 
        from bzrlib.add import add_action_null
191
 
        self.run_action(add_action_null, "", False)
192
 
 
193
 
    def test_add(self):
194
 
        self.entry = InventoryFile("id", "name", None)
195
 
        from bzrlib.add import add_action_add
196
 
        self.run_action(add_action_add, "", True)
197
 
 
198
 
    def test_add_and_print(self):
199
 
        from bzrlib.add import add_action_add_and_print
200
 
        self.run_action(add_action_add_and_print, "added path\n", True)
201
 
 
202
 
    def test_print(self):
203
 
        from bzrlib.add import add_action_print
204
 
        self.run_action(add_action_print, "added path\n", False)
205
 
 
206
 
    def run_action(self, action, output, should_add):
207
 
        from StringIO import StringIO
 
208
    def test_quiet(self):
 
209
        self.run_action("")
 
210
 
 
211
    def test__print(self):
 
212
        self.run_action("added path\n")
 
213
 
 
214
    def run_action(self, output):
 
215
        from bzrlib.add import AddAction, FastPath
 
216
        from cStringIO import StringIO
208
217
        inv = Inventory()
209
218
        stdout = StringIO()
 
219
        action = AddAction(to_file=stdout, should_print=bool(output))
210
220
 
211
 
        self.apply_redirected(None, stdout, None, action, inv, None, 'path', 'file')
 
221
        self.apply_redirected(None, stdout, None, action, inv, None, FastPath('path'), 'file')
212
222
        self.assertEqual(stdout.getvalue(), output)
213
 
 
214
 
        if should_add:
215
 
            self.assertNotEqual(inv.path2id('path'), None)
216
 
        else:
217
 
            self.assertEqual(inv.path2id('path'), None)