/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/test_transform.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import errno
18
18
import os
19
 
from StringIO import StringIO
20
19
import sys
21
20
import time
22
21
 
23
 
from bzrlib import (
 
22
from .. import (
24
23
    bencode,
25
24
    errors,
26
25
    filters,
34
33
    transform,
35
34
    urlutils,
36
35
    )
37
 
from bzrlib.conflicts import (
 
36
from ..conflicts import (
38
37
    DeletingParent,
39
38
    DuplicateEntry,
40
39
    DuplicateID,
43
42
    ParentLoop,
44
43
    UnversionedParent,
45
44
)
46
 
from bzrlib.controldir import ControlDir
47
 
from bzrlib.diff import show_diff_trees
48
 
from bzrlib.errors import (
 
45
from ..controldir import ControlDir
 
46
from ..diff import show_diff_trees
 
47
from ..errors import (
49
48
    DuplicateKey,
50
49
    ExistingLimbo,
51
50
    ExistingPendingDeletion,
55
54
    MalformedTransform,
56
55
    ReusingTransform,
57
56
)
58
 
from bzrlib.osutils import (
 
57
from ..osutils import (
59
58
    file_kind,
60
59
    pathjoin,
61
60
)
62
 
from bzrlib.merge import Merge3Merger, Merger
63
 
from bzrlib.mutabletree import MutableTree
64
 
from bzrlib.tests import (
 
61
from ..merge import Merge3Merger, Merger
 
62
from ..mutabletree import MutableTree
 
63
from ..sixish import (
 
64
    BytesIO,
 
65
    )
 
66
from . import (
65
67
    features,
66
68
    TestCaseInTempDir,
67
69
    TestSkipped,
68
70
    )
69
 
from bzrlib.tests.features import (
 
71
from .features import (
70
72
    HardlinkFeature,
71
73
    SymlinkFeature,
72
74
    )
73
 
from bzrlib.transform import (
 
75
from ..transform import (
74
76
    build_tree,
75
77
    create_from_tree,
76
78
    cook_conflicts,
685
687
 
686
688
    def test_both_rename2(self):
687
689
        create_tree,root = self.get_transform()
688
 
        bzrlib = create_tree.new_directory('bzrlib', root, 'bzrlib-id')
689
 
        tests = create_tree.new_directory('tests', bzrlib, 'tests-id')
 
690
        breezy = create_tree.new_directory('breezy', root, 'breezy-id')
 
691
        tests = create_tree.new_directory('tests', breezy, 'tests-id')
690
692
        blackbox = create_tree.new_directory('blackbox', tests, 'blackbox-id')
691
693
        create_tree.new_file('test_too_much.py', blackbox, 'hello1',
692
694
                             'test_too_much-id')
693
695
        create_tree.apply()
694
696
        mangle_tree,root = self.get_transform()
695
 
        bzrlib = mangle_tree.trans_id_tree_file_id('bzrlib-id')
 
697
        breezy = mangle_tree.trans_id_tree_file_id('breezy-id')
696
698
        tests = mangle_tree.trans_id_tree_file_id('tests-id')
697
699
        test_too_much = mangle_tree.trans_id_tree_file_id('test_too_much-id')
698
 
        mangle_tree.adjust_path('selftest', bzrlib, tests)
 
700
        mangle_tree.adjust_path('selftest', breezy, tests)
699
701
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much)
700
702
        mangle_tree.set_executability(True, test_too_much)
701
703
        mangle_tree.apply()
913
915
    def test_resolve_conflicts_wrong_existing_parent_kind(self):
914
916
        tt = self.prepare_wrong_parent_kind()
915
917
        raw_conflicts = resolve_conflicts(tt)
916
 
        self.assertEqual(set([('non-directory parent', 'Created directory',
917
 
                         'new-3')]), raw_conflicts)
 
918
        self.assertEqual({('non-directory parent', 'Created directory',
 
919
                         'new-3')}, raw_conflicts)
918
920
        cooked_conflicts = cook_conflicts(raw_conflicts, tt)
919
921
        self.assertEqual([NonDirectoryParent('Created directory', 'parent.new',
920
922
        'parent-id')], cooked_conflicts)
932
934
        tt.delete_contents(parent_id)
933
935
        tt.create_file('contents', parent_id)
934
936
        raw_conflicts = resolve_conflicts(tt)
935
 
        self.assertEqual(set([('non-directory parent', 'Created directory',
936
 
                         'new-3')]), raw_conflicts)
 
937
        self.assertEqual({('non-directory parent', 'Created directory',
 
938
                         'new-3')}, raw_conflicts)
937
939
        tt.apply()
938
940
        self.assertEqual(None, self.wt.path2id('parent'))
939
941
        self.assertEqual('parent-id', self.wt.path2id('parent.new'))
1020
1022
            # windows filesystems fail on renaming open files
1021
1023
            self.addCleanup(file(self.wt.abspath('myfile')).close)
1022
1024
        else:
1023
 
            self.skip("Don't know how to force a permissions error on rename")
 
1025
            self.skipTest("Can't force a permissions error on rename")
1024
1026
        # now transform to rename
1025
1027
        rename_transform, root_id = self.get_transform()
1026
1028
        file_trans_id = rename_transform.trans_id_file_id('myfile-id')
2455
2457
        mover.rename('c/e', 'c/d')
2456
2458
        try:
2457
2459
            mover.rename('a', 'c')
2458
 
        except errors.FileExists, e:
 
2460
        except errors.FileExists as e:
2459
2461
            mover.rollback()
2460
2462
        self.assertPathExists('a')
2461
2463
        self.assertPathExists('c/d')
2536
2538
    def _override_globals_in_method(self, instance, method_name, globals):
2537
2539
        """Replace method on instance with one with updated globals"""
2538
2540
        import types
2539
 
        func = getattr(instance, method_name).im_func
2540
 
        new_globals = dict(func.func_globals)
 
2541
        func = getattr(instance, method_name).__func__
 
2542
        new_globals = dict(func.__globals__)
2541
2543
        new_globals.update(globals)
2542
 
        new_func = types.FunctionType(func.func_code, new_globals,
2543
 
            func.func_name, func.func_defaults)
 
2544
        new_func = types.FunctionType(func.__code__, new_globals,
 
2545
            func.__name__, func.__defaults__)
2544
2546
        setattr(instance, method_name,
2545
2547
            types.MethodType(new_func, instance, instance.__class__))
2546
2548
        self.addCleanup(delattr, instance, method_name)
2740
2742
        self.addCleanup(preview.finalize)
2741
2743
        preview.new_file('file2', preview.root, 'content B\n', 'file2-id')
2742
2744
        preview_tree = preview.get_preview_tree()
2743
 
        out = StringIO()
 
2745
        out = BytesIO()
2744
2746
        show_diff_trees(revision_tree, preview_tree, out)
2745
2747
        lines = out.getvalue().splitlines()
2746
2748
        self.assertEqual(lines[0], "=== added file 'file2'")
2882
2884
        preview.unversion_file(c_trans_id)
2883
2885
        preview.version_file('c-id', c_trans_id)
2884
2886
        preview_tree = preview.get_preview_tree()
2885
 
        self.assertEqual(set(['a-id', 'c-id', tree.get_root_id()]),
 
2887
        self.assertEqual({'a-id', 'c-id', tree.get_root_id()},
2886
2888
                         preview_tree.all_file_ids())
2887
2889
 
2888
2890
    def test_path2id_deleted_unchanged(self):
3208
3210
                         'new-versioned-id')
3209
3211
        tree = preview.get_preview_tree()
3210
3212
        preview.unversion_file(preview.trans_id_tree_path('removed-file'))
3211
 
        self.assertEqual(set(['new-file', 'removed-file', 'existing-file']),
 
3213
        self.assertEqual({'new-file', 'removed-file', 'existing-file'},
3212
3214
                         set(tree.extras()))
3213
3215
 
3214
3216
    def test_merge_into_preview(self):
3468
3470
        self.assertEqual({'new-1': u'foo\u1234',
3469
3471
                          'new-2': 'bar',
3470
3472
                          tt.root: ''}, tt._tree_id_paths)
3471
 
        self.assertEqual(set(['new-1']), tt._removed_id)
3472
 
        self.assertEqual(set(['new-2']), tt._removed_contents)
 
3473
        self.assertEqual({'new-1'}, tt._removed_id)
 
3474
        self.assertEqual({'new-2'}, tt._removed_contents)
3473
3475
 
3474
3476
    def missing_records(self):
3475
3477
        attribs = self.default_attribs()