~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
    def test_add_dot_from_root(self):
37
37
        """Test adding . from the root of the tree.""" 
38
 
        from bzrlib.add import smart_add
39
38
        paths = ("original/", "original/file1", "original/file2")
40
39
        self.build_tree(paths)
41
40
        wt = self.make_branch_and_tree('.')
109
108
        for path in expected_paths:
110
109
            self.assertNotEqual(wt.path2id(path), None, "No id added for %s" % path)
111
110
 
112
 
    def test_save_false(self):
113
 
        """Test smart-adding a path with save set to false."""
114
 
        wt = self.make_branch_and_tree('.')
115
 
        self.build_tree(['file'])
116
 
        smart_add_tree(wt, ['file'], save=False)
117
 
        self.assertNotEqual(wt.path2id('file'), None, "No id added for 'file'")
118
 
        wt.read_working_inventory()
119
 
        self.assertEqual(wt.path2id('file'), None)
120
 
 
121
111
    def test_add_dry_run(self):
122
112
        """Test a dry run add, make sure nothing is added."""
123
113
        from bzrlib.commands import run_bzr
125
115
        wt = self.make_branch_and_tree('.')
126
116
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
127
117
        eq(list(wt.unknowns()), ['inertiatic'])
128
 
        self.capture('add --dry-run .')
 
118
        self.run_bzr('add --dry-run .')
129
119
        eq(list(wt.unknowns()), ['inertiatic'])
130
120
 
131
121
    def test_add_non_existant(self):
154
144
    def __call__(self, inv, parent_ie, path, kind):
155
145
        # The first part just logs if appropriate
156
146
        # Now generate a custom id
157
 
        file_id = kind + '-' + path.raw_path.replace('/', '%')
 
147
        file_id = osutils.safe_file_id(kind + '-'
 
148
                                       + path.raw_path.replace('/', '%'),
 
149
                                       warn=False)
158
150
        if self.should_print:
159
 
            self._to_file.write('added %s with id %s\n' 
 
151
            self._to_file.write('added %s with id %s\n'
160
152
                                % (path.raw_path, file_id))
161
153
        return file_id
162
154
 
258
250
                              'added dir1/file2 with id file-dir1%file2\n',
259
251
                              'added file1 with id file-file1\n',
260
252
                             ], lines)
261
 
        self.assertEqual([('', wt.inventory.root.file_id),
 
253
        wt.lock_read()
 
254
        self.addCleanup(wt.unlock)
 
255
        self.assertEqual([('', wt.path2id('')),
262
256
                          ('dir1', 'directory-dir1'),
263
257
                          ('dir1/file2', 'file-dir1%file2'),
264
258
                          ('file1', 'file-file1'),
319
313
 
320
314
        self.build_tree(['new/a', 'new/b', 'new/c',
321
315
                         'new/subdir/', 'new/subdir/b', 'new/subdir/d'])
 
316
        new_tree.set_root_id(self.base_tree.get_root_id())
322
317
        self.add_helper(self.base_tree, 'dir', new_tree, ['new'])
323
318
 
324
 
        # We 'a' and 'b' exist in the root, and they are being added
325
 
        # in a new 'root'. Since ROOT ids are not unique, we will
 
319
        # We know 'a' and 'b' exist in the root, and they are being added
 
320
        # in a new 'root'. Since ROOT ids have been set as the same, we will
326
321
        # use those ids
327
 
        # TODO: This will probably change once trees have a unique root id
328
 
        # It is definitely arguable that 'a' should get the id of
329
 
        # 'dir/a' not of 'a'.
330
322
        self.assertEqual(self.base_tree.path2id('a'),
331
323
                         new_tree.path2id('a'))
332
324
        self.assertEqual(self.base_tree.path2id('b'),
343
335
        # These should get newly generated ids
344
336
        c_id = new_tree.path2id('c')
345
337
        self.assertNotEqual(None, c_id)
 
338
        self.base_tree.lock_read()
 
339
        self.addCleanup(self.base_tree.unlock)
346
340
        self.failIf(c_id in self.base_tree)
347
341
 
348
342
        d_id = new_tree.path2id('subdir/d')
366
360
        # matching path or child of 'subby'.
367
361
        a_id = new_tree.path2id('subby/a')
368
362
        self.assertNotEqual(None, a_id)
 
363
        self.base_tree.lock_read()
 
364
        self.addCleanup(self.base_tree.unlock)
369
365
        self.failIf(a_id in self.base_tree)
370
366
 
371
367
 
385
381
        osutils.normalized_filename = osutils._accessible_normalized_filename
386
382
        try:
387
383
            smart_add_tree(self.wt, [u'a\u030a'])
 
384
            self.wt.lock_read()
 
385
            self.addCleanup(self.wt.unlock)
388
386
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
389
387
                    [(path, ie.kind) for path,ie in 
390
388
                        self.wt.inventory.iter_entries()])
397
395
        osutils.normalized_filename = osutils._accessible_normalized_filename
398
396
        try:
399
397
            smart_add_tree(self.wt, [])
 
398
            self.wt.lock_read()
 
399
            self.addCleanup(self.wt.unlock)
400
400
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
401
401
                    [(path, ie.kind) for path,ie in 
402
402
                        self.wt.inventory.iter_entries()])