/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-08 09:54:43 UTC
  • mfrom: (5745.3.4 tree-lazy-imports)
  • Revision ID: pqm@pqm.ubuntu.com-20110408095443-euiq0776jpr18w5d
(spiv) Use lazy imports in bzrlib.tree. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
import errno
17
18
import os
18
19
from StringIO import StringIO
19
20
import sys
25
26
    filters,
26
27
    generate_ids,
27
28
    osutils,
28
 
    progress,
29
29
    revision as _mod_revision,
30
30
    rules,
 
31
    symbol_versioning,
31
32
    tests,
 
33
    trace,
 
34
    transform,
32
35
    urlutils,
33
36
    )
34
37
from bzrlib.bzrdir import BzrDir
35
 
from bzrlib.conflicts import (DuplicateEntry, DuplicateID, MissingParent,
36
 
                              UnversionedParent, ParentLoop, DeletingParent,
37
 
                              NonDirectoryParent)
 
38
from bzrlib.conflicts import (
 
39
    DeletingParent,
 
40
    DuplicateEntry,
 
41
    DuplicateID,
 
42
    MissingParent,
 
43
    NonDirectoryParent,
 
44
    ParentLoop,
 
45
    UnversionedParent,
 
46
)
38
47
from bzrlib.diff import show_diff_trees
39
 
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
40
 
                           ReusingTransform, CantMoveRoot,
41
 
                           PathsNotVersionedError, ExistingLimbo,
42
 
                           ExistingPendingDeletion, ImmortalLimbo,
43
 
                           ImmortalPendingDeletion, LockError)
44
 
from bzrlib.osutils import file_kind, pathjoin
 
48
from bzrlib.errors import (
 
49
    DuplicateKey,
 
50
    ExistingLimbo,
 
51
    ExistingPendingDeletion,
 
52
    ImmortalLimbo,
 
53
    ImmortalPendingDeletion,
 
54
    LockError,
 
55
    MalformedTransform,
 
56
    ReusingTransform,
 
57
)
 
58
from bzrlib.osutils import (
 
59
    file_kind,
 
60
    pathjoin,
 
61
)
45
62
from bzrlib.merge import Merge3Merger, Merger
46
63
from bzrlib.tests import (
 
64
    features,
47
65
    HardlinkFeature,
48
66
    SymlinkFeature,
49
 
    TestCase,
50
67
    TestCaseInTempDir,
51
68
    TestSkipped,
52
 
    )
53
 
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths,
54
 
                              resolve_conflicts, cook_conflicts,
55
 
                              build_tree, get_backup_name,
56
 
                              _FileMover, resolve_checkout,
57
 
                              TransformPreview, create_from_tree)
 
69
)
 
70
from bzrlib.transform import (
 
71
    build_tree,
 
72
    create_from_tree,
 
73
    cook_conflicts,
 
74
    _FileMover,
 
75
    FinalPaths,
 
76
    resolve_conflicts,
 
77
    resolve_checkout,
 
78
    ROOT_PARENT,
 
79
    TransformPreview,
 
80
    TreeTransform,
 
81
)
58
82
 
59
83
 
60
84
class TestTreeTransform(tests.TestCaseWithTransport):
69
93
        self.addCleanup(transform.finalize)
70
94
        return transform, transform.root
71
95
 
 
96
    def get_transform_for_sha1_test(self):
 
97
        trans, root = self.get_transform()
 
98
        self.wt.lock_tree_write()
 
99
        self.addCleanup(self.wt.unlock)
 
100
        contents = ['just some content\n']
 
101
        sha1 = osutils.sha_strings(contents)
 
102
        # Roll back the clock
 
103
        trans._creation_mtime = time.time() - 20.0
 
104
        return trans, root, contents, sha1
 
105
 
72
106
    def test_existing_limbo(self):
73
107
        transform, root = self.get_transform()
74
108
        limbo_name = transform._limbodir
101
135
        imaginary_id = transform.trans_id_tree_path('imaginary')
102
136
        imaginary_id2 = transform.trans_id_tree_path('imaginary/')
103
137
        self.assertEqual(imaginary_id, imaginary_id2)
104
 
        self.assertEqual(transform.get_tree_parent(imaginary_id), root)
105
 
        self.assertEqual(transform.final_kind(root), 'directory')
106
 
        self.assertEqual(transform.final_file_id(root), self.wt.get_root_id())
 
138
        self.assertEqual(root, transform.get_tree_parent(imaginary_id))
 
139
        self.assertEqual('directory', transform.final_kind(root))
 
140
        self.assertEqual(self.wt.get_root_id(), transform.final_file_id(root))
107
141
        trans_id = transform.create_path('name', root)
108
142
        self.assertIs(transform.final_file_id(trans_id), None)
109
 
        self.assertRaises(NoSuchFile, transform.final_kind, trans_id)
 
143
        self.assertIs(None, transform.final_kind(trans_id))
110
144
        transform.create_file('contents', trans_id)
111
145
        transform.set_executability(True, trans_id)
112
146
        transform.version_file('my_pretties', trans_id)
137
171
        transform.finalize()
138
172
        transform.finalize()
139
173
 
 
174
    def test_apply_informs_tree_of_observed_sha1(self):
 
175
        trans, root, contents, sha1 = self.get_transform_for_sha1_test()
 
176
        trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
 
177
                                  sha1=sha1)
 
178
        calls = []
 
179
        orig = self.wt._observed_sha1
 
180
        def _observed_sha1(*args):
 
181
            calls.append(args)
 
182
            orig(*args)
 
183
        self.wt._observed_sha1 = _observed_sha1
 
184
        trans.apply()
 
185
        self.assertEqual([(None, 'file1', trans._observed_sha1s[trans_id])],
 
186
                         calls)
 
187
 
 
188
    def test_create_file_caches_sha1(self):
 
189
        trans, root, contents, sha1 = self.get_transform_for_sha1_test()
 
190
        trans_id = trans.create_path('file1', root)
 
191
        trans.create_file(contents, trans_id, sha1=sha1)
 
192
        st_val = osutils.lstat(trans._limbo_name(trans_id))
 
193
        o_sha1, o_st_val = trans._observed_sha1s[trans_id]
 
194
        self.assertEqual(o_sha1, sha1)
 
195
        self.assertEqualStat(o_st_val, st_val)
 
196
 
 
197
    def test__apply_insertions_updates_sha1(self):
 
198
        trans, root, contents, sha1 = self.get_transform_for_sha1_test()
 
199
        trans_id = trans.create_path('file1', root)
 
200
        trans.create_file(contents, trans_id, sha1=sha1)
 
201
        st_val = osutils.lstat(trans._limbo_name(trans_id))
 
202
        o_sha1, o_st_val = trans._observed_sha1s[trans_id]
 
203
        self.assertEqual(o_sha1, sha1)
 
204
        self.assertEqualStat(o_st_val, st_val)
 
205
        creation_mtime = trans._creation_mtime + 10.0
 
206
        # We fake a time difference from when the file was created until now it
 
207
        # is being renamed by using os.utime. Note that the change we actually
 
208
        # want to see is the real ctime change from 'os.rename()', but as long
 
209
        # as we observe a new stat value, we should be fine.
 
210
        os.utime(trans._limbo_name(trans_id), (creation_mtime, creation_mtime))
 
211
        trans.apply()
 
212
        new_st_val = osutils.lstat(self.wt.abspath('file1'))
 
213
        o_sha1, o_st_val = trans._observed_sha1s[trans_id]
 
214
        self.assertEqual(o_sha1, sha1)
 
215
        self.assertEqualStat(o_st_val, new_st_val)
 
216
        self.assertNotEqual(st_val.st_mtime, new_st_val.st_mtime)
 
217
 
 
218
    def test_new_file_caches_sha1(self):
 
219
        trans, root, contents, sha1 = self.get_transform_for_sha1_test()
 
220
        trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
 
221
                                  sha1=sha1)
 
222
        st_val = osutils.lstat(trans._limbo_name(trans_id))
 
223
        o_sha1, o_st_val = trans._observed_sha1s[trans_id]
 
224
        self.assertEqual(o_sha1, sha1)
 
225
        self.assertEqualStat(o_st_val, st_val)
 
226
 
 
227
    def test_cancel_creation_removes_observed_sha1(self):
 
228
        trans, root, contents, sha1 = self.get_transform_for_sha1_test()
 
229
        trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
 
230
                                  sha1=sha1)
 
231
        self.assertTrue(trans_id in trans._observed_sha1s)
 
232
        trans.cancel_creation(trans_id)
 
233
        self.assertFalse(trans_id in trans._observed_sha1s)
 
234
 
140
235
    def test_create_files_same_timestamp(self):
141
236
        transform, root = self.get_transform()
142
237
        self.wt.lock_tree_write()
792
887
        self.assertIs(None, self.wt.path2id('parent'))
793
888
        self.assertIs(None, self.wt.path2id('parent.new'))
794
889
 
 
890
    def test_resolve_conflicts_missing_parent(self):
 
891
        wt = self.make_branch_and_tree('.')
 
892
        tt = TreeTransform(wt)
 
893
        self.addCleanup(tt.finalize)
 
894
        parent = tt.trans_id_file_id('parent-id')
 
895
        tt.new_file('file', parent, 'Contents')
 
896
        raw_conflicts = resolve_conflicts(tt)
 
897
        # Since the directory doesn't exist it's seen as 'missing'.  So
 
898
        # 'resolve_conflicts' create a conflict asking for it to be created.
 
899
        self.assertLength(1, raw_conflicts)
 
900
        self.assertEqual(('missing parent', 'Created directory', 'new-1'),
 
901
                         raw_conflicts.pop())
 
902
        # apply fail since the missing directory doesn't exist
 
903
        self.assertRaises(errors.NoFinalPath, tt.apply)
 
904
 
795
905
    def test_moving_versioned_directories(self):
796
906
        create, root = self.get_transform()
797
907
        kansas = create.new_directory('kansas', root, 'kansas-id')
830
940
        rename.set_executability(True, myfile)
831
941
        rename.apply()
832
942
 
 
943
    def test_rename_fails(self):
 
944
        self.requireFeature(features.not_running_as_root)
 
945
        # see https://bugs.launchpad.net/bzr/+bug/491763
 
946
        create, root_id = self.get_transform()
 
947
        first_dir = create.new_directory('first-dir', root_id, 'first-id')
 
948
        myfile = create.new_file('myfile', root_id, 'myfile-text',
 
949
                                 'myfile-id')
 
950
        create.apply()
 
951
        if os.name == "posix" and sys.platform != "cygwin":
 
952
            # posix filesystems fail on renaming if the readonly bit is set
 
953
            osutils.make_readonly(self.wt.abspath('first-dir'))
 
954
        elif os.name == "nt":
 
955
            # windows filesystems fail on renaming open files
 
956
            self.addCleanup(file(self.wt.abspath('myfile')).close)
 
957
        else:
 
958
            self.skip("Don't know how to force a permissions error on rename")
 
959
        # now transform to rename
 
960
        rename_transform, root_id = self.get_transform()
 
961
        file_trans_id = rename_transform.trans_id_file_id('myfile-id')
 
962
        dir_id = rename_transform.trans_id_file_id('first-id')
 
963
        rename_transform.adjust_path('newname', dir_id, file_trans_id)
 
964
        e = self.assertRaises(errors.TransformRenameFailed,
 
965
            rename_transform.apply)
 
966
        # On nix looks like: 
 
967
        # "Failed to rename .../work/.bzr/checkout/limbo/new-1
 
968
        # to .../first-dir/newname: [Errno 13] Permission denied"
 
969
        # On windows looks like:
 
970
        # "Failed to rename .../work/myfile to 
 
971
        # .../work/.bzr/checkout/limbo/new-1: [Errno 13] Permission denied"
 
972
        # This test isn't concerned with exactly what the error looks like,
 
973
        # and the strerror will vary across OS and locales, but the assert
 
974
        # that the exeception attributes are what we expect
 
975
        self.assertEqual(e.errno, errno.EACCES)
 
976
        if os.name == "posix":
 
977
            self.assertEndsWith(e.to_path, "/first-dir/newname")
 
978
        else:
 
979
            self.assertEqual(os.path.basename(e.from_path), "myfile")
 
980
 
833
981
    def test_set_executability_order(self):
834
982
        """Ensure that executability behaves the same, no matter what order.
835
983
 
2091
2239
        self.assertRaises(errors.MalformedTransform, tt.commit, branch,
2092
2240
                          'message')
2093
2241
 
2094
 
 
2095
 
class MockTransform(object):
2096
 
 
2097
 
    def has_named_child(self, by_parent, parent_id, name):
2098
 
        for child_id in by_parent[parent_id]:
2099
 
            if child_id == '0':
2100
 
                if name == "name~":
2101
 
                    return True
2102
 
            elif name == "name.~%s~" % child_id:
2103
 
                return True
2104
 
        return False
2105
 
 
2106
 
 
2107
 
class MockEntry(object):
2108
 
    def __init__(self):
2109
 
        object.__init__(self)
2110
 
        self.name = "name"
2111
 
 
2112
 
 
2113
 
class TestGetBackupName(TestCase):
2114
 
    def test_get_backup_name(self):
 
2242
    def test_commit_rich_revision_data(self):
 
2243
        branch, tt = self.get_branch_and_transform()
 
2244
        rev_id = tt.commit(branch, 'message', timestamp=1, timezone=43201,
 
2245
                           committer='me <me@example.com>',
 
2246
                           revprops={'foo': 'bar'}, revision_id='revid-1',
 
2247
                           authors=['Author1 <author1@example.com>',
 
2248
                              'Author2 <author2@example.com>',
 
2249
                               ])
 
2250
        self.assertEqual('revid-1', rev_id)
 
2251
        revision = branch.repository.get_revision(rev_id)
 
2252
        self.assertEqual(1, revision.timestamp)
 
2253
        self.assertEqual(43201, revision.timezone)
 
2254
        self.assertEqual('me <me@example.com>', revision.committer)
 
2255
        self.assertEqual(['Author1 <author1@example.com>',
 
2256
                          'Author2 <author2@example.com>'],
 
2257
                         revision.get_apparent_authors())
 
2258
        del revision.properties['authors']
 
2259
        self.assertEqual({'foo': 'bar',
 
2260
                          'branch-nick': 'tree'},
 
2261
                         revision.properties)
 
2262
 
 
2263
    def test_no_explicit_revprops(self):
 
2264
        branch, tt = self.get_branch_and_transform()
 
2265
        rev_id = tt.commit(branch, 'message', authors=[
 
2266
            'Author1 <author1@example.com>',
 
2267
            'Author2 <author2@example.com>', ])
 
2268
        revision = branch.repository.get_revision(rev_id)
 
2269
        self.assertEqual(['Author1 <author1@example.com>',
 
2270
                          'Author2 <author2@example.com>'],
 
2271
                         revision.get_apparent_authors())
 
2272
        self.assertEqual('tree', revision.properties['branch-nick'])
 
2273
 
 
2274
 
 
2275
class TestBackupName(tests.TestCase):
 
2276
 
 
2277
    def test_deprecations(self):
 
2278
        class MockTransform(object):
 
2279
 
 
2280
            def has_named_child(self, by_parent, parent_id, name):
 
2281
                return name in by_parent.get(parent_id, [])
 
2282
 
 
2283
        class MockEntry(object):
 
2284
 
 
2285
            def __init__(self):
 
2286
                object.__init__(self)
 
2287
                self.name = "name"
 
2288
 
2115
2289
        tt = MockTransform()
2116
 
        name = get_backup_name(MockEntry(), {'a':[]}, 'a', tt)
2117
 
        self.assertEqual(name, 'name.~1~')
2118
 
        name = get_backup_name(MockEntry(), {'a':['1']}, 'a', tt)
2119
 
        self.assertEqual(name, 'name.~2~')
2120
 
        name = get_backup_name(MockEntry(), {'a':['2']}, 'a', tt)
2121
 
        self.assertEqual(name, 'name.~1~')
2122
 
        name = get_backup_name(MockEntry(), {'a':['2'], 'b':[]}, 'b', tt)
2123
 
        self.assertEqual(name, 'name.~1~')
2124
 
        name = get_backup_name(MockEntry(), {'a':['1', '2', '3']}, 'a', tt)
2125
 
        self.assertEqual(name, 'name.~4~')
 
2290
        name1 = self.applyDeprecated(
 
2291
            symbol_versioning.deprecated_in((2, 3, 0)),
 
2292
            transform.get_backup_name, MockEntry(), {'a':[]}, 'a', tt)
 
2293
        self.assertEqual('name.~1~', name1)
 
2294
        name2 = self.applyDeprecated(
 
2295
            symbol_versioning.deprecated_in((2, 3, 0)),
 
2296
            transform._get_backup_name, 'name', {'a':['name.~1~']}, 'a', tt)
 
2297
        self.assertEqual('name.~2~', name2)
2126
2298
 
2127
2299
 
2128
2300
class TestFileMover(tests.TestCaseWithTransport):
2243
2415
        self.failUnlessExists('a')
2244
2416
        self.failUnlessExists('a/b')
2245
2417
 
2246
 
    def test_resolve_no_parent(self):
 
2418
 
 
2419
class TestTransformMissingParent(tests.TestCaseWithTransport):
 
2420
 
 
2421
    def make_tt_with_versioned_dir(self):
2247
2422
        wt = self.make_branch_and_tree('.')
 
2423
        self.build_tree(['dir/',])
 
2424
        wt.add(['dir'], ['dir-id'])
 
2425
        wt.commit('Create dir')
2248
2426
        tt = TreeTransform(wt)
2249
2427
        self.addCleanup(tt.finalize)
2250
 
        parent = tt.trans_id_file_id('parent-id')
2251
 
        tt.new_file('file', parent, 'Contents')
2252
 
        resolve_conflicts(tt)
 
2428
        return wt, tt
 
2429
 
 
2430
    def test_resolve_create_parent_for_versioned_file(self):
 
2431
        wt, tt = self.make_tt_with_versioned_dir()
 
2432
        dir_tid = tt.trans_id_tree_file_id('dir-id')
 
2433
        file_tid = tt.new_file('file', dir_tid, 'Contents', file_id='file-id')
 
2434
        tt.delete_contents(dir_tid)
 
2435
        tt.unversion_file(dir_tid)
 
2436
        conflicts = resolve_conflicts(tt)
 
2437
        # one conflict for the missing directory, one for the unversioned
 
2438
        # parent
 
2439
        self.assertLength(2, conflicts)
 
2440
 
 
2441
    def test_non_versioned_file_create_conflict(self):
 
2442
        wt, tt = self.make_tt_with_versioned_dir()
 
2443
        dir_tid = tt.trans_id_tree_file_id('dir-id')
 
2444
        tt.new_file('file', dir_tid, 'Contents')
 
2445
        tt.delete_contents(dir_tid)
 
2446
        tt.unversion_file(dir_tid)
 
2447
        conflicts = resolve_conflicts(tt)
 
2448
        # no conflicts or rather: orphaning 'file' resolve the 'dir' conflict
 
2449
        self.assertLength(1, conflicts)
 
2450
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
 
2451
                         conflicts.pop())
2253
2452
 
2254
2453
 
2255
2454
A_ENTRY = ('a-id', ('a', 'a'), True, (True, True),
2256
2455
                  ('TREE_ROOT', 'TREE_ROOT'), ('a', 'a'), ('file', 'file'),
2257
2456
                  (False, False))
2258
2457
ROOT_ENTRY = ('TREE_ROOT', ('', ''), False, (True, True), (None, None),
2259
 
              ('', ''), ('directory', 'directory'), (False, None))
 
2458
              ('', ''), ('directory', 'directory'), (False, False))
2260
2459
 
2261
2460
 
2262
2461
class TestTransformPreview(tests.TestCaseWithTransport):
2349
2548
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2350
2549
        changes = preview_tree.iter_changes(revision_tree,
2351
2550
                                            specific_files=[''])
2352
 
        self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
 
2551
        self.assertEqual([A_ENTRY], list(changes))
2353
2552
 
2354
2553
    def test_want_unversioned(self):
2355
2554
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2356
2555
        changes = preview_tree.iter_changes(revision_tree,
2357
2556
                                            want_unversioned=True)
2358
 
        self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
 
2557
        self.assertEqual([A_ENTRY], list(changes))
2359
2558
 
2360
2559
    def test_ignore_extra_trees_no_specific_files(self):
2361
2560
        # extra_trees is harmless without specific_files, so we'll silently
3132
3331
        trans_id = tt.trans_id_tree_path('file')
3133
3332
        self.assertEqual((LINES_ONE,),
3134
3333
            tt._get_parents_texts(trans_id))
 
3334
 
 
3335
 
 
3336
class TestOrphan(tests.TestCaseWithTransport):
 
3337
 
 
3338
    def test_no_orphan_for_transform_preview(self):
 
3339
        tree = self.make_branch_and_tree('tree')
 
3340
        tt = transform.TransformPreview(tree)
 
3341
        self.addCleanup(tt.finalize)
 
3342
        self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
 
3343
 
 
3344
    def _set_orphan_policy(self, wt, policy):
 
3345
        wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
 
3346
                                               policy)
 
3347
 
 
3348
    def _prepare_orphan(self, wt):
 
3349
        self.build_tree(['dir/', 'dir/file', 'dir/foo'])
 
3350
        wt.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
 
3351
        wt.commit('add dir and file ignoring foo')
 
3352
        tt = transform.TreeTransform(wt)
 
3353
        self.addCleanup(tt.finalize)
 
3354
        # dir and bar are deleted
 
3355
        dir_tid = tt.trans_id_tree_path('dir')
 
3356
        file_tid = tt.trans_id_tree_path('dir/file')
 
3357
        orphan_tid = tt.trans_id_tree_path('dir/foo')
 
3358
        tt.delete_contents(file_tid)
 
3359
        tt.unversion_file(file_tid)
 
3360
        tt.delete_contents(dir_tid)
 
3361
        tt.unversion_file(dir_tid)
 
3362
        # There should be a conflict because dir still contain foo
 
3363
        raw_conflicts = tt.find_conflicts()
 
3364
        self.assertLength(1, raw_conflicts)
 
3365
        self.assertEqual(('missing parent', 'new-1'), raw_conflicts[0])
 
3366
        return tt, orphan_tid
 
3367
 
 
3368
    def test_new_orphan_created(self):
 
3369
        wt = self.make_branch_and_tree('.')
 
3370
        self._set_orphan_policy(wt, 'move')
 
3371
        tt, orphan_tid = self._prepare_orphan(wt)
 
3372
        warnings = []
 
3373
        def warning(*args):
 
3374
            warnings.append(args[0] % args[1:])
 
3375
        self.overrideAttr(trace, 'warning', warning)
 
3376
        remaining_conflicts = resolve_conflicts(tt)
 
3377
        self.assertEquals(['dir/foo has been orphaned in bzr-orphans'],
 
3378
                          warnings)
 
3379
        # Yeah for resolved conflicts !
 
3380
        self.assertLength(0, remaining_conflicts)
 
3381
        # We have a new orphan
 
3382
        self.assertEquals('foo.~1~', tt.final_name(orphan_tid))
 
3383
        self.assertEquals('bzr-orphans',
 
3384
                          tt.final_name(tt.final_parent(orphan_tid)))
 
3385
 
 
3386
    def test_never_orphan(self):
 
3387
        wt = self.make_branch_and_tree('.')
 
3388
        self._set_orphan_policy(wt, 'conflict')
 
3389
        tt, orphan_tid = self._prepare_orphan(wt)
 
3390
        remaining_conflicts = resolve_conflicts(tt)
 
3391
        self.assertLength(1, remaining_conflicts)
 
3392
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
 
3393
                         remaining_conflicts.pop())
 
3394
 
 
3395
    def test_orphan_error(self):
 
3396
        def bogus_orphan(tt, orphan_id, parent_id):
 
3397
            raise transform.OrphaningError(tt.final_name(orphan_id),
 
3398
                                           tt.final_name(parent_id))
 
3399
        transform.orphaning_registry.register('bogus', bogus_orphan,
 
3400
                                              'Raise an error when orphaning')
 
3401
        wt = self.make_branch_and_tree('.')
 
3402
        self._set_orphan_policy(wt, 'bogus')
 
3403
        tt, orphan_tid = self._prepare_orphan(wt)
 
3404
        remaining_conflicts = resolve_conflicts(tt)
 
3405
        self.assertLength(1, remaining_conflicts)
 
3406
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
 
3407
                         remaining_conflicts.pop())
 
3408
 
 
3409
    def test_unknown_orphan_policy(self):
 
3410
        wt = self.make_branch_and_tree('.')
 
3411
        # Set a fictional policy nobody ever implemented
 
3412
        self._set_orphan_policy(wt, 'donttouchmypreciouuus')
 
3413
        tt, orphan_tid = self._prepare_orphan(wt)
 
3414
        warnings = []
 
3415
        def warning(*args):
 
3416
            warnings.append(args[0] % args[1:])
 
3417
        self.overrideAttr(trace, 'warning', warning)
 
3418
        remaining_conflicts = resolve_conflicts(tt)
 
3419
        # We fallback to the default policy which create a conflict
 
3420
        self.assertLength(1, remaining_conflicts)
 
3421
        self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
 
3422
                         remaining_conflicts.pop())
 
3423
        self.assertLength(1, warnings)
 
3424
        self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')