/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: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from .. import (
 
17
from cStringIO import StringIO
 
18
 
 
19
from bzrlib import (
18
20
    add,
19
 
    cache_utf8,
20
 
    errors,
 
21
    inventory,
 
22
    osutils,
21
23
    tests,
22
24
    )
23
 
from ..bzr import (
24
 
    inventory,
25
 
    )
26
 
from ..sixish import (
27
 
    StringIO,
28
 
    )
29
25
 
30
26
 
31
27
class AddCustomIDAction(add.AddAction):
33
29
    def __call__(self, inv, parent_ie, path, kind):
34
30
        # The first part just logs if appropriate
35
31
        # Now generate a custom id
36
 
        file_id = cache_utf8.encode(kind + '-' + path.replace('/', '%'))
 
32
        file_id = osutils.safe_file_id(kind + '-'
 
33
                                       + path.raw_path.replace('/', '%'),
 
34
                                       warn=False)
37
35
        if self.should_print:
38
36
            self._to_file.write('added %s with id %s\n'
39
 
                                % (path, file_id.decode('utf-8')))
 
37
                                % (path.raw_path, file_id))
40
38
        return file_id
41
39
 
42
40
 
49
47
                         'base/dir/', 'base/dir/a',
50
48
                         'base/dir/subdir/',
51
49
                         'base/dir/subdir/b',
52
 
                         ])
 
50
                        ])
53
51
        self.base_tree.add(['a', 'b', 'dir', 'dir/a',
54
52
                            'dir/subdir', 'dir/subdir/b'])
55
53
        self.base_tree.commit('creating initial tree.')
78
76
                 'dir/', 'dir/a',
79
77
                 'dir/subdir/',
80
78
                 'dir/subdir/b',
81
 
                 ]
 
79
                ]
82
80
        self.build_tree(['new/' + fn for fn in files])
83
81
        self.add_helper(self.base_tree, '', new_tree, ['new'])
84
82
 
93
91
 
94
92
        self.build_tree(['new/a', 'new/b', 'new/c',
95
93
                         'new/subdir/', 'new/subdir/b', 'new/subdir/d'])
96
 
        new_tree.set_root_id(self.base_tree.path2id(''))
 
94
        new_tree.set_root_id(self.base_tree.get_root_id())
97
95
        self.add_helper(self.base_tree, 'dir', new_tree, ['new'])
98
96
 
99
97
        # We know 'a' and 'b' exist in the root, and they are being added
117
115
        self.assertNotEqual(None, c_id)
118
116
        self.base_tree.lock_read()
119
117
        self.addCleanup(self.base_tree.unlock)
120
 
        self.assertRaises(errors.NoSuchId, self.base_tree.id2path, c_id)
 
118
        self.failIf(c_id in self.base_tree)
121
119
 
122
120
        d_id = new_tree.path2id('subdir/d')
123
121
        self.assertNotEqual(None, d_id)
124
 
        self.assertRaises(errors.NoSuchId, self.base_tree.id2path, d_id)
 
122
        self.failIf(d_id in self.base_tree)
125
123
 
126
124
    def test_copy_existing_dir(self):
127
125
        self.make_base_tree()
142
140
        self.assertNotEqual(None, a_id)
143
141
        self.base_tree.lock_read()
144
142
        self.addCleanup(self.base_tree.unlock)
145
 
        self.assertRaises(errors.NoSuchId, self.base_tree.id2path, a_id)
 
143
        self.failIf(a_id in self.base_tree)
146
144
 
147
145
 
148
146
class TestAddActions(tests.TestCase):
154
152
        self.run_action("adding path\n")
155
153
 
156
154
    def run_action(self, output):
 
155
        from bzrlib.mutabletree import _FastPath
157
156
        inv = inventory.Inventory()
158
157
        stdout = StringIO()
159
158
        action = add.AddAction(to_file=stdout, should_print=bool(output))
160
159
 
161
160
        self.apply_redirected(None, stdout, None, action, inv, None,
162
 
                              'path', 'file')
 
161
            _FastPath('path'), 'file')
163
162
        self.assertEqual(stdout.getvalue(), output)