~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Joe Julian
  • Date: 2010-01-10 02:25:31 UTC
  • mto: (4634.119.7 2.0)
  • mto: This revision was merged to the branch mainline in revision 4959.
  • Revision ID: joe@julianfamily.org-20100110022531-wqk61rsagz8xsiga
Added MANIFEST.in to allow bdist_rpm to have all the required include files and tools. bdist_rpm will still fail to build correctly on some distributions due to a disttools bug http://bugs.python.org/issue644744

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import sys
21
21
 
22
22
from bzrlib import (
 
23
    bencode,
23
24
    errors,
24
25
    generate_ids,
25
26
    osutils,
53
54
                              build_tree, get_backup_name,
54
55
                              _FileMover, resolve_checkout,
55
56
                              TransformPreview, create_from_tree)
56
 
from bzrlib.util import bencode
57
57
 
58
58
 
59
59
class TestTreeTransform(tests.TestCaseWithTransport):
525
525
        resolve_conflicts(replace)
526
526
        replace.apply()
527
527
 
528
 
    def test_symlinks(self):
 
528
    def _test_symlinks(self, link_name1,link_target1,
 
529
                       link_name2, link_target2):
 
530
 
 
531
        def ozpath(p): return 'oz/' + p
 
532
 
529
533
        self.requireFeature(SymlinkFeature)
530
 
        transform,root = self.get_transform()
 
534
        transform, root = self.get_transform()
531
535
        oz_id = transform.new_directory('oz', root, 'oz-id')
532
 
        wizard = transform.new_symlink('wizard', oz_id, 'wizard-target',
 
536
        wizard = transform.new_symlink(link_name1, oz_id, link_target1,
533
537
                                       'wizard-id')
534
 
        wiz_id = transform.create_path('wizard2', oz_id)
535
 
        transform.create_symlink('behind_curtain', wiz_id)
 
538
        wiz_id = transform.create_path(link_name2, oz_id)
 
539
        transform.create_symlink(link_target2, wiz_id)
536
540
        transform.version_file('wiz-id2', wiz_id)
537
541
        transform.set_executability(True, wiz_id)
538
542
        self.assertEqual(transform.find_conflicts(),
539
543
                         [('non-file executability', wiz_id)])
540
544
        transform.set_executability(None, wiz_id)
541
545
        transform.apply()
542
 
        self.assertEqual(self.wt.path2id('oz/wizard'), 'wizard-id')
543
 
        self.assertEqual(file_kind(self.wt.abspath('oz/wizard')), 'symlink')
544
 
        self.assertEqual(os.readlink(self.wt.abspath('oz/wizard2')),
545
 
                         'behind_curtain')
546
 
        self.assertEqual(os.readlink(self.wt.abspath('oz/wizard')),
547
 
                         'wizard-target')
 
546
        self.assertEqual(self.wt.path2id(ozpath(link_name1)), 'wizard-id')
 
547
        self.assertEqual('symlink',
 
548
                         file_kind(self.wt.abspath(ozpath(link_name1))))
 
549
        self.assertEqual(link_target2,
 
550
                         osutils.readlink(self.wt.abspath(ozpath(link_name2))))
 
551
        self.assertEqual(link_target1,
 
552
                         osutils.readlink(self.wt.abspath(ozpath(link_name1))))
 
553
 
 
554
    def test_symlinks(self):
 
555
        self._test_symlinks('wizard', 'wizard-target',
 
556
                            'wizard2', 'behind_curtain')
 
557
 
 
558
    def test_symlinks_unicode(self):
 
559
        self.requireFeature(tests.UnicodeFilenameFeature)
 
560
        self._test_symlinks(u'\N{Euro Sign}wizard',
 
561
                            u'wizard-targ\N{Euro Sign}t',
 
562
                            u'\N{Euro Sign}wizard2',
 
563
                            u'b\N{Euro Sign}hind_curtain')
548
564
 
549
565
    def test_unable_create_symlink(self):
550
566
        def tt_helper():
1841
1857
        self.assertTrue(source.is_executable('file1-id'))
1842
1858
 
1843
1859
    def test_case_insensitive_build_tree_inventory(self):
1844
 
        if (not tests.CaseInsensitiveFilesystemFeature.available()
1845
 
            or not tests.CaseInsCasePresFilenameFeature.available()):
 
1860
        if (tests.CaseInsensitiveFilesystemFeature.available()
 
1861
            or tests.CaseInsCasePresFilenameFeature.available()):
1846
1862
            raise tests.UnavailableFeature('Fully case sensitive filesystem')
1847
1863
        source = self.make_branch_and_tree('source')
1848
1864
        self.build_tree(['source/file', 'source/FILE'])
1857
1873
        self.assertEqual('FILE', target.id2path('upper-id'))
1858
1874
 
1859
1875
 
 
1876
class TestCommitTransform(tests.TestCaseWithTransport):
 
1877
 
 
1878
    def get_branch(self):
 
1879
        tree = self.make_branch_and_tree('tree')
 
1880
        tree.lock_write()
 
1881
        self.addCleanup(tree.unlock)
 
1882
        tree.commit('empty commit')
 
1883
        return tree.branch
 
1884
 
 
1885
    def get_branch_and_transform(self):
 
1886
        branch = self.get_branch()
 
1887
        tt = TransformPreview(branch.basis_tree())
 
1888
        self.addCleanup(tt.finalize)
 
1889
        return branch, tt
 
1890
 
 
1891
    def test_commit_wrong_basis(self):
 
1892
        branch = self.get_branch()
 
1893
        basis = branch.repository.revision_tree(
 
1894
            _mod_revision.NULL_REVISION)
 
1895
        tt = TransformPreview(basis)
 
1896
        self.addCleanup(tt.finalize)
 
1897
        e = self.assertRaises(ValueError, tt.commit, branch, '')
 
1898
        self.assertEqual('TreeTransform not based on branch basis: null:',
 
1899
                         str(e))
 
1900
 
 
1901
    def test_empy_commit(self):
 
1902
        branch, tt = self.get_branch_and_transform()
 
1903
        rev = tt.commit(branch, 'my message')
 
1904
        self.assertEqual(2, branch.revno())
 
1905
        repo = branch.repository
 
1906
        self.assertEqual('my message', repo.get_revision(rev).message)
 
1907
 
 
1908
    def test_merge_parents(self):
 
1909
        branch, tt = self.get_branch_and_transform()
 
1910
        rev = tt.commit(branch, 'my message', ['rev1b', 'rev1c'])
 
1911
        self.assertEqual(['rev1b', 'rev1c'],
 
1912
                         branch.basis_tree().get_parent_ids()[1:])
 
1913
 
 
1914
    def test_first_commit(self):
 
1915
        branch = self.make_branch('branch')
 
1916
        branch.lock_write()
 
1917
        self.addCleanup(branch.unlock)
 
1918
        tt = TransformPreview(branch.basis_tree())
 
1919
        tt.new_directory('', ROOT_PARENT, 'TREE_ROOT')
 
1920
        rev = tt.commit(branch, 'my message')
 
1921
        self.assertEqual([], branch.basis_tree().get_parent_ids())
 
1922
        self.assertNotEqual(_mod_revision.NULL_REVISION,
 
1923
                            branch.last_revision())
 
1924
 
 
1925
    def test_first_commit_with_merge_parents(self):
 
1926
        branch = self.make_branch('branch')
 
1927
        branch.lock_write()
 
1928
        self.addCleanup(branch.unlock)
 
1929
        tt = TransformPreview(branch.basis_tree())
 
1930
        e = self.assertRaises(ValueError, tt.commit, branch,
 
1931
                          'my message', ['rev1b-id'])
 
1932
        self.assertEqual('Cannot supply merge parents for first commit.',
 
1933
                         str(e))
 
1934
        self.assertEqual(_mod_revision.NULL_REVISION, branch.last_revision())
 
1935
 
 
1936
    def test_add_files(self):
 
1937
        branch, tt = self.get_branch_and_transform()
 
1938
        tt.new_file('file', tt.root, 'contents', 'file-id')
 
1939
        trans_id = tt.new_directory('dir', tt.root, 'dir-id')
 
1940
        tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
 
1941
        rev = tt.commit(branch, 'message')
 
1942
        tree = branch.basis_tree()
 
1943
        self.assertEqual('file', tree.id2path('file-id'))
 
1944
        self.assertEqual('contents', tree.get_file_text('file-id'))
 
1945
        self.assertEqual('dir', tree.id2path('dir-id'))
 
1946
        self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
 
1947
        self.assertEqual('target', tree.get_symlink_target('symlink-id'))
 
1948
 
 
1949
    def test_add_unversioned(self):
 
1950
        branch, tt = self.get_branch_and_transform()
 
1951
        tt.new_file('file', tt.root, 'contents')
 
1952
        self.assertRaises(errors.StrictCommitFailed, tt.commit, branch,
 
1953
                          'message', strict=True)
 
1954
 
 
1955
    def test_modify_strict(self):
 
1956
        branch, tt = self.get_branch_and_transform()
 
1957
        tt.new_file('file', tt.root, 'contents', 'file-id')
 
1958
        tt.commit(branch, 'message', strict=True)
 
1959
        tt = TransformPreview(branch.basis_tree())
 
1960
        trans_id = tt.trans_id_file_id('file-id')
 
1961
        tt.delete_contents(trans_id)
 
1962
        tt.create_file('contents', trans_id)
 
1963
        tt.commit(branch, 'message', strict=True)
 
1964
 
 
1965
    def test_commit_malformed(self):
 
1966
        """Committing a malformed transform should raise an exception.
 
1967
 
 
1968
        In this case, we are adding a file without adding its parent.
 
1969
        """
 
1970
        branch, tt = self.get_branch_and_transform()
 
1971
        parent_id = tt.trans_id_file_id('parent-id')
 
1972
        tt.new_file('file', parent_id, 'contents', 'file-id')
 
1973
        self.assertRaises(errors.MalformedTransform, tt.commit, branch,
 
1974
                          'message')
 
1975
 
 
1976
 
1860
1977
class MockTransform(object):
1861
1978
 
1862
1979
    def has_named_child(self, by_parent, parent_id, name):
2029
2146
    def create_tree(self):
2030
2147
        tree = self.make_branch_and_tree('.')
2031
2148
        self.build_tree_contents([('a', 'content 1')])
 
2149
        tree.set_root_id('TREE_ROOT')
2032
2150
        tree.add('a', 'a-id')
2033
2151
        tree.commit('rev1', rev_id='rev1')
2034
2152
        return tree.branch.repository.revision_tree('rev1')
2496
2614
 
2497
2615
    def test_walkdirs(self):
2498
2616
        preview = self.get_empty_preview()
2499
 
        preview.version_file('tree-root', preview.root)
 
2617
        root = preview.new_directory('', ROOT_PARENT, 'tree-root')
 
2618
        # FIXME: new_directory should mark root.
 
2619
        preview.adjust_path('', ROOT_PARENT, root)
2500
2620
        preview_tree = preview.get_preview_tree()
2501
2621
        file_trans_id = preview.new_file('a', preview.root, 'contents',
2502
2622
                                         'a-id')
2533
2653
        self.addCleanup(work_tree.unlock)
2534
2654
        preview = TransformPreview(work_tree)
2535
2655
        self.addCleanup(preview.finalize)
2536
 
        preview_tree = preview.get_preview_tree()
2537
2656
        file_trans_id = preview.trans_id_file_id('file-id')
2538
2657
        preview.delete_contents(file_trans_id)
2539
2658
        preview.create_file('a\nb\n', file_trans_id)
2540
2659
        pb = progress.DummyProgress()
 
2660
        preview_tree = preview.get_preview_tree()
2541
2661
        merger = Merger.from_revision_ids(pb, preview_tree,
2542
2662
                                          child_tree.branch.last_revision(),
2543
2663
                                          other_branch=child_tree.branch,
2550
2670
 
2551
2671
    def test_merge_preview_into_workingtree(self):
2552
2672
        tree = self.make_branch_and_tree('tree')
 
2673
        tree.set_root_id('TREE_ROOT')
2553
2674
        tt = TransformPreview(tree)
2554
2675
        self.addCleanup(tt.finalize)
2555
2676
        tt.new_file('name', tt.root, 'content', 'file-id')
2556
2677
        tree2 = self.make_branch_and_tree('tree2')
 
2678
        tree2.set_root_id('TREE_ROOT')
2557
2679
        pb = progress.DummyProgress()
2558
2680
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2559
2681
                                         pb, tree.basis_tree())
2588
2710
                                                           'tree/foo'))
2589
2711
        self.assertEqual(False, preview_tree.is_executable('baz-id'))
2590
2712
 
 
2713
    def test_commit_preview_tree(self):
 
2714
        tree = self.make_branch_and_tree('tree')
 
2715
        rev_id = tree.commit('rev1')
 
2716
        tree.branch.lock_write()
 
2717
        self.addCleanup(tree.branch.unlock)
 
2718
        tt = TransformPreview(tree)
 
2719
        tt.new_file('file', tt.root, 'contents', 'file_id')
 
2720
        self.addCleanup(tt.finalize)
 
2721
        preview = tt.get_preview_tree()
 
2722
        preview.set_parent_ids([rev_id])
 
2723
        builder = tree.branch.get_commit_builder([rev_id])
 
2724
        list(builder.record_iter_changes(preview, rev_id, tt.iter_changes()))
 
2725
        builder.finish_inventory()
 
2726
        rev2_id = builder.commit('rev2')
 
2727
        rev2_tree = tree.branch.repository.revision_tree(rev2_id)
 
2728
        self.assertEqual('contents', rev2_tree.get_file_text('file_id'))
 
2729
 
 
2730
    def test_ascii_limbo_paths(self):
 
2731
        self.requireFeature(tests.UnicodeFilenameFeature)
 
2732
        branch = self.make_branch('any')
 
2733
        tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
 
2734
        tt = TransformPreview(tree)
 
2735
        foo_id = tt.new_directory('', ROOT_PARENT)
 
2736
        bar_id = tt.new_file(u'\u1234bar', foo_id, 'contents')
 
2737
        limbo_path = tt._limbo_name(bar_id)
 
2738
        self.assertEqual(limbo_path.encode('ascii', 'replace'), limbo_path)
 
2739
 
2591
2740
 
2592
2741
class FakeSerializer(object):
2593
2742
    """Serializer implementation that simply returns the input.
2688
2837
        self.assertSerializesTo(self.symlink_creation_records(), tt)
2689
2838
 
2690
2839
    def test_deserialize_symlink_creation(self):
 
2840
        self.requireFeature(tests.SymlinkFeature)
2691
2841
        tt = self.get_preview()
2692
2842
        tt.deserialize(iter(self.symlink_creation_records()))
2693
 
        # XXX readlink should be returning unicode, not utf-8
2694
 
        foo_content = os.readlink(tt._limbo_name('new-1')).decode('utf-8')
 
2843
        abspath = tt._limbo_name('new-1')
 
2844
        foo_content = osutils.readlink(abspath)
2695
2845
        self.assertEqual(u'bar\u1234', foo_content)
2696
2846
 
2697
2847
    def make_destruction_preview(self):