/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: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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