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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

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