~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-13 00:05:14 UTC
  • mfrom: (1861 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1871.
  • Revision ID: john@arbash-meinel.com-20060713000514-aa62627aa0d4deb6
[merge] bzr.dev 1861

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
import unittest
3
3
 
4
 
from bzrlib import ignores
 
4
from bzrlib import errors, ignores, osutils
5
5
from bzrlib.add import smart_add, smart_add_tree
6
 
from bzrlib.tests import TestCaseWithTransport, TestCase
 
6
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
7
7
from bzrlib.errors import NoSuchFile
8
8
from bzrlib.inventory import InventoryFile, Inventory
9
9
from bzrlib.workingtree import WorkingTree
17
17
        paths = ("original/", "original/file1", "original/file2")
18
18
        self.build_tree(paths)
19
19
        wt = self.make_branch_and_tree('.')
20
 
        branch = wt.branch
21
20
        smart_add_tree(wt, (u".",))
22
21
        for path in paths:
23
22
            self.assertNotEqual(wt.path2id(path), None)
28
27
        paths = ("original/", "original/file1", "original/file2")
29
28
        self.build_tree(paths)
30
29
        wt = self.make_branch_and_tree('.')
31
 
        branch = wt.branch
32
30
        os.chdir("original")
33
31
        smart_add_tree(wt, (u".",))
34
32
        for path in paths:
42
40
                        "branch/original/file2")
43
41
        self.build_tree(branch_paths)
44
42
        wt = self.make_branch_and_tree('branch')
45
 
        branch = wt.branch
46
43
        smart_add_tree(wt, ("branch",))
47
44
        for path in paths:
48
45
            self.assertNotEqual(wt.path2id(path), None)
58
55
        
59
56
        self.build_tree(build_paths)
60
57
        wt = self.make_branch_and_tree('.')
61
 
        branch = wt.branch
62
58
        child_tree = self.make_branch_and_tree('original/child')
63
59
        smart_add_tree(wt, (".",))
64
60
        for path in paths:
106
102
        ignores.set_user_ignores(['./.bazaar'])
107
103
        eq = self.assertEqual
108
104
        wt = self.make_branch_and_tree('.')
109
 
        branch = wt.branch
110
105
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
111
106
        eq(list(wt.unknowns()), ['inertiatic'])
112
107
        self.capture('add --dry-run .')
116
111
        """Test smart-adding a file that does not exist."""
117
112
        from bzrlib.add import smart_add
118
113
        wt = self.make_branch_and_tree('.')
119
 
        branch = wt.branch
120
114
        self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
121
115
 
122
116
    def test_returns_and_ignores(self):
123
117
        """Correctly returns added/ignored files"""
124
118
        from bzrlib.commands import run_bzr
125
119
        wt = self.make_branch_and_tree('.')
126
 
        branch = wt.branch
127
120
        # The default ignore list includes '*.py[co]', but not CVS
128
121
        ignores.set_user_ignores(['./.bazaar', '*.py[co]'])
129
122
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
143
136
        paths = ("original/", "original/file1", "original/file2")
144
137
        self.build_tree(paths)
145
138
        wt = self.make_branch_and_tree('.')
146
 
        branch = wt.branch
147
139
        smart_add_tree(wt, (u".",))
148
140
        for path in paths:
149
141
            self.assertNotEqual(wt.path2id(path), None)
150
142
 
151
143
    def test_add_dot_from_subdir(self):
152
144
        """Test adding . from a subdir of the tree.""" 
153
 
        from bzrlib.add import smart_add_tree
154
145
        paths = ("original/", "original/file1", "original/file2")
155
146
        self.build_tree(paths)
156
147
        wt = self.make_branch_and_tree('.')
157
 
        branch = wt.branch
158
148
        os.chdir("original")
159
149
        smart_add_tree(wt, (u".",))
160
150
        for path in paths:
162
152
 
163
153
    def test_add_tree_from_above_tree(self):
164
154
        """Test adding a tree from above the tree.""" 
165
 
        from bzrlib.add import smart_add_tree
166
155
        paths = ("original/", "original/file1", "original/file2")
167
156
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
168
157
                        "branch/original/file2")
169
158
        self.build_tree(branch_paths)
170
159
        tree = self.make_branch_and_tree('branch')
171
 
        branch = tree.branch
172
160
        smart_add_tree(tree, ("branch",))
173
161
        for path in paths:
174
162
            self.assertNotEqual(tree.path2id(path), None)
175
163
 
176
164
    def test_add_above_tree_preserves_tree(self):
177
165
        """Test nested trees are not affect by an add above them."""
178
 
        from bzrlib.add import smart_add_tree
179
166
        paths = ("original/", "original/file1", "original/file2")
180
167
        child_paths = ("path")
181
168
        full_child_paths = ("original/child", "original/child/path")
183
170
                       "original/child/", "original/child/path")
184
171
        self.build_tree(build_paths)
185
172
        tree = self.make_branch_and_tree('.')
186
 
        branch = tree.branch
187
173
        child_tree = self.make_branch_and_tree("original/child")
188
174
        smart_add_tree(tree, (u".",))
189
175
        for path in paths:
197
183
 
198
184
    def test_add_paths(self):
199
185
        """Test smart-adding a list of paths."""
200
 
        from bzrlib.add import smart_add_tree
201
186
        paths = ("file1", "file2")
202
187
        self.build_tree(paths)
203
188
        wt = self.make_branch_and_tree('.')
204
 
        branch = wt.branch
205
189
        smart_add_tree(wt, paths)
206
190
        for path in paths:
207
191
            self.assertNotEqual(wt.path2id(path), None)
208
192
 
 
193
    def test_add_multiple_dirs(self):
 
194
        """Test smart adding multiple directories at once."""
 
195
        added_paths = ['file1', 'file2',
 
196
                       'dir1/', 'dir1/file3',
 
197
                       'dir1/subdir2/', 'dir1/subdir2/file4',
 
198
                       'dir2/', 'dir2/file5',
 
199
                      ]
 
200
        not_added = ['file6', 'dir3/', 'dir3/file7', 'dir3/file8']
 
201
        self.build_tree(added_paths)
 
202
        self.build_tree(not_added)
 
203
 
 
204
        wt = self.make_branch_and_tree('.')
 
205
        smart_add_tree(wt, ['file1', 'file2', 'dir1', 'dir2'])
 
206
 
 
207
        for path in added_paths:
 
208
            self.assertNotEqual(None, wt.path2id(path.rstrip('/')),
 
209
                    'Failed to add path: %s' % (path,))
 
210
        for path in not_added:
 
211
            self.assertEqual(None, wt.path2id(path.rstrip('/')),
 
212
                    'Accidentally added path: %s' % (path,))
 
213
 
 
214
 
 
215
class TestAddNonNormalized(TestCaseWithTransport):
 
216
 
 
217
    def make(self):
 
218
        try:
 
219
            self.build_tree([u'a\u030a'])
 
220
        except UnicodeError:
 
221
            raise TestSkipped('Filesystem cannot create unicode filenames')
 
222
 
 
223
        self.wt = self.make_branch_and_tree('.')
 
224
 
 
225
    def test_accessible_explicit(self):
 
226
        self.make()
 
227
        orig = osutils.normalized_filename
 
228
        osutils.normalized_filename = osutils._accessible_normalized_filename
 
229
        try:
 
230
            smart_add_tree(self.wt, [u'a\u030a'])
 
231
            self.assertEqual([(u'\xe5', 'file')],
 
232
                    [(path, ie.kind) for path,ie in 
 
233
                        self.wt.inventory.iter_entries()])
 
234
        finally:
 
235
            osutils.normalized_filename = orig
 
236
 
 
237
    def test_accessible_implicit(self):
 
238
        self.make()
 
239
        orig = osutils.normalized_filename
 
240
        osutils.normalized_filename = osutils._accessible_normalized_filename
 
241
        try:
 
242
            smart_add_tree(self.wt, [])
 
243
            self.assertEqual([(u'\xe5', 'file')],
 
244
                    [(path, ie.kind) for path,ie in 
 
245
                        self.wt.inventory.iter_entries()])
 
246
        finally:
 
247
            osutils.normalized_filename = orig
 
248
 
 
249
    def test_inaccessible_explicit(self):
 
250
        self.make()
 
251
        orig = osutils.normalized_filename
 
252
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
 
253
        try:
 
254
            self.assertRaises(errors.InvalidNormalization,
 
255
                    smart_add_tree, self.wt, [u'a\u030a'])
 
256
        finally:
 
257
            osutils.normalized_filename = orig
 
258
 
 
259
    def test_inaccessible_implicit(self):
 
260
        self.make()
 
261
        orig = osutils.normalized_filename
 
262
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
 
263
        try:
 
264
            # TODO: jam 20060701 In the future, this should probably
 
265
            #       just ignore files that don't fit the normalization
 
266
            #       rules, rather than exploding
 
267
            self.assertRaises(errors.InvalidNormalization,
 
268
                    smart_add_tree, self.wt, [])
 
269
        finally:
 
270
            osutils.normalized_filename = orig
 
271
 
209
272
 
210
273
class TestAddActions(TestCase):
211
274