/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: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

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