~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: Wouter van Heyst
  • Date: 2006-07-13 18:18:00 UTC
  • mfrom: (1863 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1867.
  • Revision ID: larstiq@larstiq.dyndns.org-20060713181800-4e8c4f9326597d7f
[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.branch import Branch
7
 
from bzrlib.errors import NotBranchError, NoSuchFile
 
6
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
 
7
from bzrlib.errors import NoSuchFile
8
8
from bzrlib.inventory import InventoryFile, Inventory
9
9
from bzrlib.workingtree import WorkingTree
10
10
 
 
11
 
11
12
class TestSmartAdd(TestCaseWithTransport):
12
13
 
13
14
    def test_add_dot_from_root(self):
16
17
        paths = ("original/", "original/file1", "original/file2")
17
18
        self.build_tree(paths)
18
19
        wt = self.make_branch_and_tree('.')
19
 
        branch = wt.branch
20
20
        smart_add_tree(wt, (u".",))
21
21
        for path in paths:
22
22
            self.assertNotEqual(wt.path2id(path), None)
27
27
        paths = ("original/", "original/file1", "original/file2")
28
28
        self.build_tree(paths)
29
29
        wt = self.make_branch_and_tree('.')
30
 
        branch = wt.branch
31
30
        os.chdir("original")
32
31
        smart_add_tree(wt, (u".",))
33
32
        for path in paths:
41
40
                        "branch/original/file2")
42
41
        self.build_tree(branch_paths)
43
42
        wt = self.make_branch_and_tree('branch')
44
 
        branch = wt.branch
45
43
        smart_add_tree(wt, ("branch",))
46
44
        for path in paths:
47
45
            self.assertNotEqual(wt.path2id(path), None)
57
55
        
58
56
        self.build_tree(build_paths)
59
57
        wt = self.make_branch_and_tree('.')
60
 
        branch = wt.branch
61
58
        child_tree = self.make_branch_and_tree('original/child')
62
59
        smart_add_tree(wt, (".",))
63
60
        for path in paths:
104
101
        from bzrlib.commands import run_bzr
105
102
        eq = self.assertEqual
106
103
        wt = self.make_branch_and_tree('.')
107
 
        branch = wt.branch
108
104
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
109
105
        eq(list(wt.unknowns()), ['inertiatic'])
110
106
        self.capture('add --dry-run .')
114
110
        """Test smart-adding a file that does not exist."""
115
111
        from bzrlib.add import smart_add
116
112
        wt = self.make_branch_and_tree('.')
117
 
        branch = wt.branch
118
113
        self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
119
114
 
120
 
    def test_returns(self):
 
115
    def test_returns_and_ignores(self):
121
116
        """Correctly returns added/ignored files"""
122
117
        from bzrlib.commands import run_bzr
123
118
        wt = self.make_branch_and_tree('.')
124
 
        branch = wt.branch
 
119
        # no files should be ignored by default, so we need to create
 
120
        # an ignore rule - we create one for the pyc files, which means
 
121
        # CVS should not be ignored.
125
122
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS', 
126
123
                        'inertiatic/foo.pyc'])
 
124
        self.build_tree_contents([('.bzrignore', '*.py[oc]\n')])
127
125
        added, ignored = smart_add_tree(wt, u'.')
128
 
        self.assertSubset(('inertiatic', 'inertiatic/esp'), added)
129
 
        self.assertSubset(('CVS', '*.py[oc]'), ignored)
130
 
        self.assertSubset(('inertiatic/CVS',), ignored['CVS'])
 
126
        self.assertSubset(('inertiatic', 'inertiatic/esp', 'inertiatic/CVS'),
 
127
                          added)
 
128
        self.assertSubset(('*.py[oc]',), ignored)
131
129
        self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[oc]'])
132
130
 
133
131
 
134
 
class TestSmartAddBranch(TestCaseWithTransport):
 
132
class TestSmartAddTree(TestCaseWithTransport):
135
133
    """Test smart adds with a specified branch."""
136
134
 
137
135
    def test_add_dot_from_root(self):
139
137
        paths = ("original/", "original/file1", "original/file2")
140
138
        self.build_tree(paths)
141
139
        wt = self.make_branch_and_tree('.')
142
 
        branch = wt.branch
143
140
        smart_add_tree(wt, (u".",))
144
141
        for path in paths:
145
142
            self.assertNotEqual(wt.path2id(path), None)
146
143
 
147
144
    def test_add_dot_from_subdir(self):
148
145
        """Test adding . from a subdir of the tree.""" 
149
 
        from bzrlib.add import smart_add_tree
150
146
        paths = ("original/", "original/file1", "original/file2")
151
147
        self.build_tree(paths)
152
148
        wt = self.make_branch_and_tree('.')
153
 
        branch = wt.branch
154
149
        os.chdir("original")
155
150
        smart_add_tree(wt, (u".",))
156
151
        for path in paths:
158
153
 
159
154
    def test_add_tree_from_above_tree(self):
160
155
        """Test adding a tree from above the tree.""" 
161
 
        from bzrlib.add import smart_add_tree
162
156
        paths = ("original/", "original/file1", "original/file2")
163
157
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
164
158
                        "branch/original/file2")
165
159
        self.build_tree(branch_paths)
166
160
        tree = self.make_branch_and_tree('branch')
167
 
        branch = tree.branch
168
161
        smart_add_tree(tree, ("branch",))
169
162
        for path in paths:
170
163
            self.assertNotEqual(tree.path2id(path), None)
171
164
 
172
165
    def test_add_above_tree_preserves_tree(self):
173
166
        """Test nested trees are not affect by an add above them."""
174
 
        from bzrlib.add import smart_add_tree
175
167
        paths = ("original/", "original/file1", "original/file2")
176
168
        child_paths = ("path")
177
169
        full_child_paths = ("original/child", "original/child/path")
179
171
                       "original/child/", "original/child/path")
180
172
        self.build_tree(build_paths)
181
173
        tree = self.make_branch_and_tree('.')
182
 
        branch = tree.branch
183
174
        child_tree = self.make_branch_and_tree("original/child")
184
175
        smart_add_tree(tree, (u".",))
185
176
        for path in paths:
193
184
 
194
185
    def test_add_paths(self):
195
186
        """Test smart-adding a list of paths."""
196
 
        from bzrlib.add import smart_add_tree
197
187
        paths = ("file1", "file2")
198
188
        self.build_tree(paths)
199
189
        wt = self.make_branch_and_tree('.')
200
 
        branch = wt.branch
201
190
        smart_add_tree(wt, paths)
202
191
        for path in paths:
203
192
            self.assertNotEqual(wt.path2id(path), None)
204
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
 
205
273
 
206
274
class TestAddActions(TestCase):
207
275