/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-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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
 
18
 
17
19
from .. import (
18
20
    add,
19
21
    cache_utf8,
20
 
    osutils,
 
22
    errors,
21
23
    tests,
22
24
    )
23
25
from ..bzr import (
24
26
    inventory,
25
27
    )
26
 
from ..sixish import (
27
 
    BytesIO,
28
 
    )
29
28
 
30
29
 
31
30
class AddCustomIDAction(add.AddAction):
36
35
        file_id = cache_utf8.encode(kind + '-' + path.replace('/', '%'))
37
36
        if self.should_print:
38
37
            self._to_file.write('added %s with id %s\n'
39
 
                                % (path, file_id))
 
38
                                % (path, file_id.decode('utf-8')))
40
39
        return file_id
41
40
 
42
41
 
49
48
                         'base/dir/', 'base/dir/a',
50
49
                         'base/dir/subdir/',
51
50
                         'base/dir/subdir/b',
52
 
                        ])
 
51
                         ])
53
52
        self.base_tree.add(['a', 'b', 'dir', 'dir/a',
54
53
                            'dir/subdir', 'dir/subdir/b'])
55
54
        self.base_tree.commit('creating initial tree.')
56
55
 
57
56
    def add_helper(self, base_tree, base_path, new_tree, file_list,
58
57
                   should_print=False):
59
 
        to_file = BytesIO()
 
58
        to_file = StringIO()
60
59
        base_tree.lock_read()
61
60
        try:
62
61
            new_tree.lock_write()
78
77
                 'dir/', 'dir/a',
79
78
                 'dir/subdir/',
80
79
                 'dir/subdir/b',
81
 
                ]
 
80
                 ]
82
81
        self.build_tree(['new/' + fn for fn in files])
83
82
        self.add_helper(self.base_tree, '', new_tree, ['new'])
84
83
 
93
92
 
94
93
        self.build_tree(['new/a', 'new/b', 'new/c',
95
94
                         'new/subdir/', 'new/subdir/b', 'new/subdir/d'])
96
 
        new_tree.set_root_id(self.base_tree.get_root_id())
 
95
        new_tree.set_root_id(self.base_tree.path2id(''))
97
96
        self.add_helper(self.base_tree, 'dir', new_tree, ['new'])
98
97
 
99
98
        # We know 'a' and 'b' exist in the root, and they are being added
117
116
        self.assertNotEqual(None, c_id)
118
117
        self.base_tree.lock_read()
119
118
        self.addCleanup(self.base_tree.unlock)
120
 
        self.assertFalse(self.base_tree.has_id(c_id))
 
119
        self.assertRaises(errors.NoSuchId, self.base_tree.id2path, c_id)
121
120
 
122
121
        d_id = new_tree.path2id('subdir/d')
123
122
        self.assertNotEqual(None, d_id)
124
 
        self.assertFalse(self.base_tree.has_id(d_id))
 
123
        self.assertRaises(errors.NoSuchId, self.base_tree.id2path, d_id)
125
124
 
126
125
    def test_copy_existing_dir(self):
127
126
        self.make_base_tree()
142
141
        self.assertNotEqual(None, a_id)
143
142
        self.base_tree.lock_read()
144
143
        self.addCleanup(self.base_tree.unlock)
145
 
        self.assertFalse(self.base_tree.has_id(a_id))
 
144
        self.assertRaises(errors.NoSuchId, self.base_tree.id2path, a_id)
146
145
 
147
146
 
148
147
class TestAddActions(tests.TestCase):
155
154
 
156
155
    def run_action(self, output):
157
156
        inv = inventory.Inventory()
158
 
        stdout = BytesIO()
 
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
                              'path', 'file')
163
162
        self.assertEqual(stdout.getvalue(), output)