/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 bzrlib/tests/test_inv.py

  • Committer: Aaron Bentley
  • Date: 2006-05-20 17:51:13 UTC
  • mfrom: (1718 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: aaron.bentley@utoronto.ca-20060520175113-4549e0023f9210bf
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib.branch import Branch
21
21
import bzrlib.errors as errors
22
22
from bzrlib.diff import internal_diff
23
 
from bzrlib.inventory import Inventory, ROOT_ID
 
23
from bzrlib.inventory import (Inventory, ROOT_ID, InventoryFile,
 
24
    InventoryDirectory, InventoryEntry)
24
25
import bzrlib.inventory as inventory
25
26
from bzrlib.osutils import has_symlinks, rename, pathjoin
26
27
from bzrlib.tests import TestCase, TestCaseWithTransport
 
28
from bzrlib.transform import TreeTransform
 
29
from bzrlib.uncommit import uncommit
27
30
 
28
31
 
29
32
class TestInventory(TestCase):
139
142
        self.wt = self.make_branch_and_tree('.')
140
143
        self.branch = self.wt.branch
141
144
        print >> open('file', 'wb'), 'foo'
 
145
        print >> open('binfile', 'wb'), 'foo'
142
146
        self.wt.add(['file'], ['fileid'])
 
147
        self.wt.add(['binfile'], ['binfileid'])
143
148
        if has_symlinks():
144
149
            os.symlink('target1', 'symlink')
145
150
            self.wt.add(['symlink'], ['linkid'])
146
151
        self.wt.commit('message_1', rev_id = '1')
147
152
        print >> open('file', 'wb'), 'bar'
 
153
        print >> open('binfile', 'wb'), 'x' * 1023 + '\x00'
148
154
        if has_symlinks():
149
155
            os.unlink('symlink')
150
156
            os.symlink('target2', 'symlink')
151
157
        self.tree_1 = self.branch.repository.revision_tree('1')
152
158
        self.inv_1 = self.branch.repository.get_inventory('1')
153
159
        self.file_1 = self.inv_1['fileid']
 
160
        self.file_1b = self.inv_1['binfileid']
154
161
        self.tree_2 = self.wt
155
162
        self.inv_2 = self.tree_2.read_working_inventory()
156
163
        self.file_2 = self.inv_2['fileid']
 
164
        self.file_2b = self.inv_2['binfileid']
157
165
        if has_symlinks():
158
166
            self.link_1 = self.inv_1['linkid']
159
167
            self.link_2 = self.inv_2['linkid']
195
203
                                            "+bar\n"
196
204
                                            "\n")
197
205
        
 
206
    def test_file_diff_binary(self):
 
207
        output = StringIO()
 
208
        self.file_1.diff(internal_diff, 
 
209
                          "/dev/null", self.tree_1, 
 
210
                          "new_label", self.file_2b, self.tree_2,
 
211
                          output)
 
212
        self.assertEqual(output.getvalue(), 
 
213
                         "Binary files /dev/null and new_label differ\n")
198
214
    def test_link_diff_deleted(self):
199
215
        if not has_symlinks():
200
216
            return
339
355
        self.wt.add(['file'], ['fileid'])
340
356
        self.wt.commit('add file', rev_id='B')
341
357
        self.inv_B = self.branch.repository.get_inventory('B')
342
 
        self.branch.lock_write()
343
 
        try:
344
 
            self.branch.control_files.put_utf8('revision-history', 'A\n')
345
 
        finally:
346
 
            self.branch.unlock()
 
358
        uncommit(self.branch, tree=self.wt)
347
359
        self.assertEqual(self.branch.revision_history(), ['A'])
348
360
        self.wt.commit('another add of file', rev_id='C')
349
361
        self.inv_C = self.branch.repository.get_inventory('C')
388
400
    # TODO: test two inventories with the same file revision 
389
401
 
390
402
 
 
403
class TestDescribeChanges(TestCase):
 
404
 
 
405
    def test_describe_change(self):
 
406
        # we need to test the following change combinations:
 
407
        # rename
 
408
        # reparent
 
409
        # modify
 
410
        # gone
 
411
        # added
 
412
        # renamed/reparented and modified
 
413
        # change kind (perhaps can't be done yet?)
 
414
        # also, merged in combination with all of these?
 
415
        old_a = InventoryFile('a-id', 'a_file', ROOT_ID)
 
416
        old_a.text_sha1 = '123132'
 
417
        old_a.text_size = 0
 
418
        new_a = InventoryFile('a-id', 'a_file', ROOT_ID)
 
419
        new_a.text_sha1 = '123132'
 
420
        new_a.text_size = 0
 
421
 
 
422
        self.assertChangeDescription('unchanged', old_a, new_a)
 
423
 
 
424
        new_a.text_size = 10
 
425
        new_a.text_sha1 = 'abcabc'
 
426
        self.assertChangeDescription('modified', old_a, new_a)
 
427
 
 
428
        self.assertChangeDescription('added', None, new_a)
 
429
        self.assertChangeDescription('removed', old_a, None)
 
430
        # perhaps a bit questionable but seems like the most reasonable thing...
 
431
        self.assertChangeDescription('unchanged', None, None)
 
432
 
 
433
        # in this case it's both renamed and modified; show a rename and 
 
434
        # modification:
 
435
        new_a.name = 'newfilename'
 
436
        self.assertChangeDescription('modified and renamed', old_a, new_a)
 
437
 
 
438
        # reparenting is 'renaming'
 
439
        new_a.name = old_a.name
 
440
        new_a.parent_id = 'somedir-id'
 
441
        self.assertChangeDescription('modified and renamed', old_a, new_a)
 
442
 
 
443
        # reset the content values so its not modified
 
444
        new_a.text_size = old_a.text_size
 
445
        new_a.text_sha1 = old_a.text_sha1
 
446
        new_a.name = old_a.name
 
447
 
 
448
        new_a.name = 'newfilename'
 
449
        self.assertChangeDescription('renamed', old_a, new_a)
 
450
 
 
451
        # reparenting is 'renaming'
 
452
        new_a.name = old_a.name
 
453
        new_a.parent_id = 'somedir-id'
 
454
        self.assertChangeDescription('renamed', old_a, new_a)
 
455
 
 
456
    def assertChangeDescription(self, expected_change, old_ie, new_ie):
 
457
        change = InventoryEntry.describe_change(old_ie, new_ie)
 
458
        self.assertEqual(expected_change, change)
 
459
 
 
460
 
391
461
class TestExecutable(TestCaseWithTransport):
392
462
 
393
463
    def test_stays_executable(self):
394
 
        basic_inv = """<inventory format="5">
395
 
<file file_id="a-20051208024829-849e76f7968d7a86" name="a" executable="yes" />
396
 
<file file_id="b-20051208024829-849e76f7968d7a86" name="b" />
397
 
</inventory>
398
 
"""
399
 
        wt = self.make_branch_and_tree('b1')
400
 
        b = wt.branch
401
 
        open('b1/a', 'wb').write('a test\n')
402
 
        open('b1/b', 'wb').write('b test\n')
403
 
        os.chmod('b1/a', 0755)
404
 
        os.chmod('b1/b', 0644)
405
 
        # Manually writing the inventory, to ensure that
406
 
        # the executable="yes" entry is set for 'a' and not for 'b'
407
 
        open('b1/.bzr/inventory', 'wb').write(basic_inv)
408
 
 
409
464
        a_id = "a-20051208024829-849e76f7968d7a86"
410
465
        b_id = "b-20051208024829-849e76f7968d7a86"
 
466
        wt = self.make_branch_and_tree('b1')
 
467
        b = wt.branch
 
468
        tt = TreeTransform(wt)
 
469
        tt.new_file('a', tt.root, 'a test\n', a_id, True)
 
470
        tt.new_file('b', tt.root, 'b test\n', b_id, False)
 
471
        tt.apply()
 
472
 
 
473
        self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
 
474
 
 
475
        # reopen the tree and ensure it stuck.
411
476
        wt = wt.bzrdir.open_workingtree()
412
477
        self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
413
478
 
488
553
        self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
489
554
        self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
490
555
 
 
556
 
491
557
class TestRevert(TestCaseWithTransport):
 
558
 
492
559
    def test_dangling_id(self):
493
560
        wt = self.make_branch_and_tree('b1')
494
561
        self.assertEqual(len(wt.inventory), 1)
498
565
        os.unlink('b1/a')
499
566
        wt.revert([])
500
567
        self.assertEqual(len(wt.inventory), 1)
501
 
 
502