~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Vincent Ladeuil
  • Date: 2012-02-14 17:22:37 UTC
  • mfrom: (6466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120214172237-7dv7er3n4uy8d5m4
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    pathjoin,
61
61
)
62
62
from bzrlib.merge import Merge3Merger, Merger
 
63
from bzrlib.mutabletree import MutableTree
63
64
from bzrlib.tests import (
64
65
    features,
65
66
    TestCaseInTempDir,
87
88
 
88
89
    def setUp(self):
89
90
        super(TestTreeTransform, self).setUp()
90
 
        self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
 
91
        self.wt = self.make_branch_and_tree('.', format='development-subtree')
91
92
        os.chdir('..')
92
93
 
93
94
    def get_transform(self):
398
399
        tree.lock_read()
399
400
        self.addCleanup(tree.unlock)
400
401
        self.assertEqual('subtree-revision',
401
 
                         tree.inventory['subtree-id'].reference_revision)
 
402
                         tree.root_inventory['subtree-id'].reference_revision)
402
403
 
403
404
    def test_conflicts(self):
404
405
        transform, root = self.get_transform()
1531
1532
        self.assertPathExists("foo/bar")
1532
1533
        wt.lock_read()
1533
1534
        try:
1534
 
            self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1535
 
                    "directory")
 
1535
            self.assertEqual(wt.kind(wt.path2id("foo")), "directory")
1536
1536
        finally:
1537
1537
            wt.unlock()
1538
1538
        wt.commit("two")
1554
1554
        self.assertPathExists("foo")
1555
1555
        wt.lock_read()
1556
1556
        self.addCleanup(wt.unlock)
1557
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1558
 
                "symlink")
 
1557
        self.assertEqual(wt.kind(wt.path2id("foo")), "symlink")
1559
1558
 
1560
1559
    def test_dir_to_file(self):
1561
1560
        wt = self.make_branch_and_tree('.')
1573
1572
        self.assertPathExists("foo")
1574
1573
        wt.lock_read()
1575
1574
        self.addCleanup(wt.unlock)
1576
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1577
 
                "file")
 
1575
        self.assertEqual(wt.kind(wt.path2id("foo")), "file")
1578
1576
 
1579
1577
    def test_dir_to_hardlink(self):
1580
1578
        self.requireFeature(HardlinkFeature)
1595
1593
        self.assertPathExists("baz")
1596
1594
        wt.lock_read()
1597
1595
        self.addCleanup(wt.unlock)
1598
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1599
 
                "file")
 
1596
        self.assertEqual(wt.kind(wt.path2id("foo")), "file")
1600
1597
 
1601
1598
    def test_no_final_path(self):
1602
1599
        transform, root = self.get_transform()
1764
1761
        merge_modified = this.wt.merge_modified()
1765
1762
        self.assertSubset(merge_modified, modified)
1766
1763
        self.assertEqual(len(merge_modified), len(modified))
1767
 
        file(this.wt.id2abspath('a'), 'wb').write('booga')
 
1764
        with file(this.wt.id2abspath('a'), 'wb') as f: f.write('booga')
1768
1765
        modified.pop(0)
1769
1766
        merge_modified = this.wt.merge_modified()
1770
1767
        self.assertSubset(merge_modified, modified)
1886
1883
        os.mkdir('a')
1887
1884
        a = BzrDir.create_standalone_workingtree('a')
1888
1885
        os.mkdir('a/foo')
1889
 
        file('a/foo/bar', 'wb').write('contents')
 
1886
        with file('a/foo/bar', 'wb') as f: f.write('contents')
1890
1887
        os.symlink('a/foo/bar', 'a/foo/baz')
1891
1888
        a.add(['foo', 'foo/bar', 'foo/baz'])
1892
1889
        a.commit('initial commit')
1901
1898
 
1902
1899
    def test_build_with_references(self):
1903
1900
        tree = self.make_branch_and_tree('source',
1904
 
            format='dirstate-with-subtree')
 
1901
            format='development-subtree')
1905
1902
        subtree = self.make_branch_and_tree('source/subtree',
1906
 
            format='dirstate-with-subtree')
 
1903
            format='development-subtree')
1907
1904
        tree.add_reference(subtree)
1908
1905
        tree.commit('a revision')
1909
1906
        tree.branch.create_checkout('target')
2795
2792
 
2796
2793
    def test_iter_changes(self):
2797
2794
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2798
 
        root = revision_tree.inventory.root.file_id
 
2795
        root = revision_tree.get_root_id()
2799
2796
        self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
2800
2797
                          (root, root), ('a', 'a'), ('file', 'file'),
2801
2798
                          (False, False))],
2805
2802
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2806
2803
        changes = preview_tree.iter_changes(revision_tree,
2807
2804
                                            include_unchanged=True)
2808
 
        root = revision_tree.inventory.root.file_id
 
2805
        root = revision_tree.get_root_id()
2809
2806
 
2810
2807
        self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
2811
2808
 
3637
3634
        self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3638
3635
 
3639
3636
    def _set_orphan_policy(self, wt, policy):
3640
 
        wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
 
3637
        wt.branch.get_config_stack().set('bzr.transform.orphan_policy',
3641
3638
                                               policy)
3642
3639
 
3643
3640
    def _prepare_orphan(self, wt):
3716
3713
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3717
3714
                         remaining_conflicts.pop())
3718
3715
        self.assertLength(1, warnings)
3719
 
        self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')
 
3716
        self.assertStartsWith(warnings[0], 'Value "donttouchmypreciouuus" ')
 
3717
 
 
3718
 
 
3719
class TestTransformHooks(tests.TestCaseWithTransport):
 
3720
 
 
3721
    def setUp(self):
 
3722
        super(TestTransformHooks, self).setUp()
 
3723
        self.wt = self.make_branch_and_tree('.')
 
3724
        os.chdir('..')
 
3725
 
 
3726
    def get_transform(self):
 
3727
        transform = TreeTransform(self.wt)
 
3728
        self.addCleanup(transform.finalize)
 
3729
        return transform, transform.root
 
3730
 
 
3731
    def test_pre_commit_hooks(self):
 
3732
        calls = []
 
3733
        def record_pre_transform(tree, tt):
 
3734
            calls.append((tree, tt))
 
3735
        MutableTree.hooks.install_named_hook('pre_transform',
 
3736
            record_pre_transform, "Pre transform")
 
3737
        transform, root = self.get_transform()
 
3738
        old_root_id = transform.tree_file_id(root)
 
3739
        transform.apply()
 
3740
        self.assertEqual(old_root_id, self.wt.get_root_id())
 
3741
        self.assertEquals([(self.wt, transform)], calls)
 
3742
 
 
3743
    def test_post_commit_hooks(self):
 
3744
        calls = []
 
3745
        def record_post_transform(tree, tt):
 
3746
            calls.append((tree, tt))
 
3747
        MutableTree.hooks.install_named_hook('post_transform',
 
3748
            record_post_transform, "Post transform")
 
3749
        transform, root = self.get_transform()
 
3750
        old_root_id = transform.tree_file_id(root)
 
3751
        transform.apply()
 
3752
        self.assertEqual(old_root_id, self.wt.get_root_id())
 
3753
        self.assertEquals([(self.wt, transform)], calls)