/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 breezy/tests/test_subsume.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
                         'tree/subtree/',
32
32
                         'tree/subtree/file2'])
33
33
        base_tree = self.make_branch_and_tree('tree', format=format)
34
 
        base_tree.add('file', b'file-id')
35
 
        base_tree.commit('first commit', rev_id=b'tree-1')
 
34
        base_tree.add('file', 'file-id')
 
35
        base_tree.commit('first commit', rev_id='tree-1')
36
36
        sub_tree = self.make_branch_and_tree('tree/subtree',
37
 
                                             format='development-subtree')
 
37
            format='development-subtree')
38
38
        if same_root is True:
39
 
            sub_tree.set_root_id(base_tree.path2id(''))
40
 
        sub_tree.add('file2', b'file2-id')
41
 
        sub_tree.commit('first commit', rev_id=b'subtree-1')
 
39
            sub_tree.set_root_id(base_tree.get_root_id())
 
40
        sub_tree.add('file2', 'file2-id')
 
41
        sub_tree.commit('first commit', rev_id='subtree-1')
42
42
        return base_tree, sub_tree
43
43
 
44
44
    def test_old_knit1_failure(self):
59
59
 
60
60
    def test_subsume_tree(self):
61
61
        base_tree, sub_tree = self.make_trees()
62
 
        self.assertNotEqual(base_tree.path2id(''), sub_tree.path2id(''))
63
 
        sub_root_id = sub_tree.path2id('')
 
62
        self.assertNotEqual(base_tree.get_root_id(), sub_tree.get_root_id())
 
63
        sub_root_id = sub_tree.get_root_id()
64
64
        # this test checks the subdir is removed, so it needs to know the
65
65
        # control directory; that changes rarely so just hardcode (and check)
66
66
        # it is correct.
67
67
        self.assertPathExists('tree/subtree/.bzr')
68
68
        base_tree.subsume(sub_tree)
69
 
        self.assertEqual([b'tree-1', b'subtree-1'], base_tree.get_parent_ids())
 
69
        self.assertEqual(['tree-1', 'subtree-1'], base_tree.get_parent_ids())
70
70
        self.assertEqual(sub_root_id, base_tree.path2id('subtree'))
71
 
        self.assertEqual(b'file2-id', base_tree.path2id('subtree/file2'))
 
71
        self.assertEqual('file2-id', base_tree.path2id('subtree/file2'))
72
72
        # subsuming the tree removes the control directory, so you can't open
73
73
        # it.
74
74
        self.assertPathDoesNotExist('tree/subtree/.bzr')
75
 
        with open('tree/subtree/file2', 'rb') as file2:
 
75
        file2 = open('tree/subtree/file2', 'rb')
 
76
        try:
76
77
            file2_contents = file2.read()
 
78
        finally:
 
79
            file2.close()
77
80
        base_tree = workingtree.WorkingTree.open('tree')
78
 
        base_tree.commit('combined', rev_id=b'combined-1')
79
 
        self.assertEqual(b'file2-id', base_tree.path2id('subtree/file2'))
80
 
        if base_tree.supports_setting_file_ids():
81
 
            self.assertEqual('subtree/file2', base_tree.id2path(b'file2-id'))
 
81
        base_tree.commit('combined', rev_id='combined-1')
 
82
        self.assertEqual('file2-id', base_tree.path2id('subtree/file2'))
 
83
        self.assertEqual('subtree/file2', base_tree.id2path('file2-id'))
82
84
        self.assertEqualDiff(file2_contents,
83
 
                             base_tree.get_file_text('subtree/file2'))
 
85
                             base_tree.get_file_text('file2-id'))
84
86
        basis_tree = base_tree.basis_tree()
85
87
        basis_tree.lock_read()
86
88
        self.addCleanup(basis_tree.unlock)
87
89
        self.assertEqualDiff(file2_contents,
88
 
                             base_tree.get_file_text('subtree/file2'))
 
90
                             base_tree.get_file_text('file2-id'))
89
91
        self.assertEqualDiff(file2_contents,
90
 
                             basis_tree.get_file_text('subtree/file2'))
91
 
        self.assertEqual(b'subtree-1',
92
 
                         basis_tree.get_file_revision('subtree/file2'))
93
 
        self.assertEqual(b'combined-1',
94
 
                         basis_tree.get_file_revision('subtree'))
 
92
                             basis_tree.get_file_text('file2-id'))
 
93
        self.assertEqual('subtree-1',
 
94
                         basis_tree.get_file_revision('file2-id'))
 
95
        self.assertEqual('combined-1',
 
96
                         basis_tree.get_file_revision(sub_root_id))
95
97
 
96
98
    def test_subsume_failure(self):
97
99
        base_tree, sub_tree = self.make_trees()
98
 
        if base_tree.path2id('') == sub_tree.path2id(''):
 
100
        if base_tree.get_root_id() == sub_tree.get_root_id():
99
101
            raise tests.TestSkipped('This test requires unique roots')
 
102
        sub_root_id = sub_tree.get_root_id()
100
103
        self.assertRaises(errors.BadSubsumeSource, base_tree.subsume,
101
104
                          base_tree)
102
105
        self.assertRaises(errors.BadSubsumeSource, sub_tree.subsume,