~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 18:38:58 UTC
  • mfrom: (1863 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1869.
  • Revision ID: john@arbash-meinel.com-20060713183858-ebf4aa1f9ef8bb6e
[merge] bzr.dev 1863

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