~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-07 10:45:44 UTC
  • mfrom: (2321.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070307104544-59e3e6358e4bdb29
(robertc) Merge dirstate and subtrees. (Robert Collins, Martin Pool, Aaaron Bentley, John A Meinel, James Westby)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib import (
22
22
    errors,
23
23
    generate_ids,
 
24
    symbol_versioning,
24
25
    tests,
25
26
    urlutils,
26
27
    )
39
40
                              find_interesting, build_tree, get_backup_name)
40
41
 
41
42
 
42
 
class TestTreeTransform(TestCaseInTempDir):
 
43
class TestTreeTransform(tests.TestCaseWithTransport):
43
44
 
44
45
    def setUp(self):
45
46
        super(TestTreeTransform, self).setUp()
46
 
        self.wt = BzrDir.create_standalone_workingtree('.')
 
47
        self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
47
48
        os.chdir('..')
48
49
 
49
50
    def get_transform(self):
126
127
        self.assertEqual(self.wt.path2id('oz/dorothy'), 'dorothy-id')
127
128
        self.assertEqual(self.wt.path2id('oz/dorothy/toto'), 'toto-id')
128
129
 
129
 
        self.assertEqual('toto-contents', 
 
130
        self.assertEqual('toto-contents',
130
131
                         self.wt.get_file_byname('oz/dorothy/toto').read())
131
132
        self.assertIs(self.wt.is_executable('toto-id'), False)
132
133
 
 
134
    def test_tree_reference(self):
 
135
        transform, root = self.get_transform()
 
136
        tree = transform._tree
 
137
        trans_id = transform.new_directory('reference', root, 'subtree-id')
 
138
        transform.set_tree_reference('subtree-revision', trans_id)
 
139
        transform.apply()
 
140
        tree.lock_read()
 
141
        self.addCleanup(tree.unlock)
 
142
        self.assertEqual('subtree-revision',
 
143
                         tree.inventory['subtree-id'].reference_revision)
 
144
 
133
145
    def test_conflicts(self):
134
146
        transform, root = self.get_transform()
135
147
        trans_id = transform.new_file('name', root, 'contents', 
516
528
        create.new_file('vfile', root, 'myfile-text', 'myfile-id')
517
529
        create.new_file('uvfile', root, 'othertext')
518
530
        create.apply()
519
 
        self.assertEqual(find_interesting(wt, wt, ['vfile']),
520
 
                         set(['myfile-id']))
521
 
        self.assertRaises(PathsNotVersionedError, find_interesting, wt, wt,
522
 
                          ['uvfile'])
 
531
        result = self.applyDeprecated(symbol_versioning.zero_fifteen,
 
532
            find_interesting, wt, wt, ['vfile'])
 
533
        self.assertEqual(result, set(['myfile-id']))
523
534
 
524
535
    def test_set_executability_order(self):
525
536
        """Ensure that executability behaves the same, no matter what order.
588
599
        self.assertEqual([bar1_abspath], stat_paths)
589
600
 
590
601
    def test_iter_changes(self):
 
602
        self.wt.set_root_id('eert_toor')
591
603
        transform, root = self.get_transform()
592
604
        transform.new_file('old', root, 'blah', 'id-1', True)
593
605
        transform.apply()
596
608
            self.assertEqual([], list(transform._iter_changes()))
597
609
            old = transform.trans_id_tree_file_id('id-1')
598
610
            transform.unversion_file(old)
599
 
            self.assertEqual([('id-1', 'old', False, (True, False),
600
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'old'), ('file', 'file'),
 
611
            self.assertEqual([('id-1', ('old', None), False, (True, False),
 
612
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
601
613
                (True, True))], list(transform._iter_changes()))
602
614
            transform.new_directory('new', root, 'id-1')
603
 
            self.assertEqual([('id-1', 'new', True, (True, True),
604
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'new'),
 
615
            self.assertEqual([('id-1', ('old', 'new'), True, (True, True),
 
616
                ('eert_toor', 'eert_toor'), ('old', 'new'),
605
617
                ('file', 'directory'),
606
618
                (True, False))], list(transform._iter_changes()))
607
619
        finally:
608
620
            transform.finalize()
609
621
 
610
622
    def test_iter_changes_new(self):
 
623
        self.wt.set_root_id('eert_toor')
611
624
        transform, root = self.get_transform()
612
625
        transform.new_file('old', root, 'blah')
613
626
        transform.apply()
615
628
        try:
616
629
            old = transform.trans_id_tree_path('old')
617
630
            transform.version_file('id-1', old)
618
 
            self.assertEqual([('id-1', 'old', False, (False, True),
619
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'old'), ('file', 'file'),
 
631
            self.assertEqual([('id-1', (None, 'old'), False, (False, True),
 
632
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
620
633
                (False, False))], list(transform._iter_changes()))
621
634
        finally:
622
635
            transform.finalize()
623
636
 
624
637
    def test_iter_changes_modifications(self):
 
638
        self.wt.set_root_id('eert_toor')
625
639
        transform, root = self.get_transform()
626
640
        transform.new_file('old', root, 'blah', 'id-1')
627
641
        transform.new_file('new', root, 'blah')
636
650
 
637
651
            #content deletion
638
652
            transform.delete_contents(old)
639
 
            self.assertEqual([('id-1', 'old', True, (True, True),
640
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'old'), ('file', None),
 
653
            self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
 
654
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', None),
641
655
                (False, False))], list(transform._iter_changes()))
642
656
 
643
657
            #content change
644
658
            transform.create_file('blah', old)
645
 
            self.assertEqual([('id-1', 'old', True, (True, True),
646
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'old'), ('file', 'file'),
 
659
            self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
 
660
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
647
661
                (False, False))], list(transform._iter_changes()))
648
662
            transform.cancel_deletion(old)
649
 
            self.assertEqual([('id-1', 'old', True, (True, True),
650
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'old'), ('file', 'file'),
 
663
            self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
 
664
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
651
665
                (False, False))], list(transform._iter_changes()))
652
666
            transform.cancel_creation(old)
653
667
 
656
670
            transform.unversion_file(old)
657
671
            transform.version_file('id-1', new)
658
672
            transform.adjust_path('old', root, new)
659
 
            self.assertEqual([('id-1', 'old', True, (True, True),
660
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'old'), ('file', 'file'),
 
673
            self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
 
674
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
661
675
                (False, False))], list(transform._iter_changes()))
662
676
            transform.cancel_versioning(new)
663
677
            transform._removed_id = set()
665
679
            #execute bit
666
680
            self.assertEqual([], list(transform._iter_changes()))
667
681
            transform.set_executability(True, old)
668
 
            self.assertEqual([('id-1', 'old', False, (True, True),
669
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'old'), ('file', 'file'),
 
682
            self.assertEqual([('id-1', ('old', 'old'), False, (True, True),
 
683
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
670
684
                (False, True))], list(transform._iter_changes()))
671
685
            transform.set_executability(None, old)
672
686
 
674
688
            self.assertEqual([], list(transform._iter_changes()))
675
689
            transform.adjust_path('new', root, old)
676
690
            transform._new_parent = {}
677
 
            self.assertEqual([('id-1', 'new', False, (True, True),
678
 
                ('TREE_ROOT', 'TREE_ROOT'), ('old', 'new'), ('file', 'file'),
 
691
            self.assertEqual([('id-1', ('old', 'new'), False, (True, True),
 
692
                ('eert_toor', 'eert_toor'), ('old', 'new'), ('file', 'file'),
679
693
                (False, False))], list(transform._iter_changes()))
680
694
            transform._new_name = {}
681
695
 
683
697
            self.assertEqual([], list(transform._iter_changes()))
684
698
            transform.adjust_path('new', subdir, old)
685
699
            transform._new_name = {}
686
 
            self.assertEqual([('id-1', 'subdir/old', False, (True, True),
687
 
                ('TREE_ROOT', 'subdir-id'), ('old', 'old'), ('file', 'file'),
688
 
                (False, False))], list(transform._iter_changes()))
 
700
            self.assertEqual([('id-1', ('old', 'subdir/old'), False,
 
701
                (True, True), ('eert_toor', 'subdir-id'), ('old', 'old'),
 
702
                ('file', 'file'), (False, False))],
 
703
                list(transform._iter_changes()))
689
704
            transform._new_path = {}
690
705
 
691
706
        finally:
692
707
            transform.finalize()
693
708
 
694
709
    def test_iter_changes_modified_bleed(self):
 
710
        self.wt.set_root_id('eert_toor')
695
711
        """Modified flag should not bleed from one change to another"""
696
712
        # unfortunately, we have no guarantee that file1 (which is modified)
697
713
        # will be applied before file2.  And if it's applied after file2, it
706
722
            transform.delete_contents(transform.trans_id_file_id('id-1'))
707
723
            transform.set_executability(True,
708
724
            transform.trans_id_file_id('id-2'))
709
 
            self.assertEqual([('id-1', u'file1', True, (True, True),
710
 
                ('TREE_ROOT', 'TREE_ROOT'), ('file1', u'file1'),
 
725
            self.assertEqual([('id-1', (u'file1', u'file1'), True, (True, True),
 
726
                ('eert_toor', 'eert_toor'), ('file1', u'file1'),
711
727
                ('file', None), (False, False)),
712
 
                ('id-2', u'file2', False, (True, True),
713
 
                ('TREE_ROOT', 'TREE_ROOT'), ('file2', u'file2'),
 
728
                ('id-2', (u'file2', u'file2'), False, (True, True),
 
729
                ('eert_toor', 'eert_toor'), ('file2', u'file2'),
714
730
                ('file', 'file'), (False, True))],
715
731
                list(transform._iter_changes()))
716
732
        finally:
718
734
 
719
735
    def test_iter_changes_pointless(self):
720
736
        """Ensure that no-ops are not treated as modifications"""
 
737
        self.wt.set_root_id('eert_toor')
721
738
        transform, root = self.get_transform()
722
739
        transform.new_file('old', root, 'blah', 'id-1')
723
740
        transform.new_directory('subdir', root, 'subdir-id')
952
969
        a.add(['foo', 'foo/bar', 'foo/baz'])
953
970
        a.commit('initial commit')
954
971
        b = BzrDir.create_standalone_workingtree('b')
955
 
        build_tree(a.basis_tree(), b)
 
972
        basis = a.basis_tree()
 
973
        basis.lock_read()
 
974
        self.addCleanup(basis.unlock)
 
975
        build_tree(basis, b)
956
976
        self.assertIs(os.path.isdir('b/foo'), True)
957
977
        self.assertEqual(file('b/foo/bar', 'rb').read(), "contents")
958
978
        self.assertEqual(os.readlink('b/foo/baz'), 'a/foo/bar')
959
979
 
 
980
    def test_build_with_references(self):
 
981
        tree = self.make_branch_and_tree('source',
 
982
            format='dirstate-with-subtree')
 
983
        subtree = self.make_branch_and_tree('source/subtree',
 
984
            format='dirstate-with-subtree')
 
985
        tree.add_reference(subtree)
 
986
        tree.commit('a revision')
 
987
        tree.branch.create_checkout('target')
 
988
        self.failUnlessExists('target')
 
989
        self.failUnlessExists('target/subtree')
 
990
 
960
991
    def test_file_conflict_handling(self):
961
992
        """Ensure that when building trees, conflict handling is done"""
962
993
        source = self.make_branch_and_tree('source')