/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 brzlib/tests/test_status.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

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
 
from io import StringIO
18
 
 
19
 
from .. import (
 
17
 
 
18
from StringIO import StringIO
 
19
 
 
20
from brzlib import (
20
21
    config,
21
22
    status as _mod_status,
22
23
    )
23
 
from ..revisionspec import RevisionSpec
24
 
from ..status import show_pending_merges, show_tree_status
25
 
from . import TestCaseWithTransport
 
24
from brzlib.revisionspec import RevisionSpec
 
25
from brzlib.status import show_pending_merges, show_tree_status
 
26
from brzlib.tests import TestCaseWithTransport
26
27
 
27
28
 
28
29
class TestStatus(TestCaseWithTransport):
33
34
        tree.commit('empty commit')
34
35
        tree2 = self.make_branch_and_tree('b')
35
36
        # set a left most parent that is not a present commit
36
 
        tree2.add_parent_tree_id(b'some-ghost', allow_leftmost_as_ghost=True)
 
37
        tree2.add_parent_tree_id('some-ghost', allow_leftmost_as_ghost=True)
37
38
        # do a merge
38
39
        tree2.merge_from_branch(tree.branch)
39
40
        output = StringIO()
40
 
        with tree2.lock_read():
 
41
        tree2.lock_read()
 
42
        try:
41
43
            show_pending_merges(tree2, output)
 
44
        finally:
 
45
            tree2.unlock()
42
46
        self.assertContainsRe(output.getvalue(), 'empty commit')
43
47
 
44
48
    def make_multiple_pending_tree(self):
45
49
        config.GlobalStack().set('email', 'Joe Foo <joe@foo.com>')
46
50
        tree = self.make_branch_and_tree('a')
47
51
        tree.commit('commit 1', timestamp=1196796819, timezone=0)
48
 
        tree2 = tree.controldir.clone('b').open_workingtree()
 
52
        tree2 = tree.bzrdir.clone('b').open_workingtree()
49
53
        tree.commit('commit 2', timestamp=1196796819, timezone=0)
50
54
        tree2.commit('commit 2b', timestamp=1196796819, timezone=0)
51
 
        tree3 = tree2.controldir.clone('c').open_workingtree()
 
55
        tree3 = tree2.bzrdir.clone('c').open_workingtree()
52
56
        tree2.commit('commit 3b', timestamp=1196796819, timezone=0)
53
57
        tree3.commit('commit 3c', timestamp=1196796819, timezone=0)
54
58
        tree.merge_from_branch(tree2.branch)
86
90
        """Test when a pending merge is itself a ghost"""
87
91
        tree = self.make_branch_and_tree('a')
88
92
        tree.commit('first')
89
 
        tree.add_parent_tree_id(b'a-ghost-revision')
 
93
        tree.add_parent_tree_id('a-ghost-revision')
90
94
        tree.lock_read()
91
95
        self.addCleanup(tree.unlock)
92
96
        output = StringIO()
101
105
        config.GlobalStack().set('email', 'Joe Foo <joe@foo.com>')
102
106
        tree = self.make_branch_and_tree('a')
103
107
        tree.commit('empty commit')
104
 
        tree2 = tree.controldir.clone('b').open_workingtree()
 
108
        tree2 = tree.bzrdir.clone('b').open_workingtree()
105
109
        tree2.commit('a non-ghost', timestamp=1196796819, timezone=0)
106
 
        tree2.add_parent_tree_id(b'a-ghost-revision')
 
110
        tree2.add_parent_tree_id('a-ghost-revision')
107
111
        tree2.commit('commit with ghost', timestamp=1196796819, timezone=0)
108
112
        tree2.commit('another non-ghost', timestamp=1196796819, timezone=0)
109
113
        tree.merge_from_branch(tree2.branch)
111
115
        self.addCleanup(tree.unlock)
112
116
        output = StringIO()
113
117
        show_pending_merges(tree, output, verbose=True)
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())
 
118
        self.assertEqualDiff('pending merges:\n'
 
119
                             '  Joe Foo 2007-12-04 another non-ghost\n'
 
120
                             '    Joe Foo 2007-12-04 [merge] commit with ghost\n'
 
121
                             '    (ghost) a-ghost-revision\n'
 
122
                             '    Joe Foo 2007-12-04 a non-ghost\n',
 
123
                             output.getvalue())
121
124
 
122
125
    def tests_revision_to_revision(self):
123
126
        """doing a status between two revision trees should work."""
124
127
        tree = self.make_branch_and_tree('.')
125
128
        r1_id = tree.commit('one', allow_pointless=True)
126
129
        r2_id = tree.commit('two', allow_pointless=True)
 
130
        r2_tree = tree.branch.repository.revision_tree(r2_id)
127
131
        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'))])
 
132
        show_tree_status(tree, to_file=output,
 
133
                     revision=[RevisionSpec.from_string("revid:%s" % r1_id),
 
134
                               RevisionSpec.from_string("revid:%s" % r2_id)])
131
135
        # return does not matter as long as it did not raise.
132
136
 
133
137
 
137
141
        """Check that creating a StatusHooks instance has the right defaults.
138
142
        """
139
143
        hooks = _mod_status.StatusHooks()
140
 
        self.assertTrue("post_status" in hooks,
141
 
                        "post_status not in %s" % hooks)
 
144
        self.assertTrue("post_status" in hooks, "post_status not in %s" % hooks)
142
145
        self.assertTrue("pre_status" in hooks, "pre_status not in %s" % hooks)
143
146
 
144
147
    def test_installed_hooks_are_StatusHooks(self):
146
149
        """
147
150
        # the installed hooks are saved in self._preserved_hooks.
148
151
        self.assertIsInstance(self._preserved_hooks[_mod_status][1],
149
 
                              _mod_status.StatusHooks)
 
152
            _mod_status.StatusHooks)
150
153
 
151
154
    def test_post_status_hook(self):
152
155
        """Ensure that post_status hook is invoked with the right args.
157
160
        tree = self.make_branch_and_tree('.')
158
161
        r1_id = tree.commit('one', allow_pointless=True)
159
162
        r2_id = tree.commit('two', allow_pointless=True)
 
163
        r2_tree = tree.branch.repository.revision_tree(r2_id)
160
164
        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'))])
 
165
        show_tree_status(tree, to_file=output,
 
166
            revision=[RevisionSpec.from_string("revid:%s" % r1_id),
 
167
                RevisionSpec.from_string("revid:%s" % r2_id)])
164
168
        self.assertLength(1, calls)
165
169
        params = calls[0]
166
170
        self.assertIsInstance(params, _mod_status.StatusHookParams)
167
171
        attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
168
 
                 'show_ids', 'short', 'verbose', 'specific_files']
 
172
            'show_ids', 'short', 'verbose', 'specific_files']
169
173
        for a in attrs:
170
174
            self.assertTrue(hasattr(params, a),
171
 
                            'Attribute "%s" not found in StatusHookParam' % a)
 
175
                'Attribute "%s" not found in StatusHookParam' % a)
172
176
 
173
177
    def test_pre_status_hook(self):
174
178
        """Ensure that pre_status hook is invoked with the right args.
179
183
        tree = self.make_branch_and_tree('.')
180
184
        r1_id = tree.commit('one', allow_pointless=True)
181
185
        r2_id = tree.commit('two', allow_pointless=True)
 
186
        r2_tree = tree.branch.repository.revision_tree(r2_id)
182
187
        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'))])
 
188
        show_tree_status(tree, to_file=output,
 
189
            revision=[RevisionSpec.from_string("revid:%s" % r1_id),
 
190
                RevisionSpec.from_string("revid:%s" % r2_id)])
188
191
        self.assertLength(1, calls)
189
192
        params = calls[0]
190
193
        self.assertIsInstance(params, _mod_status.StatusHookParams)
191
194
        attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
192
 
                 'show_ids', 'short', 'verbose', 'specific_files']
 
195
            'show_ids', 'short', 'verbose', 'specific_files']
193
196
        for a in attrs:
194
197
            self.assertTrue(hasattr(params, a),
195
 
                            'Attribute "%s" not found in StatusHookParam' % a)
 
198
                'Attribute "%s" not found in StatusHookParam' % a)
 
199