/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 breezy/tests/test_smart_add.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-17 17:17:02 UTC
  • mto: This revision was merged to the branch mainline in revision 7187.
  • Revision ID: jelmer@jelmer.uk-20181117171702-4tm0yznbaw3rq3es
More beees.

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 cStringIO import StringIO
18
 
 
19
 
from bzrlib import (
 
17
from .. import (
20
18
    add,
 
19
    cache_utf8,
 
20
    tests,
 
21
    )
 
22
from ..bzr import (
21
23
    inventory,
22
 
    osutils,
23
 
    tests,
 
24
    )
 
25
from ..sixish import (
 
26
    StringIO,
24
27
    )
25
28
 
26
29
 
29
32
    def __call__(self, inv, parent_ie, path, kind):
30
33
        # The first part just logs if appropriate
31
34
        # Now generate a custom id
32
 
        file_id = osutils.safe_file_id(kind + '-'
33
 
                                       + path.raw_path.replace('/', '%'),
34
 
                                       warn=False)
 
35
        file_id = cache_utf8.encode(kind + '-' + path.replace('/', '%'))
35
36
        if self.should_print:
36
37
            self._to_file.write('added %s with id %s\n'
37
 
                                % (path.raw_path, file_id))
 
38
                                % (path, file_id.decode('utf-8')))
38
39
        return file_id
39
40
 
40
41
 
47
48
                         'base/dir/', 'base/dir/a',
48
49
                         'base/dir/subdir/',
49
50
                         'base/dir/subdir/b',
50
 
                        ])
 
51
                         ])
51
52
        self.base_tree.add(['a', 'b', 'dir', 'dir/a',
52
53
                            'dir/subdir', 'dir/subdir/b'])
53
54
        self.base_tree.commit('creating initial tree.')
76
77
                 'dir/', 'dir/a',
77
78
                 'dir/subdir/',
78
79
                 'dir/subdir/b',
79
 
                ]
 
80
                 ]
80
81
        self.build_tree(['new/' + fn for fn in files])
81
82
        self.add_helper(self.base_tree, '', new_tree, ['new'])
82
83
 
115
116
        self.assertNotEqual(None, c_id)
116
117
        self.base_tree.lock_read()
117
118
        self.addCleanup(self.base_tree.unlock)
118
 
        self.failIf(c_id in self.base_tree)
 
119
        self.assertFalse(self.base_tree.has_id(c_id))
119
120
 
120
121
        d_id = new_tree.path2id('subdir/d')
121
122
        self.assertNotEqual(None, d_id)
122
 
        self.failIf(d_id in self.base_tree)
 
123
        self.assertFalse(self.base_tree.has_id(d_id))
123
124
 
124
125
    def test_copy_existing_dir(self):
125
126
        self.make_base_tree()
140
141
        self.assertNotEqual(None, a_id)
141
142
        self.base_tree.lock_read()
142
143
        self.addCleanup(self.base_tree.unlock)
143
 
        self.failIf(a_id in self.base_tree)
 
144
        self.assertFalse(self.base_tree.has_id(a_id))
144
145
 
145
146
 
146
147
class TestAddActions(tests.TestCase):
152
153
        self.run_action("adding path\n")
153
154
 
154
155
    def run_action(self, output):
155
 
        from bzrlib.mutabletree import _FastPath
156
156
        inv = inventory.Inventory()
157
157
        stdout = StringIO()
158
158
        action = add.AddAction(to_file=stdout, should_print=bool(output))
159
159
 
160
160
        self.apply_redirected(None, stdout, None, action, inv, None,
161
 
            _FastPath('path'), 'file')
 
161
                              'path', 'file')
162
162
        self.assertEqual(stdout.getvalue(), output)