~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: Matthieu Moy
  • Date: 2006-07-08 19:32:30 UTC
  • mfrom: (1845 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1857.
  • Revision ID: Matthieu.Moy@imag.fr-20060708193230-3eb72d871471bd5b
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
from bzrlib.add import smart_add, smart_add_tree
5
5
from bzrlib.tests import TestCaseWithTransport, TestCase
6
 
from bzrlib.branch import Branch
7
 
from bzrlib.errors import NotBranchError, NoSuchFile
 
6
from bzrlib.errors import NoSuchFile
8
7
from bzrlib.inventory import InventoryFile, Inventory
9
8
from bzrlib.workingtree import WorkingTree
10
9
 
59
58
        wt = self.make_branch_and_tree('.')
60
59
        branch = wt.branch
61
60
        child_tree = self.make_branch_and_tree('original/child')
62
 
        smart_add_tree(wt, (u".",))
 
61
        smart_add_tree(wt, (".",))
63
62
        for path in paths:
64
63
            self.assertNotEqual((path, wt.path2id(path)),
65
64
                                (path, None))
75
74
        paths = ("file1", "file2")
76
75
        self.build_tree(paths)
77
76
        wt = self.make_branch_and_tree('.')
78
 
        branch = wt.branch
79
77
        smart_add_tree(wt, paths)
80
78
        for path in paths:
81
79
            self.assertNotEqual(wt.path2id(path), None)
 
80
    
 
81
    def test_add_ignored_nested_paths(self):
 
82
        """Test smart-adding a list of paths which includes ignored ones."""
 
83
        wt = self.make_branch_and_tree('.')
 
84
        tree_shape = ("adir/", "adir/CVS/", "adir/CVS/afile", "adir/CVS/afile2")
 
85
        add_paths = ("adir/CVS", "adir/CVS/afile", "adir")
 
86
        expected_paths = ("adir", "adir/CVS", "adir/CVS/afile", "adir/CVS/afile2")
 
87
        self.build_tree(tree_shape)
 
88
        smart_add_tree(wt, add_paths)
 
89
        for path in expected_paths:
 
90
            self.assertNotEqual(wt.path2id(path), None, "No id added for %s" % path)
 
91
 
 
92
    def test_save_false(self):
 
93
        """Test smart-adding a path with save set to false."""
 
94
        wt = self.make_branch_and_tree('.')
 
95
        self.build_tree(['file'])
 
96
        smart_add_tree(wt, ['file'], save=False)
 
97
        self.assertNotEqual(wt.path2id('file'), None, "No id added for 'file'")
 
98
        wt.read_working_inventory()
 
99
        self.assertEqual(wt.path2id('file'), None)
82
100
 
83
101
    def test_add_dry_run(self):
84
102
        """Test a dry run add, make sure nothing is added."""
98
116
        branch = wt.branch
99
117
        self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
100
118
 
101
 
    def test_returns(self):
 
119
    def test_returns_and_ignores(self):
102
120
        """Correctly returns added/ignored files"""
103
121
        from bzrlib.commands import run_bzr
104
122
        wt = self.make_branch_and_tree('.')
105
123
        branch = wt.branch
 
124
        # no files should be ignored by default, so we need to create
 
125
        # an ignore rule - we create one for the pyc files, which means
 
126
        # CVS should not be ignored.
106
127
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS', 
107
128
                        'inertiatic/foo.pyc'])
 
129
        self.build_tree_contents([('.bzrignore', '*.py[oc]\n')])
108
130
        added, ignored = smart_add_tree(wt, u'.')
109
 
        self.assertSubset(('inertiatic', 'inertiatic/esp'), added)
110
 
        self.assertSubset(('CVS', '*.py[oc]'), ignored)
111
 
        self.assertSubset(('inertiatic/CVS',), ignored['CVS'])
 
131
        self.assertSubset(('inertiatic', 'inertiatic/esp', 'inertiatic/CVS'),
 
132
                          added)
 
133
        self.assertSubset(('*.py[oc]',), ignored)
112
134
        self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[oc]'])
113
135
 
114
136
 
115
 
class TestSmartAddBranch(TestCaseWithTransport):
 
137
class TestSmartAddTree(TestCaseWithTransport):
116
138
    """Test smart adds with a specified branch."""
117
139
 
118
140
    def test_add_dot_from_root(self):
186
208
 
187
209
class TestAddActions(TestCase):
188
210
 
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
 
211
    def test_quiet(self):
 
212
        self.run_action("")
 
213
 
 
214
    def test__print(self):
 
215
        self.run_action("added path\n")
 
216
 
 
217
    def run_action(self, output):
 
218
        from bzrlib.add import AddAction, FastPath
 
219
        from cStringIO import StringIO
208
220
        inv = Inventory()
209
221
        stdout = StringIO()
 
222
        action = AddAction(to_file=stdout, should_print=bool(output))
210
223
 
211
 
        self.apply_redirected(None, stdout, None, action, inv, None, 'path', 'file')
 
224
        self.apply_redirected(None, stdout, None, action, inv, None, FastPath('path'), 'file')
212
225
        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)