~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

  • Committer: Martin Pool
  • Date: 2006-02-01 12:24:35 UTC
  • mfrom: (1534.4.32 branch-formats)
  • mto: This revision was merged to the branch mainline in revision 1553.
  • Revision ID: mbp@sourcefrog.net-20060201122435-53f3efb1b5749fe1
[merge] branch-formats branch, and reconcile changes

Show diffs side-by-side

added added

removed removed

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