~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-16 11:08:11 UTC
  • mfrom: (6521 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6522.
  • Revision ID: jelmer@samba.org-20120416110811-0y996ihqy9o2bb1t
Merge bzr.dev.

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,
88
88
 
89
89
    def setUp(self):
90
90
        super(TestTreeTransform, self).setUp()
91
 
        self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
 
91
        self.wt = self.make_branch_and_tree('.', format='development-subtree')
92
92
        os.chdir('..')
93
93
 
94
94
    def get_transform(self):
399
399
        tree.lock_read()
400
400
        self.addCleanup(tree.unlock)
401
401
        self.assertEqual('subtree-revision',
402
 
                         tree.inventory['subtree-id'].reference_revision)
 
402
                         tree.root_inventory['subtree-id'].reference_revision)
403
403
 
404
404
    def test_conflicts(self):
405
405
        transform, root = self.get_transform()
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)
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
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')
2188
2184
        def rot13(chunks, context=None):
2189
2185
            return [''.join(chunks).encode('rot13')]
2190
2186
        rot13filter = filters.ContentFilter(rot13, rot13)
2191
 
        filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
 
2187
        filters.filter_stacks_registry.register(
 
2188
            'rot13', {'yes': [rot13filter]}.get)
2192
2189
        os.mkdir(self.test_home_dir + '/.bazaar')
2193
2190
        rules_filename = self.test_home_dir + '/.bazaar/rules'
2194
2191
        f = open(rules_filename, 'wb')
2414
2411
        self.assertEqual('tree', revision.properties['branch-nick'])
2415
2412
 
2416
2413
 
2417
 
class TestBackupName(tests.TestCase):
2418
 
 
2419
 
    def test_deprecations(self):
2420
 
        class MockTransform(object):
2421
 
 
2422
 
            def has_named_child(self, by_parent, parent_id, name):
2423
 
                return name in by_parent.get(parent_id, [])
2424
 
 
2425
 
        class MockEntry(object):
2426
 
 
2427
 
            def __init__(self):
2428
 
                object.__init__(self)
2429
 
                self.name = "name"
2430
 
 
2431
 
        tt = MockTransform()
2432
 
        name1 = self.applyDeprecated(
2433
 
            symbol_versioning.deprecated_in((2, 3, 0)),
2434
 
            transform.get_backup_name, MockEntry(), {'a':[]}, 'a', tt)
2435
 
        self.assertEqual('name.~1~', name1)
2436
 
        name2 = self.applyDeprecated(
2437
 
            symbol_versioning.deprecated_in((2, 3, 0)),
2438
 
            transform._get_backup_name, 'name', {'a':['name.~1~']}, 'a', tt)
2439
 
        self.assertEqual('name.~2~', name2)
2440
 
 
2441
 
 
2442
2414
class TestFileMover(tests.TestCaseWithTransport):
2443
2415
 
2444
2416
    def test_file_mover(self):
2796
2768
 
2797
2769
    def test_iter_changes(self):
2798
2770
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2799
 
        root = revision_tree.inventory.root.file_id
 
2771
        root = revision_tree.get_root_id()
2800
2772
        self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
2801
2773
                          (root, root), ('a', 'a'), ('file', 'file'),
2802
2774
                          (False, False))],
2806
2778
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2807
2779
        changes = preview_tree.iter_changes(revision_tree,
2808
2780
                                            include_unchanged=True)
2809
 
        root = revision_tree.inventory.root.file_id
 
2781
        root = revision_tree.get_root_id()
2810
2782
 
2811
2783
        self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
2812
2784
 
3638
3610
        self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3639
3611
 
3640
3612
    def _set_orphan_policy(self, wt, policy):
3641
 
        wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
 
3613
        wt.branch.get_config_stack().set('bzr.transform.orphan_policy',
3642
3614
                                               policy)
3643
3615
 
3644
3616
    def _prepare_orphan(self, wt):
3717
3689
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3718
3690
                         remaining_conflicts.pop())
3719
3691
        self.assertLength(1, warnings)
3720
 
        self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')
 
3692
        self.assertStartsWith(warnings[0], 'Value "donttouchmypreciouuus" ')
3721
3693
 
3722
3694
 
3723
3695
class TestTransformHooks(tests.TestCaseWithTransport):