~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-03-13 17:25:29 UTC
  • mfrom: (6499 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6501.
  • Revision ID: v.ladeuil+lp@free.fr-20120313172529-i0suyjnepsor25i7
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    transform,
35
35
    urlutils,
36
36
    )
37
 
from bzrlib.bzrdir import BzrDir
38
37
from bzrlib.conflicts import (
39
38
    DeletingParent,
40
39
    DuplicateEntry,
44
43
    ParentLoop,
45
44
    UnversionedParent,
46
45
)
 
46
from bzrlib.controldir import ControlDir
47
47
from bzrlib.diff import show_diff_trees
48
48
from bzrlib.errors import (
49
49
    DuplicateKey,
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,
 
66
    TestCaseInTempDir,
 
67
    TestSkipped,
 
68
    )
 
69
from bzrlib.tests.features import (
65
70
    HardlinkFeature,
66
71
    SymlinkFeature,
67
 
    TestCaseInTempDir,
68
 
    TestSkipped,
69
 
)
 
72
    )
70
73
from bzrlib.transform import (
71
74
    build_tree,
72
75
    create_from_tree,
85
88
 
86
89
    def setUp(self):
87
90
        super(TestTreeTransform, self).setUp()
88
 
        self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
 
91
        self.wt = self.make_branch_and_tree('.', format='development-subtree')
89
92
        os.chdir('..')
90
93
 
91
94
    def get_transform(self):
396
399
        tree.lock_read()
397
400
        self.addCleanup(tree.unlock)
398
401
        self.assertEqual('subtree-revision',
399
 
                         tree.inventory['subtree-id'].reference_revision)
 
402
                         tree.root_inventory['subtree-id'].reference_revision)
400
403
 
401
404
    def test_conflicts(self):
402
405
        transform, root = self.get_transform()
779
782
                            'wizard2', 'behind_curtain')
780
783
 
781
784
    def test_symlinks_unicode(self):
782
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
785
        self.requireFeature(features.UnicodeFilenameFeature)
783
786
        self._test_symlinks(u'\N{Euro Sign}wizard',
784
787
                            u'wizard-targ\N{Euro Sign}t',
785
788
                            u'\N{Euro Sign}wizard2',
1474
1477
        # The rename will fail because the target directory is not empty (but
1475
1478
        # raises FileExists anyway).
1476
1479
        err = self.assertRaises(errors.FileExists, tt_helper)
1477
 
        self.assertContainsRe(str(err),
1478
 
            "^File exists: .+/baz")
 
1480
        self.assertEndsWith(err.path, "/baz")
1479
1481
 
1480
1482
    def test_two_directories_clash(self):
1481
1483
        def tt_helper():
1493
1495
                wt.unlock()
1494
1496
                raise
1495
1497
        err = self.assertRaises(errors.FileExists, tt_helper)
1496
 
        self.assertContainsRe(str(err),
1497
 
            "^File exists: .+/foo")
 
1498
        self.assertEndsWith(err.path, "/foo")
1498
1499
 
1499
1500
    def test_two_directories_clash_finalize(self):
1500
1501
        def tt_helper():
1512
1513
                tt.finalize()
1513
1514
                raise
1514
1515
        err = self.assertRaises(errors.FileExists, tt_helper)
1515
 
        self.assertContainsRe(str(err),
1516
 
            "^File exists: .+/foo")
 
1516
        self.assertEndsWith(err.path, "/foo")
1517
1517
 
1518
1518
    def test_file_to_directory(self):
1519
1519
        wt = self.make_branch_and_tree('.')
1532
1532
        self.assertPathExists("foo/bar")
1533
1533
        wt.lock_read()
1534
1534
        try:
1535
 
            self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1536
 
                    "directory")
 
1535
            self.assertEqual(wt.kind(wt.path2id("foo")), "directory")
1537
1536
        finally:
1538
1537
            wt.unlock()
1539
1538
        wt.commit("two")
1555
1554
        self.assertPathExists("foo")
1556
1555
        wt.lock_read()
1557
1556
        self.addCleanup(wt.unlock)
1558
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1559
 
                "symlink")
 
1557
        self.assertEqual(wt.kind(wt.path2id("foo")), "symlink")
1560
1558
 
1561
1559
    def test_dir_to_file(self):
1562
1560
        wt = self.make_branch_and_tree('.')
1574
1572
        self.assertPathExists("foo")
1575
1573
        wt.lock_read()
1576
1574
        self.addCleanup(wt.unlock)
1577
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1578
 
                "file")
 
1575
        self.assertEqual(wt.kind(wt.path2id("foo")), "file")
1579
1576
 
1580
1577
    def test_dir_to_hardlink(self):
1581
1578
        self.requireFeature(HardlinkFeature)
1596
1593
        self.assertPathExists("baz")
1597
1594
        wt.lock_read()
1598
1595
        self.addCleanup(wt.unlock)
1599
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1600
 
                "file")
 
1596
        self.assertEqual(wt.kind(wt.path2id("foo")), "file")
1601
1597
 
1602
1598
    def test_no_final_path(self):
1603
1599
        transform, root = self.get_transform()
1649
1645
    def __init__(self, dirname, root_id):
1650
1646
        self.name = dirname
1651
1647
        os.mkdir(dirname)
1652
 
        self.wt = BzrDir.create_standalone_workingtree(dirname)
 
1648
        self.wt = ControlDir.create_standalone_workingtree(dirname)
1653
1649
        self.wt.set_root_id(root_id)
1654
1650
        self.b = self.wt.branch
1655
1651
        self.tt = TreeTransform(self.wt)
1765
1761
        merge_modified = this.wt.merge_modified()
1766
1762
        self.assertSubset(merge_modified, modified)
1767
1763
        self.assertEqual(len(merge_modified), len(modified))
1768
 
        file(this.wt.id2abspath('a'), 'wb').write('booga')
 
1764
        with file(this.wt.id2abspath('a'), 'wb') as f: f.write('booga')
1769
1765
        modified.pop(0)
1770
1766
        merge_modified = this.wt.merge_modified()
1771
1767
        self.assertSubset(merge_modified, modified)
1885
1881
    def test_build_tree_with_symlinks(self):
1886
1882
        self.requireFeature(SymlinkFeature)
1887
1883
        os.mkdir('a')
1888
 
        a = BzrDir.create_standalone_workingtree('a')
 
1884
        a = ControlDir.create_standalone_workingtree('a')
1889
1885
        os.mkdir('a/foo')
1890
 
        file('a/foo/bar', 'wb').write('contents')
 
1886
        with file('a/foo/bar', 'wb') as f: f.write('contents')
1891
1887
        os.symlink('a/foo/bar', 'a/foo/baz')
1892
1888
        a.add(['foo', 'foo/bar', 'foo/baz'])
1893
1889
        a.commit('initial commit')
1894
 
        b = BzrDir.create_standalone_workingtree('b')
 
1890
        b = ControlDir.create_standalone_workingtree('b')
1895
1891
        basis = a.basis_tree()
1896
1892
        basis.lock_read()
1897
1893
        self.addCleanup(basis.unlock)
1902
1898
 
1903
1899
    def test_build_with_references(self):
1904
1900
        tree = self.make_branch_and_tree('source',
1905
 
            format='dirstate-with-subtree')
 
1901
            format='development-subtree')
1906
1902
        subtree = self.make_branch_and_tree('source/subtree',
1907
 
            format='dirstate-with-subtree')
 
1903
            format='development-subtree')
1908
1904
        tree.add_reference(subtree)
1909
1905
        tree.commit('a revision')
1910
1906
        tree.branch.create_checkout('target')
2224
2220
        self.assertEqualStat(source_stat, target_stat)
2225
2221
 
2226
2222
    def test_case_insensitive_build_tree_inventory(self):
2227
 
        if (tests.CaseInsensitiveFilesystemFeature.available()
2228
 
            or tests.CaseInsCasePresFilenameFeature.available()):
 
2223
        if (features.CaseInsensitiveFilesystemFeature.available()
 
2224
            or features.CaseInsCasePresFilenameFeature.available()):
2229
2225
            raise tests.UnavailableFeature('Fully case sensitive filesystem')
2230
2226
        source = self.make_branch_and_tree('source')
2231
2227
        self.build_tree(['source/file', 'source/FILE'])
2796
2792
 
2797
2793
    def test_iter_changes(self):
2798
2794
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2799
 
        root = revision_tree.inventory.root.file_id
 
2795
        root = revision_tree.get_root_id()
2800
2796
        self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
2801
2797
                          (root, root), ('a', 'a'), ('file', 'file'),
2802
2798
                          (False, False))],
2806
2802
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2807
2803
        changes = preview_tree.iter_changes(revision_tree,
2808
2804
                                            include_unchanged=True)
2809
 
        root = revision_tree.inventory.root.file_id
 
2805
        root = revision_tree.get_root_id()
2810
2806
 
2811
2807
        self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
2812
2808
 
3344
3340
        self.assertEqual('contents', rev2_tree.get_file_text('file_id'))
3345
3341
 
3346
3342
    def test_ascii_limbo_paths(self):
3347
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
3343
        self.requireFeature(features.UnicodeFilenameFeature)
3348
3344
        branch = self.make_branch('any')
3349
3345
        tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
3350
3346
        tt = TransformPreview(tree)
3367
3363
 
3368
3364
class TestSerializeTransform(tests.TestCaseWithTransport):
3369
3365
 
3370
 
    _test_needs_features = [tests.UnicodeFilenameFeature]
 
3366
    _test_needs_features = [features.UnicodeFilenameFeature]
3371
3367
 
3372
3368
    def get_preview(self, tree=None):
3373
3369
        if tree is None:
3448
3444
        return self.make_records(attribs, contents)
3449
3445
 
3450
3446
    def test_serialize_symlink_creation(self):
3451
 
        self.requireFeature(tests.SymlinkFeature)
 
3447
        self.requireFeature(features.SymlinkFeature)
3452
3448
        tt = self.get_preview()
3453
3449
        tt.new_symlink(u'foo\u1234', tt.root, u'bar\u1234')
3454
3450
        self.assertSerializesTo(self.symlink_creation_records(), tt)
3455
3451
 
3456
3452
    def test_deserialize_symlink_creation(self):
3457
 
        self.requireFeature(tests.SymlinkFeature)
 
3453
        self.requireFeature(features.SymlinkFeature)
3458
3454
        tt = self.get_preview()
3459
3455
        tt.deserialize(iter(self.symlink_creation_records()))
3460
3456
        abspath = tt._limbo_name('new-1')
3638
3634
        self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3639
3635
 
3640
3636
    def _set_orphan_policy(self, wt, policy):
3641
 
        wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
 
3637
        wt.branch.get_config_stack().set('bzr.transform.orphan_policy',
3642
3638
                                               policy)
3643
3639
 
3644
3640
    def _prepare_orphan(self, wt):
3717
3713
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3718
3714
                         remaining_conflicts.pop())
3719
3715
        self.assertLength(1, warnings)
3720
 
        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)