/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: Robert Collins
  • Date: 2006-08-08 23:19:29 UTC
  • mfrom: (1884 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1912.
  • Revision ID: robertc@robertcollins.net-20060808231929-4e3e298190214b3a
current status

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
import time
20
20
 
 
21
from bzrlib import errors, inventory, osutils
21
22
from bzrlib.branch import Branch
22
 
import bzrlib.errors as errors
23
23
from bzrlib.diff import internal_diff
24
24
from bzrlib.inventory import (Inventory, ROOT_ID, InventoryFile,
25
25
    InventoryDirectory, InventoryEntry)
26
 
import bzrlib.inventory as inventory
27
26
from bzrlib.osutils import (has_symlinks, rename, pathjoin, is_inside_any, 
28
27
    is_inside_or_parent_of_any)
29
28
from bzrlib.tests import TestCase, TestCaseWithTransport
200
199
        self.assertIsInstance(inventory.make_entry("directory", "name", ROOT_ID),
201
200
            inventory.InventoryDirectory)
202
201
 
 
202
    def test_make_entry_non_normalized(self):
 
203
        orig_normalized_filename = osutils.normalized_filename
 
204
 
 
205
        try:
 
206
            osutils.normalized_filename = osutils._accessible_normalized_filename
 
207
            entry = inventory.make_entry("file", u'a\u030a', ROOT_ID)
 
208
            self.assertEqual(u'\xe5', entry.name)
 
209
            self.assertIsInstance(entry, inventory.InventoryFile)
 
210
 
 
211
            osutils.normalized_filename = osutils._inaccessible_normalized_filename
 
212
            self.assertRaises(errors.InvalidNormalization,
 
213
                    inventory.make_entry, 'file', u'a\u030a', ROOT_ID)
 
214
        finally:
 
215
            osutils.normalized_filename = orig_normalized_filename
 
216
 
 
217
 
203
218
class TestEntryDiffing(TestCaseWithTransport):
204
219
 
205
220
    def setUp(self):
516
531
        self.assertEqual(expected_change, change)
517
532
 
518
533
 
519
 
class TestExecutable(TestCaseWithTransport):
520
 
 
521
 
    def test_stays_executable(self):
522
 
        a_id = "a-20051208024829-849e76f7968d7a86"
523
 
        b_id = "b-20051208024829-849e76f7968d7a86"
524
 
        wt = self.make_branch_and_tree('b1')
525
 
        b = wt.branch
526
 
        tt = TreeTransform(wt)
527
 
        tt.new_file('a', tt.root, 'a test\n', a_id, True)
528
 
        tt.new_file('b', tt.root, 'b test\n', b_id, False)
529
 
        tt.apply()
530
 
 
531
 
        self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
532
 
 
533
 
        # reopen the tree and ensure it stuck.
534
 
        wt = wt.bzrdir.open_workingtree()
535
 
        self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
536
 
 
537
 
        self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
538
 
        self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
539
 
 
540
 
        wt.commit('adding a,b', rev_id='r1')
541
 
 
542
 
        rev_tree = b.repository.revision_tree('r1')
543
 
        self.failUnless(rev_tree.is_executable(a_id), "'a' lost the execute bit")
544
 
        self.failIf(rev_tree.is_executable(b_id), "'b' gained an execute bit")
545
 
 
546
 
        self.failUnless(rev_tree.inventory[a_id].executable)
547
 
        self.failIf(rev_tree.inventory[b_id].executable)
548
 
 
549
 
        # Make sure the entries are gone
550
 
        os.remove('b1/a')
551
 
        os.remove('b1/b')
552
 
        self.failIf(wt.has_id(a_id))
553
 
        self.failIf(wt.has_filename('a'))
554
 
        self.failIf(wt.has_id(b_id))
555
 
        self.failIf(wt.has_filename('b'))
556
 
 
557
 
        # Make sure that revert is able to bring them back,
558
 
        # and sets 'a' back to being executable
559
 
 
560
 
        wt.revert(['a', 'b'], rev_tree, backups=False)
561
 
        self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
562
 
 
563
 
        self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
564
 
        self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
565
 
 
566
 
        # Now remove them again, and make sure that after a
567
 
        # commit, they are still marked correctly
568
 
        os.remove('b1/a')
569
 
        os.remove('b1/b')
570
 
        wt.commit('removed', rev_id='r2')
571
 
 
572
 
        self.assertEqual([], [cn for cn,ie in wt.inventory.iter_entries()])
573
 
        self.failIf(wt.has_id(a_id))
574
 
        self.failIf(wt.has_filename('a'))
575
 
        self.failIf(wt.has_id(b_id))
576
 
        self.failIf(wt.has_filename('b'))
577
 
 
578
 
        # Now revert back to the previous commit
579
 
        wt.revert([], rev_tree, backups=False)
580
 
        self.assertEqual(['a', 'b'], [cn for cn,ie in wt.inventory.iter_entries()])
581
 
 
582
 
        self.failUnless(wt.is_executable(a_id), "'a' lost the execute bit")
583
 
        self.failIf(wt.is_executable(b_id), "'b' gained an execute bit")
584
 
 
585
 
        # Now make sure that 'bzr branch' also preserves the
586
 
        # executable bit
587
 
        # TODO: Maybe this should be a blackbox test
588
 
        d2 = b.bzrdir.clone('b2', revision_id='r1')
589
 
        t2 = d2.open_workingtree()
590
 
        b2 = t2.branch
591
 
        self.assertEquals('r1', b2.last_revision())
592
 
 
593
 
        self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
594
 
        self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
595
 
        self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
596
 
 
597
 
        # Make sure pull will delete the files
598
 
        t2.pull(b)
599
 
        self.assertEquals('r2', b2.last_revision())
600
 
        self.assertEqual([], [cn for cn,ie in t2.inventory.iter_entries()])
601
 
 
602
 
        # Now commit the changes on the first branch
603
 
        # so that the second branch can pull the changes
604
 
        # and make sure that the executable bit has been copied
605
 
        wt.commit('resurrected', rev_id='r3')
606
 
 
607
 
        t2.pull(b)
608
 
        self.assertEquals('r3', b2.last_revision())
609
 
        self.assertEqual(['a', 'b'], [cn for cn,ie in t2.inventory.iter_entries()])
610
 
 
611
 
        self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
612
 
        self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
613
 
 
614
 
 
615
534
class TestRevert(TestCaseWithTransport):
616
535
 
617
536
    def test_dangling_id(self):