~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-28 07:08:42 UTC
  • mfrom: (2380 +trunk)
  • mto: (2018.5.146 hpss)
  • mto: This revision was merged to the branch mainline in revision 2414.
  • Revision ID: andrew.bennetts@canonical.com-20070328070842-r843houy668oxb9o
Merge from bzr.dev.

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.
587
598
        bar1_abspath = self.wt.abspath('bar')
588
599
        self.assertEqual([bar1_abspath], stat_paths)
589
600
 
 
601
    def test_iter_changes(self):
 
602
        self.wt.set_root_id('eert_toor')
 
603
        transform, root = self.get_transform()
 
604
        transform.new_file('old', root, 'blah', 'id-1', True)
 
605
        transform.apply()
 
606
        transform, root = self.get_transform()
 
607
        try:
 
608
            self.assertEqual([], list(transform._iter_changes()))
 
609
            old = transform.trans_id_tree_file_id('id-1')
 
610
            transform.unversion_file(old)
 
611
            self.assertEqual([('id-1', ('old', None), False, (True, False),
 
612
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
 
613
                (True, True))], list(transform._iter_changes()))
 
614
            transform.new_directory('new', root, 'id-1')
 
615
            self.assertEqual([('id-1', ('old', 'new'), True, (True, True),
 
616
                ('eert_toor', 'eert_toor'), ('old', 'new'),
 
617
                ('file', 'directory'),
 
618
                (True, False))], list(transform._iter_changes()))
 
619
        finally:
 
620
            transform.finalize()
 
621
 
 
622
    def test_iter_changes_new(self):
 
623
        self.wt.set_root_id('eert_toor')
 
624
        transform, root = self.get_transform()
 
625
        transform.new_file('old', root, 'blah')
 
626
        transform.apply()
 
627
        transform, root = self.get_transform()
 
628
        try:
 
629
            old = transform.trans_id_tree_path('old')
 
630
            transform.version_file('id-1', old)
 
631
            self.assertEqual([('id-1', (None, 'old'), False, (False, True),
 
632
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
 
633
                (False, False))], list(transform._iter_changes()))
 
634
        finally:
 
635
            transform.finalize()
 
636
 
 
637
    def test_iter_changes_modifications(self):
 
638
        self.wt.set_root_id('eert_toor')
 
639
        transform, root = self.get_transform()
 
640
        transform.new_file('old', root, 'blah', 'id-1')
 
641
        transform.new_file('new', root, 'blah')
 
642
        transform.new_directory('subdir', root, 'subdir-id')
 
643
        transform.apply()
 
644
        transform, root = self.get_transform()
 
645
        try:
 
646
            old = transform.trans_id_tree_path('old')
 
647
            subdir = transform.trans_id_tree_file_id('subdir-id')
 
648
            new = transform.trans_id_tree_path('new')
 
649
            self.assertEqual([], list(transform._iter_changes()))
 
650
 
 
651
            #content deletion
 
652
            transform.delete_contents(old)
 
653
            self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
 
654
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', None),
 
655
                (False, False))], list(transform._iter_changes()))
 
656
 
 
657
            #content change
 
658
            transform.create_file('blah', old)
 
659
            self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
 
660
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
 
661
                (False, False))], list(transform._iter_changes()))
 
662
            transform.cancel_deletion(old)
 
663
            self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
 
664
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
 
665
                (False, False))], list(transform._iter_changes()))
 
666
            transform.cancel_creation(old)
 
667
 
 
668
            # move file_id to a different file
 
669
            self.assertEqual([], list(transform._iter_changes()))
 
670
            transform.unversion_file(old)
 
671
            transform.version_file('id-1', new)
 
672
            transform.adjust_path('old', root, new)
 
673
            self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
 
674
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
 
675
                (False, False))], list(transform._iter_changes()))
 
676
            transform.cancel_versioning(new)
 
677
            transform._removed_id = set()
 
678
 
 
679
            #execute bit
 
680
            self.assertEqual([], list(transform._iter_changes()))
 
681
            transform.set_executability(True, old)
 
682
            self.assertEqual([('id-1', ('old', 'old'), False, (True, True),
 
683
                ('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
 
684
                (False, True))], list(transform._iter_changes()))
 
685
            transform.set_executability(None, old)
 
686
 
 
687
            # filename
 
688
            self.assertEqual([], list(transform._iter_changes()))
 
689
            transform.adjust_path('new', root, old)
 
690
            transform._new_parent = {}
 
691
            self.assertEqual([('id-1', ('old', 'new'), False, (True, True),
 
692
                ('eert_toor', 'eert_toor'), ('old', 'new'), ('file', 'file'),
 
693
                (False, False))], list(transform._iter_changes()))
 
694
            transform._new_name = {}
 
695
 
 
696
            # parent directory
 
697
            self.assertEqual([], list(transform._iter_changes()))
 
698
            transform.adjust_path('new', subdir, old)
 
699
            transform._new_name = {}
 
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()))
 
704
            transform._new_path = {}
 
705
 
 
706
        finally:
 
707
            transform.finalize()
 
708
 
 
709
    def test_iter_changes_modified_bleed(self):
 
710
        self.wt.set_root_id('eert_toor')
 
711
        """Modified flag should not bleed from one change to another"""
 
712
        # unfortunately, we have no guarantee that file1 (which is modified)
 
713
        # will be applied before file2.  And if it's applied after file2, it
 
714
        # obviously can't bleed into file2's change output.  But for now, it
 
715
        # works.
 
716
        transform, root = self.get_transform()
 
717
        transform.new_file('file1', root, 'blah', 'id-1')
 
718
        transform.new_file('file2', root, 'blah', 'id-2')
 
719
        transform.apply()
 
720
        transform, root = self.get_transform()
 
721
        try:
 
722
            transform.delete_contents(transform.trans_id_file_id('id-1'))
 
723
            transform.set_executability(True,
 
724
            transform.trans_id_file_id('id-2'))
 
725
            self.assertEqual([('id-1', (u'file1', u'file1'), True, (True, True),
 
726
                ('eert_toor', 'eert_toor'), ('file1', u'file1'),
 
727
                ('file', None), (False, False)),
 
728
                ('id-2', (u'file2', u'file2'), False, (True, True),
 
729
                ('eert_toor', 'eert_toor'), ('file2', u'file2'),
 
730
                ('file', 'file'), (False, True))],
 
731
                list(transform._iter_changes()))
 
732
        finally:
 
733
            transform.finalize()
 
734
 
 
735
    def test_iter_changes_move_missing(self):
 
736
        """Test moving ids with no files around"""
 
737
        self.wt.set_root_id('toor_eert')
 
738
        # Need two steps because versioning a non-existant file is a conflict.
 
739
        transform, root = self.get_transform()
 
740
        transform.new_directory('floater', root, 'floater-id')
 
741
        transform.apply()
 
742
        transform, root = self.get_transform()
 
743
        transform.delete_contents(transform.trans_id_tree_path('floater'))
 
744
        transform.apply()
 
745
        transform, root = self.get_transform()
 
746
        floater = transform.trans_id_tree_path('floater')
 
747
        try:
 
748
            transform.adjust_path('flitter', root, floater)
 
749
            self.assertEqual([('floater-id', ('floater', 'flitter'), False,
 
750
            (True, True), ('toor_eert', 'toor_eert'), ('floater', 'flitter'),
 
751
            (None, None), (False, False))], list(transform._iter_changes()))
 
752
        finally:
 
753
            transform.finalize()
 
754
 
 
755
    def test_iter_changes_pointless(self):
 
756
        """Ensure that no-ops are not treated as modifications"""
 
757
        self.wt.set_root_id('eert_toor')
 
758
        transform, root = self.get_transform()
 
759
        transform.new_file('old', root, 'blah', 'id-1')
 
760
        transform.new_directory('subdir', root, 'subdir-id')
 
761
        transform.apply()
 
762
        transform, root = self.get_transform()
 
763
        try:
 
764
            old = transform.trans_id_tree_path('old')
 
765
            subdir = transform.trans_id_tree_file_id('subdir-id')
 
766
            self.assertEqual([], list(transform._iter_changes()))
 
767
            transform.delete_contents(subdir)
 
768
            transform.create_directory(subdir)
 
769
            transform.set_executability(False, old)
 
770
            transform.unversion_file(old)
 
771
            transform.version_file('id-1', old)
 
772
            transform.adjust_path('old', root, old)
 
773
            self.assertEqual([], list(transform._iter_changes()))
 
774
        finally:
 
775
            transform.finalize()
590
776
 
591
777
class TransformGroup(object):
592
778
    def __init__(self, dirname, root_id):
598
784
        self.tt = TreeTransform(self.wt)
599
785
        self.root = self.tt.trans_id_tree_file_id(self.wt.get_root_id())
600
786
 
 
787
 
601
788
def conflict_text(tree, merge):
602
789
    template = '%s TREE\n%s%s\n%s%s MERGE-SOURCE\n'
603
790
    return template % ('<' * 7, tree, '=' * 7, merge, '>' * 7)
802
989
        a.add(['foo', 'foo/bar', 'foo/baz'])
803
990
        a.commit('initial commit')
804
991
        b = BzrDir.create_standalone_workingtree('b')
805
 
        build_tree(a.basis_tree(), b)
 
992
        basis = a.basis_tree()
 
993
        basis.lock_read()
 
994
        self.addCleanup(basis.unlock)
 
995
        build_tree(basis, b)
806
996
        self.assertIs(os.path.isdir('b/foo'), True)
807
997
        self.assertEqual(file('b/foo/bar', 'rb').read(), "contents")
808
998
        self.assertEqual(os.readlink('b/foo/baz'), 'a/foo/bar')
809
999
 
 
1000
    def test_build_with_references(self):
 
1001
        tree = self.make_branch_and_tree('source',
 
1002
            format='dirstate-with-subtree')
 
1003
        subtree = self.make_branch_and_tree('source/subtree',
 
1004
            format='dirstate-with-subtree')
 
1005
        tree.add_reference(subtree)
 
1006
        tree.commit('a revision')
 
1007
        tree.branch.create_checkout('target')
 
1008
        self.failUnlessExists('target')
 
1009
        self.failUnlessExists('target/subtree')
 
1010
 
810
1011
    def test_file_conflict_handling(self):
811
1012
        """Ensure that when building trees, conflict handling is done"""
812
1013
        source = self.make_branch_and_tree('source')