~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-05-05 19:55:59 UTC
  • mfrom: (4331.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090505195559-0qmeyyua7e407sym
(vila) Parametrize tests against dir readers and fix some unicode
        symlink latent bugs

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
        self.assertEqual('directory',
130
130
            creator.shelf_transform.final_kind(s_bar_trans_id))
131
131
 
 
132
    def _test_shelve_symlink_creation(self, link_name, link_target):
 
133
        self.requireFeature(tests.SymlinkFeature)
 
134
        tree = self.make_branch_and_tree('.')
 
135
        tree.lock_write()
 
136
        self.addCleanup(tree.unlock)
 
137
        tree.commit('Empty tree')
 
138
        os.symlink(link_target, link_name)
 
139
        tree.add(link_name, 'foo-id')
 
140
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
 
141
        self.addCleanup(creator.finalize)
 
142
        self.assertEqual([('add file', 'foo-id', 'symlink', link_name)],
 
143
                         list(creator.iter_shelvable()))
 
144
        creator.shelve_creation('foo-id')
 
145
        creator.transform()
 
146
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
 
147
        self.failIfExists(link_name)
 
148
        limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
 
149
        self.assertEqual(link_target, osutils.readlink(limbo_name))
 
150
        ptree = creator.shelf_transform.get_preview_tree()
 
151
        self.assertEqual(link_target, ptree.get_symlink_target('foo-id'))
 
152
 
132
153
    def test_shelve_symlink_creation(self):
133
 
        self.requireFeature(tests.SymlinkFeature)
134
 
        tree = self.make_branch_and_tree('.')
135
 
        tree.lock_write()
136
 
        self.addCleanup(tree.unlock)
137
 
        tree.commit('Empty tree')
138
 
        os.symlink('bar', 'foo')
139
 
        tree.add('foo', 'foo-id')
140
 
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
141
 
        self.addCleanup(creator.finalize)
142
 
        self.assertEqual([('add file', 'foo-id', 'symlink', 'foo')],
143
 
                         list(creator.iter_shelvable()))
144
 
        creator.shelve_creation('foo-id')
145
 
        creator.transform()
146
 
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
147
 
        self.failIfExists('foo')
148
 
        limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
149
 
        self.assertEqual('bar', os.readlink(limbo_name))
150
 
 
151
 
    def test_shelve_symlink_target_change(self):
152
 
        self.requireFeature(tests.SymlinkFeature)
153
 
        tree = self.make_branch_and_tree('.')
154
 
        tree.lock_write()
155
 
        self.addCleanup(tree.unlock)
156
 
        os.symlink('bar', 'foo')
157
 
        tree.add('foo', 'foo-id')
 
154
        self._test_shelve_symlink_creation('foo', 'bar')
 
155
 
 
156
    def test_shelve_unicode_symlink_creation(self):
 
157
        self.requireFeature(tests.UnicodeFilenameFeature)
 
158
        self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
 
159
                                           u'b\N{Euro Sign}ar')
 
160
 
 
161
    def _test_shelve_symlink_target_change(self, link_name,
 
162
                                           old_target, new_target):
 
163
        self.requireFeature(tests.SymlinkFeature)
 
164
        tree = self.make_branch_and_tree('.')
 
165
        tree.lock_write()
 
166
        self.addCleanup(tree.unlock)
 
167
        os.symlink(old_target, link_name)
 
168
        tree.add(link_name, 'foo-id')
158
169
        tree.commit("commit symlink")
159
 
        os.unlink("foo")
160
 
        os.symlink('baz', 'foo')
 
170
        os.unlink(link_name)
 
171
        os.symlink(new_target, link_name)
161
172
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
162
173
        self.addCleanup(creator.finalize)
163
 
        self.assertEqual([('modify target', 'foo-id', 'foo', 'bar', 'baz')],
 
174
        self.assertEqual([('modify target', 'foo-id', link_name,
 
175
                           old_target, new_target)],
164
176
                         list(creator.iter_shelvable()))
165
177
        creator.shelve_modify_target('foo-id')
166
178
        creator.transform()
167
 
        self.assertEqual('bar', os.readlink('foo'))
 
179
        self.assertEqual(old_target, osutils.readlink(link_name))
168
180
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
169
181
        limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
170
 
        self.assertEqual('baz', os.readlink(limbo_name))
 
182
        self.assertEqual(new_target, osutils.readlink(limbo_name))
 
183
        ptree = creator.shelf_transform.get_preview_tree()
 
184
        self.assertEqual(new_target, ptree.get_symlink_target('foo-id'))
 
185
 
 
186
    def test_shelve_symlink_target_change(self):
 
187
        self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
 
188
 
 
189
    def test_shelve_unicode_symlink_target_change(self):
 
190
        self.requireFeature(tests.UnicodeFilenameFeature)
 
191
        self._test_shelve_symlink_target_change(
 
192
            u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
171
193
 
172
194
    def test_shelve_creation_no_contents(self):
173
195
        tree = self.make_branch_and_tree('.')