/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-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

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