/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: Jan Balster
  • Date: 2006-08-15 12:39:42 UTC
  • mfrom: (1923 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1928.
  • Revision ID: jan@merlinux.de-20060815123942-22c388c6e9a8ac91
merge bzr.dev 1923

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, ignores, 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:
102
99
    def test_add_dry_run(self):
103
100
        """Test a dry run add, make sure nothing is added."""
104
101
        from bzrlib.commands import run_bzr
 
102
        ignores._set_user_ignores(['./.bazaar'])
105
103
        eq = self.assertEqual
106
104
        wt = self.make_branch_and_tree('.')
107
 
        branch = wt.branch
108
105
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
109
106
        eq(list(wt.unknowns()), ['inertiatic'])
110
107
        self.capture('add --dry-run .')
114
111
        """Test smart-adding a file that does not exist."""
115
112
        from bzrlib.add import smart_add
116
113
        wt = self.make_branch_and_tree('.')
117
 
        branch = wt.branch
118
114
        self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
119
115
 
120
 
    def test_returns(self):
 
116
    def test_returns_and_ignores(self):
121
117
        """Correctly returns added/ignored files"""
122
118
        from bzrlib.commands import run_bzr
123
119
        wt = self.make_branch_and_tree('.')
124
 
        branch = wt.branch
125
 
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS', 
 
120
        # The default ignore list includes '*.py[co]', but not CVS
 
121
        ignores._set_user_ignores(['./.bazaar', '*.py[co]'])
 
122
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
126
123
                        'inertiatic/foo.pyc'])
127
124
        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'])
131
 
        self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[oc]'])
132
 
 
133
 
 
134
 
class TestSmartAddBranch(TestCaseWithTransport):
 
125
        self.assertSubset(('inertiatic', 'inertiatic/esp', 'inertiatic/CVS'),
 
126
                          added)
 
127
        self.assertSubset(('*.py[co]',), ignored)
 
128
        self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[co]'])
 
129
 
 
130
 
 
131
class TestSmartAddTree(TestCaseWithTransport):
135
132
    """Test smart adds with a specified branch."""
136
133
 
137
134
    def test_add_dot_from_root(self):
139
136
        paths = ("original/", "original/file1", "original/file2")
140
137
        self.build_tree(paths)
141
138
        wt = self.make_branch_and_tree('.')
142
 
        branch = wt.branch
143
139
        smart_add_tree(wt, (u".",))
144
140
        for path in paths:
145
141
            self.assertNotEqual(wt.path2id(path), None)
146
142
 
147
143
    def test_add_dot_from_subdir(self):
148
144
        """Test adding . from a subdir of the tree.""" 
149
 
        from bzrlib.add import smart_add_tree
150
145
        paths = ("original/", "original/file1", "original/file2")
151
146
        self.build_tree(paths)
152
147
        wt = self.make_branch_and_tree('.')
153
 
        branch = wt.branch
154
148
        os.chdir("original")
155
149
        smart_add_tree(wt, (u".",))
156
150
        for path in paths:
158
152
 
159
153
    def test_add_tree_from_above_tree(self):
160
154
        """Test adding a tree from above the tree.""" 
161
 
        from bzrlib.add import smart_add_tree
162
155
        paths = ("original/", "original/file1", "original/file2")
163
156
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
164
157
                        "branch/original/file2")
165
158
        self.build_tree(branch_paths)
166
159
        tree = self.make_branch_and_tree('branch')
167
 
        branch = tree.branch
168
160
        smart_add_tree(tree, ("branch",))
169
161
        for path in paths:
170
162
            self.assertNotEqual(tree.path2id(path), None)
171
163
 
172
164
    def test_add_above_tree_preserves_tree(self):
173
165
        """Test nested trees are not affect by an add above them."""
174
 
        from bzrlib.add import smart_add_tree
175
166
        paths = ("original/", "original/file1", "original/file2")
176
167
        child_paths = ("path")
177
168
        full_child_paths = ("original/child", "original/child/path")
179
170
                       "original/child/", "original/child/path")
180
171
        self.build_tree(build_paths)
181
172
        tree = self.make_branch_and_tree('.')
182
 
        branch = tree.branch
183
173
        child_tree = self.make_branch_and_tree("original/child")
184
174
        smart_add_tree(tree, (u".",))
185
175
        for path in paths:
193
183
 
194
184
    def test_add_paths(self):
195
185
        """Test smart-adding a list of paths."""
196
 
        from bzrlib.add import smart_add_tree
197
186
        paths = ("file1", "file2")
198
187
        self.build_tree(paths)
199
188
        wt = self.make_branch_and_tree('.')
200
 
        branch = wt.branch
201
189
        smart_add_tree(wt, paths)
202
190
        for path in paths:
203
191
            self.assertNotEqual(wt.path2id(path), None)
204
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([('', 'directory'), (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([('', 'directory'), (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
 
205
272
 
206
273
class TestAddActions(TestCase):
207
274