~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

Move working tree initialisation out from  Branch.initialize, deprecated Branch.initialize to Branch.create.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from bzrlib.inventory import Inventory, ROOT_ID
25
25
import bzrlib.inventory as inventory
26
26
from bzrlib.osutils import has_symlinks, rename, pathjoin
27
 
from bzrlib.tests import TestCase, TestCaseInTempDir
 
27
from bzrlib.tests import TestCase, TestCaseWithTransport
 
28
from bzrlib.workingtree import WorkingTree
28
29
 
29
30
 
30
31
class TestInventory(TestCase):
133
134
        self.failIf(link.has_text())
134
135
 
135
136
 
136
 
class TestEntryDiffing(TestCaseInTempDir):
 
137
class TestEntryDiffing(TestCaseWithTransport):
137
138
 
138
139
    def setUp(self):
139
140
        super(TestEntryDiffing, self).setUp()
140
 
        self.branch = Branch.initialize(u'.')
141
 
        self.wt = self.branch.working_tree()
 
141
        self.wt = self.make_branch_and_tree('.')
 
142
        self.branch = self.wt.branch
142
143
        print >> open('file', 'wb'), 'foo'
143
 
        self.branch.working_tree().add(['file'], ['fileid'])
 
144
        self.wt.add(['file'], ['fileid'])
144
145
        if has_symlinks():
145
146
            os.symlink('target1', 'symlink')
146
 
            self.branch.working_tree().add(['symlink'], ['linkid'])
 
147
            self.wt.add(['symlink'], ['linkid'])
147
148
        self.wt.commit('message_1', rev_id = '1')
148
149
        print >> open('file', 'wb'), 'bar'
149
150
        if has_symlinks():
230
231
                         "=== target changed 'target1' => 'target2'\n")
231
232
 
232
233
 
233
 
class TestSnapshot(TestCaseInTempDir):
 
234
class TestSnapshot(TestCaseWithTransport):
234
235
 
235
236
    def setUp(self):
236
237
        # for full testing we'll need a branch
240
241
        # to change, and then test merge patterns
241
242
        # with fake parent entries.
242
243
        super(TestSnapshot, self).setUp()
243
 
        self.branch = Branch.initialize(u'.')
 
244
        self.wt = self.make_branch_and_tree('.')
 
245
        self.branch = self.wt.branch
244
246
        self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
245
 
        self.branch.working_tree().add(['subdir', 'subdir/file'],
 
247
        self.wt.add(['subdir', 'subdir/file'],
246
248
                                       ['dirid', 'fileid'])
247
249
        if has_symlinks():
248
250
            pass
249
 
        self.wt = self.branch.working_tree()
250
251
        self.wt.commit('message_1', rev_id = '1')
251
252
        self.tree_1 = self.branch.revision_tree('1')
252
253
        self.inv_1 = self.branch.get_inventory('1')
253
254
        self.file_1 = self.inv_1['fileid']
254
 
        self.work_tree = self.branch.working_tree()
255
 
        self.file_active = self.work_tree.inventory['fileid']
 
255
        self.file_active = self.wt.inventory['fileid']
256
256
 
257
257
    def test_snapshot_new_revision(self):
258
258
        # This tests that a simple commit with no parents makes a new
259
259
        # revision value in the inventory entry
260
 
        self.file_active.snapshot('2', 'subdir/file', {}, self.work_tree, 
 
260
        self.file_active.snapshot('2', 'subdir/file', {}, self.wt, 
261
261
                                  self.branch.weave_store,
262
262
                                  self.branch.get_transaction())
263
263
        # expected outcome - file_1 has a revision id of '2', and we can get
273
273
        #This tests that a simple commit does not make a new entry for
274
274
        # an unchanged inventory entry
275
275
        self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
276
 
                                  self.work_tree, self.branch.weave_store,
 
276
                                  self.wt, self.branch.weave_store,
277
277
                                  self.branch.get_transaction())
278
278
        self.assertEqual(self.file_1.revision, '1')
279
279
        self.assertEqual(self.file_active.revision, '1')
297
297
            self.branch.get_transaction())
298
298
        self.file_active.snapshot('2', 'subdir/file', 
299
299
                                  {'1':self.file_1, 'other':other_ie},
300
 
                                  self.work_tree, self.branch.weave_store,
 
300
                                  self.wt, self.branch.weave_store,
301
301
                                  self.branch.get_transaction())
302
302
        self.assertEqual(self.file_active.revision, '2')
303
303
 
307
307
        self.file_active.name='newname'
308
308
        rename('subdir/file', 'subdir/newname')
309
309
        self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, 
310
 
                                  self.work_tree, 
 
310
                                  self.wt, 
311
311
                                  self.branch.weave_store,
312
312
                                  self.branch.get_transaction())
313
313
        # expected outcome - file_1 has a revision id of '2'
314
314
        self.assertEqual(self.file_active.revision, '2')
315
315
 
316
316
 
317
 
class TestPreviousHeads(TestCaseInTempDir):
 
317
class TestPreviousHeads(TestCaseWithTransport):
318
318
 
319
319
    def setUp(self):
320
320
        # we want several inventories, that respectively
326
326
        # D) fileid present in two inventories and one is
327
327
        #   a descendent of the other. (B, D)
328
328
        super(TestPreviousHeads, self).setUp()
 
329
        self.wt = self.make_branch_and_tree('.')
 
330
        self.branch = self.wt.branch
329
331
        self.build_tree(['file'])
330
 
        self.branch = Branch.initialize(u'.')
331
 
        self.wt = self.branch.working_tree()
332
332
        self.wt.commit('new branch', allow_pointless=True, rev_id='A')
333
333
        self.inv_A = self.branch.get_inventory('A')
334
 
        self.branch.working_tree().add(['file'], ['fileid'])
 
334
        self.wt.add(['file'], ['fileid'])
335
335
        self.wt.commit('add file', rev_id='B')
336
336
        self.inv_B = self.branch.get_inventory('B')
337
337
        self.branch.put_controlfile('revision-history', 'A\n')
376
376
    # TODO: test two inventories with the same file revision 
377
377
 
378
378
 
379
 
class TestExecutable(TestCaseInTempDir):
 
379
class TestExecutable(TestCaseWithTransport):
380
380
 
381
381
    def test_stays_executable(self):
382
382
        basic_inv = """<inventory format="5">
384
384
<file file_id="b-20051208024829-849e76f7968d7a86" name="b" />
385
385
</inventory>
386
386
"""
387
 
        os.mkdir('b1')
388
 
        b = Branch.initialize('b1')
 
387
        wt = self.make_branch_and_tree('b1')
 
388
        b = wt.branch
389
389
        open('b1/a', 'wb').write('a test\n')
390
390
        open('b1/b', 'wb').write('b test\n')
391
391
        os.chmod('b1/a', 0755)
396
396
 
397
397
        a_id = "a-20051208024829-849e76f7968d7a86"
398
398
        b_id = "b-20051208024829-849e76f7968d7a86"
399
 
        t = b.working_tree()
 
399
        t = WorkingTree('b1', b)
400
400
        self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
401
401
 
402
402
        self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
448
448
        # This seems to happen any time you do a merge operation on the
449
449
        # working tree
450
450
        del t
451
 
        t = b.working_tree()
 
451
        t = WorkingTree('b1', b)
452
452
 
453
453
        self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
454
454