/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_status.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
 
18
 
18
19
from .. import (
19
20
    config,
20
21
    status as _mod_status,
21
22
    )
22
23
from ..revisionspec import RevisionSpec
23
24
from ..sixish import (
24
 
    StringIO,
 
25
    BytesIO,
25
26
    )
26
27
from ..status import show_pending_merges, show_tree_status
27
28
from . import TestCaseWithTransport
35
36
        tree.commit('empty commit')
36
37
        tree2 = self.make_branch_and_tree('b')
37
38
        # set a left most parent that is not a present commit
38
 
        tree2.add_parent_tree_id(b'some-ghost', allow_leftmost_as_ghost=True)
 
39
        tree2.add_parent_tree_id('some-ghost', allow_leftmost_as_ghost=True)
39
40
        # do a merge
40
41
        tree2.merge_from_branch(tree.branch)
41
 
        output = StringIO()
42
 
        with tree2.lock_read():
 
42
        output = BytesIO()
 
43
        tree2.lock_read()
 
44
        try:
43
45
            show_pending_merges(tree2, output)
 
46
        finally:
 
47
            tree2.unlock()
44
48
        self.assertContainsRe(output.getvalue(), 'empty commit')
45
49
 
46
50
    def make_multiple_pending_tree(self):
59
63
 
60
64
    def test_multiple_pending(self):
61
65
        tree = self.make_multiple_pending_tree()
62
 
        output = StringIO()
 
66
        output = BytesIO()
63
67
        tree.lock_read()
64
68
        self.addCleanup(tree.unlock)
65
69
        show_pending_merges(tree, output)
72
76
 
73
77
    def test_multiple_pending_verbose(self):
74
78
        tree = self.make_multiple_pending_tree()
75
 
        output = StringIO()
 
79
        output = BytesIO()
76
80
        tree.lock_read()
77
81
        self.addCleanup(tree.unlock)
78
82
        show_pending_merges(tree, output, verbose=True)
88
92
        """Test when a pending merge is itself a ghost"""
89
93
        tree = self.make_branch_and_tree('a')
90
94
        tree.commit('first')
91
 
        tree.add_parent_tree_id(b'a-ghost-revision')
 
95
        tree.add_parent_tree_id('a-ghost-revision')
92
96
        tree.lock_read()
93
97
        self.addCleanup(tree.unlock)
94
 
        output = StringIO()
 
98
        output = BytesIO()
95
99
        show_pending_merges(tree, output)
96
100
        self.assertEqualDiff(
97
101
            'pending merge tips: (use -v to see all merge revisions)\n'
105
109
        tree.commit('empty commit')
106
110
        tree2 = tree.controldir.clone('b').open_workingtree()
107
111
        tree2.commit('a non-ghost', timestamp=1196796819, timezone=0)
108
 
        tree2.add_parent_tree_id(b'a-ghost-revision')
 
112
        tree2.add_parent_tree_id('a-ghost-revision')
109
113
        tree2.commit('commit with ghost', timestamp=1196796819, timezone=0)
110
114
        tree2.commit('another non-ghost', timestamp=1196796819, timezone=0)
111
115
        tree.merge_from_branch(tree2.branch)
112
116
        tree.lock_read()
113
117
        self.addCleanup(tree.unlock)
114
 
        output = StringIO()
 
118
        output = BytesIO()
115
119
        show_pending_merges(tree, output, verbose=True)
116
 
        self.assertEqualDiff(
117
 
            'pending merges:\n'
118
 
            '  Joe Foo 2007-12-04 another non-ghost\n'
119
 
            '    Joe Foo 2007-12-04 [merge] commit with ghost\n'
120
 
            '    (ghost) a-ghost-revision\n'
121
 
            '    Joe Foo 2007-12-04 a non-ghost\n',
122
 
            output.getvalue())
 
120
        self.assertEqualDiff('pending merges:\n'
 
121
                             '  Joe Foo 2007-12-04 another non-ghost\n'
 
122
                             '    Joe Foo 2007-12-04 [merge] commit with ghost\n'
 
123
                             '    (ghost) a-ghost-revision\n'
 
124
                             '    Joe Foo 2007-12-04 a non-ghost\n',
 
125
                             output.getvalue())
123
126
 
124
127
    def tests_revision_to_revision(self):
125
128
        """doing a status between two revision trees should work."""
126
129
        tree = self.make_branch_and_tree('.')
127
130
        r1_id = tree.commit('one', allow_pointless=True)
128
131
        r2_id = tree.commit('two', allow_pointless=True)
129
 
        output = StringIO()
130
 
        show_tree_status(tree, to_file=output, revision=[
131
 
            RevisionSpec.from_string("revid:%s" % r1_id.decode('utf-8')),
132
 
            RevisionSpec.from_string("revid:%s" % r2_id.decode('utf-8'))])
 
132
        r2_tree = tree.branch.repository.revision_tree(r2_id)
 
133
        output = BytesIO()
 
134
        show_tree_status(tree, to_file=output,
 
135
                     revision=[RevisionSpec.from_string("revid:%s" % r1_id),
 
136
                               RevisionSpec.from_string("revid:%s" % r2_id)])
133
137
        # return does not matter as long as it did not raise.
134
138
 
135
139
 
139
143
        """Check that creating a StatusHooks instance has the right defaults.
140
144
        """
141
145
        hooks = _mod_status.StatusHooks()
142
 
        self.assertTrue("post_status" in hooks,
143
 
                        "post_status not in %s" % hooks)
 
146
        self.assertTrue("post_status" in hooks, "post_status not in %s" % hooks)
144
147
        self.assertTrue("pre_status" in hooks, "pre_status not in %s" % hooks)
145
148
 
146
149
    def test_installed_hooks_are_StatusHooks(self):
148
151
        """
149
152
        # the installed hooks are saved in self._preserved_hooks.
150
153
        self.assertIsInstance(self._preserved_hooks[_mod_status][1],
151
 
                              _mod_status.StatusHooks)
 
154
            _mod_status.StatusHooks)
152
155
 
153
156
    def test_post_status_hook(self):
154
157
        """Ensure that post_status hook is invoked with the right args.
159
162
        tree = self.make_branch_and_tree('.')
160
163
        r1_id = tree.commit('one', allow_pointless=True)
161
164
        r2_id = tree.commit('two', allow_pointless=True)
162
 
        output = StringIO()
163
 
        show_tree_status(tree, to_file=output, revision=[
164
 
            RevisionSpec.from_string("revid:%s" % r1_id.decode('utf-8')),
165
 
            RevisionSpec.from_string("revid:%s" % r2_id.decode('utf-8'))])
 
165
        r2_tree = tree.branch.repository.revision_tree(r2_id)
 
166
        output = BytesIO()
 
167
        show_tree_status(tree, to_file=output,
 
168
            revision=[RevisionSpec.from_string("revid:%s" % r1_id),
 
169
                RevisionSpec.from_string("revid:%s" % r2_id)])
166
170
        self.assertLength(1, calls)
167
171
        params = calls[0]
168
172
        self.assertIsInstance(params, _mod_status.StatusHookParams)
169
173
        attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
170
 
                 'show_ids', 'short', 'verbose', 'specific_files']
 
174
            'show_ids', 'short', 'verbose', 'specific_files']
171
175
        for a in attrs:
172
176
            self.assertTrue(hasattr(params, a),
173
 
                            'Attribute "%s" not found in StatusHookParam' % a)
 
177
                'Attribute "%s" not found in StatusHookParam' % a)
174
178
 
175
179
    def test_pre_status_hook(self):
176
180
        """Ensure that pre_status hook is invoked with the right args.
181
185
        tree = self.make_branch_and_tree('.')
182
186
        r1_id = tree.commit('one', allow_pointless=True)
183
187
        r2_id = tree.commit('two', allow_pointless=True)
184
 
        output = StringIO()
185
 
        show_tree_status(
186
 
            tree, to_file=output,
187
 
            revision=[
188
 
                RevisionSpec.from_string("revid:%s" % r1_id.decode('utf-8')),
189
 
                RevisionSpec.from_string("revid:%s" % r2_id.decode('utf-8'))])
 
188
        r2_tree = tree.branch.repository.revision_tree(r2_id)
 
189
        output = BytesIO()
 
190
        show_tree_status(tree, to_file=output,
 
191
            revision=[RevisionSpec.from_string("revid:%s" % r1_id),
 
192
                RevisionSpec.from_string("revid:%s" % r2_id)])
190
193
        self.assertLength(1, calls)
191
194
        params = calls[0]
192
195
        self.assertIsInstance(params, _mod_status.StatusHookParams)
193
196
        attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
194
 
                 'show_ids', 'short', 'verbose', 'specific_files']
 
197
            'show_ids', 'short', 'verbose', 'specific_files']
195
198
        for a in attrs:
196
199
            self.assertTrue(hasattr(params, a),
197
 
                            'Attribute "%s" not found in StatusHookParam' % a)
 
200
                'Attribute "%s" not found in StatusHookParam' % a)
 
201