~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-06 20:42:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4088.
  • Revision ID: john@arbash-meinel.com-20090306204240-mzjavv31z3gu1x7i
Fix a small bug in setup.py when an extension fails to build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
 
18
import stat
18
19
from StringIO import StringIO
19
20
import sys
20
 
import time
21
21
 
22
22
from bzrlib import (
23
 
    bencode,
24
23
    errors,
25
 
    filters,
26
24
    generate_ids,
27
25
    osutils,
28
26
    progress,
29
27
    revision as _mod_revision,
30
 
    rules,
 
28
    symbol_versioning,
31
29
    tests,
32
30
    urlutils,
33
31
    )
55
53
                              build_tree, get_backup_name,
56
54
                              _FileMover, resolve_checkout,
57
55
                              TransformPreview, create_from_tree)
 
56
from bzrlib.util import bencode
58
57
 
59
58
 
60
59
class TestTreeTransform(tests.TestCaseWithTransport):
137
136
        transform.finalize()
138
137
        transform.finalize()
139
138
 
140
 
    def test_create_files_same_timestamp(self):
141
 
        transform, root = self.get_transform()
142
 
        self.wt.lock_tree_write()
143
 
        self.addCleanup(self.wt.unlock)
144
 
        # Roll back the clock, so that we know everything is being set to the
145
 
        # exact time
146
 
        transform._creation_mtime = creation_mtime = time.time() - 20.0
147
 
        transform.create_file('content-one',
148
 
                              transform.create_path('one', root))
149
 
        time.sleep(1) # *ugly*
150
 
        transform.create_file('content-two',
151
 
                              transform.create_path('two', root))
152
 
        transform.apply()
153
 
        fo, st1 = self.wt.get_file_with_stat(None, path='one', filtered=False)
154
 
        fo.close()
155
 
        fo, st2 = self.wt.get_file_with_stat(None, path='two', filtered=False)
156
 
        fo.close()
157
 
        # We only guarantee 2s resolution
158
 
        self.assertTrue(abs(creation_mtime - st1.st_mtime) < 2.0,
159
 
            "%s != %s within 2 seconds" % (creation_mtime, st1.st_mtime))
160
 
        # But if we have more than that, all files should get the same result
161
 
        self.assertEqual(st1.st_mtime, st2.st_mtime)
162
 
 
163
 
    def test_change_root_id(self):
164
 
        transform, root = self.get_transform()
165
 
        self.assertNotEqual('new-root-id', self.wt.get_root_id())
166
 
        transform.new_directory('', ROOT_PARENT, 'new-root-id')
167
 
        transform.delete_contents(root)
168
 
        transform.unversion_file(root)
169
 
        transform.fixup_new_roots()
170
 
        transform.apply()
171
 
        self.assertEqual('new-root-id', self.wt.get_root_id())
172
 
 
173
 
    def test_change_root_id_add_files(self):
174
 
        transform, root = self.get_transform()
175
 
        self.assertNotEqual('new-root-id', self.wt.get_root_id())
176
 
        new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
177
 
        transform.new_file('file', new_trans_id, ['new-contents\n'],
178
 
                           'new-file-id')
179
 
        transform.delete_contents(root)
180
 
        transform.unversion_file(root)
181
 
        transform.fixup_new_roots()
182
 
        transform.apply()
183
 
        self.assertEqual('new-root-id', self.wt.get_root_id())
184
 
        self.assertEqual('new-file-id', self.wt.path2id('file'))
185
 
        self.assertFileEqual('new-contents\n', self.wt.abspath('file'))
186
 
 
187
 
    def test_add_two_roots(self):
188
 
        transform, root = self.get_transform()
189
 
        new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
190
 
        new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
191
 
        self.assertRaises(ValueError, transform.fixup_new_roots)
192
 
 
193
139
    def test_hardlink(self):
194
140
        self.requireFeature(HardlinkFeature)
195
141
        transform, root = self.get_transform()
423
369
        self.assertContainsRe(transform._limbo_name(first), 'new-1/file')
424
370
        self.assertNotContainsRe(transform._limbo_name(second), 'new-1/FiLe')
425
371
 
426
 
    def test_adjust_path_updates_child_limbo_names(self):
427
 
        tree = self.make_branch_and_tree('tree')
428
 
        transform = TreeTransform(tree)
429
 
        self.addCleanup(transform.finalize)
430
 
        foo_id = transform.new_directory('foo', transform.root)
431
 
        bar_id = transform.new_directory('bar', foo_id)
432
 
        baz_id = transform.new_directory('baz', bar_id)
433
 
        qux_id = transform.new_directory('qux', baz_id)
434
 
        transform.adjust_path('quxx', foo_id, bar_id)
435
 
        self.assertStartsWith(transform._limbo_name(qux_id),
436
 
                              transform._limbo_name(bar_id))
437
 
 
438
372
    def test_add_del(self):
439
373
        start, root = self.get_transform()
440
374
        start.new_directory('a', root, 'a')
591
525
        resolve_conflicts(replace)
592
526
        replace.apply()
593
527
 
594
 
    def _test_symlinks(self, link_name1,link_target1,
595
 
                       link_name2, link_target2):
596
 
 
597
 
        def ozpath(p): return 'oz/' + p
598
 
 
 
528
    def test_symlinks(self):
599
529
        self.requireFeature(SymlinkFeature)
600
 
        transform, root = self.get_transform()
 
530
        transform,root = self.get_transform()
601
531
        oz_id = transform.new_directory('oz', root, 'oz-id')
602
 
        wizard = transform.new_symlink(link_name1, oz_id, link_target1,
 
532
        wizard = transform.new_symlink('wizard', oz_id, 'wizard-target',
603
533
                                       'wizard-id')
604
 
        wiz_id = transform.create_path(link_name2, oz_id)
605
 
        transform.create_symlink(link_target2, wiz_id)
 
534
        wiz_id = transform.create_path('wizard2', oz_id)
 
535
        transform.create_symlink('behind_curtain', wiz_id)
606
536
        transform.version_file('wiz-id2', wiz_id)
607
537
        transform.set_executability(True, wiz_id)
608
538
        self.assertEqual(transform.find_conflicts(),
609
539
                         [('non-file executability', wiz_id)])
610
540
        transform.set_executability(None, wiz_id)
611
541
        transform.apply()
612
 
        self.assertEqual(self.wt.path2id(ozpath(link_name1)), 'wizard-id')
613
 
        self.assertEqual('symlink',
614
 
                         file_kind(self.wt.abspath(ozpath(link_name1))))
615
 
        self.assertEqual(link_target2,
616
 
                         osutils.readlink(self.wt.abspath(ozpath(link_name2))))
617
 
        self.assertEqual(link_target1,
618
 
                         osutils.readlink(self.wt.abspath(ozpath(link_name1))))
619
 
 
620
 
    def test_symlinks(self):
621
 
        self._test_symlinks('wizard', 'wizard-target',
622
 
                            'wizard2', 'behind_curtain')
623
 
 
624
 
    def test_symlinks_unicode(self):
625
 
        self.requireFeature(tests.UnicodeFilenameFeature)
626
 
        self._test_symlinks(u'\N{Euro Sign}wizard',
627
 
                            u'wizard-targ\N{Euro Sign}t',
628
 
                            u'\N{Euro Sign}wizard2',
629
 
                            u'b\N{Euro Sign}hind_curtain')
 
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')
630
548
 
631
549
    def test_unable_create_symlink(self):
632
550
        def tt_helper():
812
730
        create.apply()
813
731
        transform, root = self.get_transform()
814
732
        transform.adjust_root_path('oldroot', fun)
815
 
        new_root = transform.trans_id_tree_path('')
 
733
        new_root=transform.trans_id_tree_path('')
816
734
        transform.version_file('new-root', new_root)
817
735
        transform.apply()
818
736
 
1922
1840
        self.assertEqual([], list(target.iter_changes(revision_tree)))
1923
1841
        self.assertTrue(source.is_executable('file1-id'))
1924
1842
 
1925
 
    def install_rot13_content_filter(self, pattern):
1926
 
        # We could use
1927
 
        # self.addCleanup(filters._reset_registry, filters._reset_registry())
1928
 
        # below, but that looks a bit... hard to read even if it's exactly
1929
 
        # the same thing.
1930
 
        original_registry = filters._reset_registry()
1931
 
        def restore_registry():
1932
 
            filters._reset_registry(original_registry)
1933
 
        self.addCleanup(restore_registry)
1934
 
        def rot13(chunks, context=None):
1935
 
            return [''.join(chunks).encode('rot13')]
1936
 
        rot13filter = filters.ContentFilter(rot13, rot13)
1937
 
        filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
1938
 
        os.mkdir(self.test_home_dir + '/.bazaar')
1939
 
        rules_filename = self.test_home_dir + '/.bazaar/rules'
1940
 
        f = open(rules_filename, 'wb')
1941
 
        f.write('[name %s]\nrot13=yes\n' % (pattern,))
1942
 
        f.close()
1943
 
        def uninstall_rules():
1944
 
            os.remove(rules_filename)
1945
 
            rules.reset_rules()
1946
 
        self.addCleanup(uninstall_rules)
1947
 
        rules.reset_rules()
1948
 
 
1949
 
    def test_build_tree_content_filtered_files_are_not_hardlinked(self):
1950
 
        """build_tree will not hardlink files that have content filtering rules
1951
 
        applied to them (but will still hardlink other files from the same tree
1952
 
        if it can).
1953
 
        """
1954
 
        self.requireFeature(HardlinkFeature)
1955
 
        self.install_rot13_content_filter('file1')
1956
 
        source = self.create_ab_tree()
1957
 
        target = self.make_branch_and_tree('target')
1958
 
        revision_tree = source.basis_tree()
1959
 
        revision_tree.lock_read()
1960
 
        self.addCleanup(revision_tree.unlock)
1961
 
        build_tree(revision_tree, target, source, hardlink=True)
1962
 
        target.lock_read()
1963
 
        self.addCleanup(target.unlock)
1964
 
        self.assertEqual([], list(target.iter_changes(revision_tree)))
1965
 
        source_stat = os.stat('source/file1')
1966
 
        target_stat = os.stat('target/file1')
1967
 
        self.assertNotEqual(source_stat, target_stat)
1968
 
        source_stat = os.stat('source/file2')
1969
 
        target_stat = os.stat('target/file2')
1970
 
        self.assertEqualStat(source_stat, target_stat)
1971
 
 
1972
1843
    def test_case_insensitive_build_tree_inventory(self):
1973
 
        if (tests.CaseInsensitiveFilesystemFeature.available()
1974
 
            or tests.CaseInsCasePresFilenameFeature.available()):
1975
 
            raise tests.UnavailableFeature('Fully case sensitive filesystem')
1976
1844
        source = self.make_branch_and_tree('source')
1977
1845
        self.build_tree(['source/file', 'source/FILE'])
1978
1846
        source.add(['file', 'FILE'], ['lower-id', 'upper-id'])
1986
1854
        self.assertEqual('FILE', target.id2path('upper-id'))
1987
1855
 
1988
1856
 
1989
 
class TestCommitTransform(tests.TestCaseWithTransport):
1990
 
 
1991
 
    def get_branch(self):
1992
 
        tree = self.make_branch_and_tree('tree')
1993
 
        tree.lock_write()
1994
 
        self.addCleanup(tree.unlock)
1995
 
        tree.commit('empty commit')
1996
 
        return tree.branch
1997
 
 
1998
 
    def get_branch_and_transform(self):
1999
 
        branch = self.get_branch()
2000
 
        tt = TransformPreview(branch.basis_tree())
2001
 
        self.addCleanup(tt.finalize)
2002
 
        return branch, tt
2003
 
 
2004
 
    def test_commit_wrong_basis(self):
2005
 
        branch = self.get_branch()
2006
 
        basis = branch.repository.revision_tree(
2007
 
            _mod_revision.NULL_REVISION)
2008
 
        tt = TransformPreview(basis)
2009
 
        self.addCleanup(tt.finalize)
2010
 
        e = self.assertRaises(ValueError, tt.commit, branch, '')
2011
 
        self.assertEqual('TreeTransform not based on branch basis: null:',
2012
 
                         str(e))
2013
 
 
2014
 
    def test_empy_commit(self):
2015
 
        branch, tt = self.get_branch_and_transform()
2016
 
        rev = tt.commit(branch, 'my message')
2017
 
        self.assertEqual(2, branch.revno())
2018
 
        repo = branch.repository
2019
 
        self.assertEqual('my message', repo.get_revision(rev).message)
2020
 
 
2021
 
    def test_merge_parents(self):
2022
 
        branch, tt = self.get_branch_and_transform()
2023
 
        rev = tt.commit(branch, 'my message', ['rev1b', 'rev1c'])
2024
 
        self.assertEqual(['rev1b', 'rev1c'],
2025
 
                         branch.basis_tree().get_parent_ids()[1:])
2026
 
 
2027
 
    def test_first_commit(self):
2028
 
        branch = self.make_branch('branch')
2029
 
        branch.lock_write()
2030
 
        self.addCleanup(branch.unlock)
2031
 
        tt = TransformPreview(branch.basis_tree())
2032
 
        self.addCleanup(tt.finalize)
2033
 
        tt.new_directory('', ROOT_PARENT, 'TREE_ROOT')
2034
 
        rev = tt.commit(branch, 'my message')
2035
 
        self.assertEqual([], branch.basis_tree().get_parent_ids())
2036
 
        self.assertNotEqual(_mod_revision.NULL_REVISION,
2037
 
                            branch.last_revision())
2038
 
 
2039
 
    def test_first_commit_with_merge_parents(self):
2040
 
        branch = self.make_branch('branch')
2041
 
        branch.lock_write()
2042
 
        self.addCleanup(branch.unlock)
2043
 
        tt = TransformPreview(branch.basis_tree())
2044
 
        self.addCleanup(tt.finalize)
2045
 
        e = self.assertRaises(ValueError, tt.commit, branch,
2046
 
                          'my message', ['rev1b-id'])
2047
 
        self.assertEqual('Cannot supply merge parents for first commit.',
2048
 
                         str(e))
2049
 
        self.assertEqual(_mod_revision.NULL_REVISION, branch.last_revision())
2050
 
 
2051
 
    def test_add_files(self):
2052
 
        branch, tt = self.get_branch_and_transform()
2053
 
        tt.new_file('file', tt.root, 'contents', 'file-id')
2054
 
        trans_id = tt.new_directory('dir', tt.root, 'dir-id')
2055
 
        if SymlinkFeature.available():
2056
 
            tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
2057
 
        rev = tt.commit(branch, 'message')
2058
 
        tree = branch.basis_tree()
2059
 
        self.assertEqual('file', tree.id2path('file-id'))
2060
 
        self.assertEqual('contents', tree.get_file_text('file-id'))
2061
 
        self.assertEqual('dir', tree.id2path('dir-id'))
2062
 
        if SymlinkFeature.available():
2063
 
            self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
2064
 
            self.assertEqual('target', tree.get_symlink_target('symlink-id'))
2065
 
 
2066
 
    def test_add_unversioned(self):
2067
 
        branch, tt = self.get_branch_and_transform()
2068
 
        tt.new_file('file', tt.root, 'contents')
2069
 
        self.assertRaises(errors.StrictCommitFailed, tt.commit, branch,
2070
 
                          'message', strict=True)
2071
 
 
2072
 
    def test_modify_strict(self):
2073
 
        branch, tt = self.get_branch_and_transform()
2074
 
        tt.new_file('file', tt.root, 'contents', 'file-id')
2075
 
        tt.commit(branch, 'message', strict=True)
2076
 
        tt = TransformPreview(branch.basis_tree())
2077
 
        self.addCleanup(tt.finalize)
2078
 
        trans_id = tt.trans_id_file_id('file-id')
2079
 
        tt.delete_contents(trans_id)
2080
 
        tt.create_file('contents', trans_id)
2081
 
        tt.commit(branch, 'message', strict=True)
2082
 
 
2083
 
    def test_commit_malformed(self):
2084
 
        """Committing a malformed transform should raise an exception.
2085
 
 
2086
 
        In this case, we are adding a file without adding its parent.
2087
 
        """
2088
 
        branch, tt = self.get_branch_and_transform()
2089
 
        parent_id = tt.trans_id_file_id('parent-id')
2090
 
        tt.new_file('file', parent_id, 'contents', 'file-id')
2091
 
        self.assertRaises(errors.MalformedTransform, tt.commit, branch,
2092
 
                          'message')
2093
 
 
2094
 
 
2095
1857
class MockTransform(object):
2096
1858
 
2097
1859
    def has_named_child(self, by_parent, parent_id, name):
2264
2026
    def create_tree(self):
2265
2027
        tree = self.make_branch_and_tree('.')
2266
2028
        self.build_tree_contents([('a', 'content 1')])
2267
 
        tree.set_root_id('TREE_ROOT')
2268
2029
        tree.add('a', 'a-id')
2269
2030
        tree.commit('rev1', rev_id='rev1')
2270
2031
        return tree.branch.repository.revision_tree('rev1')
2371
2132
    def test_ignore_pb(self):
2372
2133
        # pb could be supported, but TT.iter_changes doesn't support it.
2373
2134
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2374
 
        preview_tree.iter_changes(revision_tree)
 
2135
        preview_tree.iter_changes(revision_tree, pb=progress.DummyProgress())
2375
2136
 
2376
2137
    def test_kind(self):
2377
2138
        revision_tree = self.create_tree()
2392
2153
        self.assertEqual(os.stat(limbo_path).st_mtime,
2393
2154
                         preview_tree.get_file_mtime('file-id'))
2394
2155
 
2395
 
    def test_get_file_mtime_renamed(self):
2396
 
        work_tree = self.make_branch_and_tree('tree')
2397
 
        self.build_tree(['tree/file'])
2398
 
        work_tree.add('file', 'file-id')
2399
 
        preview = TransformPreview(work_tree)
2400
 
        self.addCleanup(preview.finalize)
2401
 
        file_trans_id = preview.trans_id_tree_file_id('file-id')
2402
 
        preview.adjust_path('renamed', preview.root, file_trans_id)
2403
 
        preview_tree = preview.get_preview_tree()
2404
 
        preview_mtime = preview_tree.get_file_mtime('file-id', 'renamed')
2405
 
        work_mtime = work_tree.get_file_mtime('file-id', 'file')
2406
 
 
2407
2156
    def test_get_file(self):
2408
2157
        preview = self.get_empty_preview()
2409
2158
        preview.new_file('file', preview.root, 'contents', 'file-id')
2557
2306
        self.assertEqual(('missing', None, None, None), summary)
2558
2307
 
2559
2308
    def test_file_content_summary_executable(self):
 
2309
        if not osutils.supports_executable():
 
2310
            raise TestNotApplicable()
2560
2311
        preview = self.get_empty_preview()
2561
2312
        path_id = preview.new_file('path', preview.root, 'contents', 'path-id')
2562
2313
        preview.set_executability(True, path_id)
2571
2322
        self.assertIs(None, summary[3])
2572
2323
 
2573
2324
    def test_change_executability(self):
 
2325
        if not osutils.supports_executable():
 
2326
            raise TestNotApplicable()
2574
2327
        tree = self.make_branch_and_tree('tree')
2575
2328
        self.build_tree(['tree/path'])
2576
2329
        tree.add('path')
2590
2343
        # size must be known
2591
2344
        self.assertEqual(len('contents'), summary[1])
2592
2345
        # not executable
2593
 
        self.assertEqual(False, summary[2])
 
2346
        if osutils.supports_executable():
 
2347
            self.assertEqual(False, summary[2])
 
2348
        else:
 
2349
            self.assertEqual(None, summary[2])
2594
2350
        # will not have hash (not cheap to determine)
2595
2351
        self.assertIs(None, summary[3])
2596
2352
 
2737
2493
 
2738
2494
    def test_walkdirs(self):
2739
2495
        preview = self.get_empty_preview()
2740
 
        root = preview.new_directory('', ROOT_PARENT, 'tree-root')
2741
 
        # FIXME: new_directory should mark root.
2742
 
        preview.fixup_new_roots()
 
2496
        preview.version_file('tree-root', preview.root)
2743
2497
        preview_tree = preview.get_preview_tree()
2744
2498
        file_trans_id = preview.new_file('a', preview.root, 'contents',
2745
2499
                                         'a-id')
2776
2530
        self.addCleanup(work_tree.unlock)
2777
2531
        preview = TransformPreview(work_tree)
2778
2532
        self.addCleanup(preview.finalize)
 
2533
        preview_tree = preview.get_preview_tree()
2779
2534
        file_trans_id = preview.trans_id_file_id('file-id')
2780
2535
        preview.delete_contents(file_trans_id)
2781
2536
        preview.create_file('a\nb\n', file_trans_id)
2782
 
        preview_tree = preview.get_preview_tree()
2783
 
        merger = Merger.from_revision_ids(None, preview_tree,
 
2537
        pb = progress.DummyProgress()
 
2538
        merger = Merger.from_revision_ids(pb, preview_tree,
2784
2539
                                          child_tree.branch.last_revision(),
2785
2540
                                          other_branch=child_tree.branch,
2786
2541
                                          tree_branch=work_tree.branch)
2792
2547
 
2793
2548
    def test_merge_preview_into_workingtree(self):
2794
2549
        tree = self.make_branch_and_tree('tree')
2795
 
        tree.set_root_id('TREE_ROOT')
2796
2550
        tt = TransformPreview(tree)
2797
2551
        self.addCleanup(tt.finalize)
2798
2552
        tt.new_file('name', tt.root, 'content', 'file-id')
2799
2553
        tree2 = self.make_branch_and_tree('tree2')
2800
 
        tree2.set_root_id('TREE_ROOT')
 
2554
        pb = progress.DummyProgress()
2801
2555
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2802
 
                                         None, tree.basis_tree())
 
2556
                                         pb, tree.basis_tree())
2803
2557
        merger.merge_type = Merge3Merger
2804
2558
        merger.do_merge()
2805
2559
 
2815
2569
        tt.create_file('baz', trans_id)
2816
2570
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
2817
2571
        self.build_tree_contents([('tree2/foo', 'qux')])
2818
 
        pb = None
 
2572
        pb = progress.DummyProgress()
2819
2573
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2820
2574
                                         pb, tree.basis_tree())
2821
2575
        merger.merge_type = Merge3Merger
2831
2585
                                                           'tree/foo'))
2832
2586
        self.assertEqual(False, preview_tree.is_executable('baz-id'))
2833
2587
 
2834
 
    def test_commit_preview_tree(self):
2835
 
        tree = self.make_branch_and_tree('tree')
2836
 
        rev_id = tree.commit('rev1')
2837
 
        tree.branch.lock_write()
2838
 
        self.addCleanup(tree.branch.unlock)
2839
 
        tt = TransformPreview(tree)
2840
 
        tt.new_file('file', tt.root, 'contents', 'file_id')
2841
 
        self.addCleanup(tt.finalize)
2842
 
        preview = tt.get_preview_tree()
2843
 
        preview.set_parent_ids([rev_id])
2844
 
        builder = tree.branch.get_commit_builder([rev_id])
2845
 
        list(builder.record_iter_changes(preview, rev_id, tt.iter_changes()))
2846
 
        builder.finish_inventory()
2847
 
        rev2_id = builder.commit('rev2')
2848
 
        rev2_tree = tree.branch.repository.revision_tree(rev2_id)
2849
 
        self.assertEqual('contents', rev2_tree.get_file_text('file_id'))
2850
 
 
2851
 
    def test_ascii_limbo_paths(self):
2852
 
        self.requireFeature(tests.UnicodeFilenameFeature)
2853
 
        branch = self.make_branch('any')
2854
 
        tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
2855
 
        tt = TransformPreview(tree)
2856
 
        self.addCleanup(tt.finalize)
2857
 
        foo_id = tt.new_directory('', ROOT_PARENT)
2858
 
        bar_id = tt.new_file(u'\u1234bar', foo_id, 'contents')
2859
 
        limbo_path = tt._limbo_name(bar_id)
2860
 
        self.assertEqual(limbo_path.encode('ascii', 'replace'), limbo_path)
2861
 
 
2862
2588
 
2863
2589
class FakeSerializer(object):
2864
2590
    """Serializer implementation that simply returns the input.
2959
2685
        self.assertSerializesTo(self.symlink_creation_records(), tt)
2960
2686
 
2961
2687
    def test_deserialize_symlink_creation(self):
2962
 
        self.requireFeature(tests.SymlinkFeature)
2963
2688
        tt = self.get_preview()
2964
2689
        tt.deserialize(iter(self.symlink_creation_records()))
2965
 
        abspath = tt._limbo_name('new-1')
2966
 
        foo_content = osutils.readlink(abspath)
 
2690
        # XXX readlink should be returning unicode, not utf-8
 
2691
        foo_content = os.readlink(tt._limbo_name('new-1')).decode('utf-8')
2967
2692
        self.assertEqual(u'bar\u1234', foo_content)
2968
2693
 
2969
2694
    def make_destruction_preview(self):