~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_status.py

  • Committer: Jelmer Vernooij
  • Date: 2012-06-29 08:19:21 UTC
  • mfrom: (0.40.147 trunk)
  • mto: This revision was merged to the branch mainline in revision 6555.
  • Revision ID: jelmer@samba.org-20120629081921-m3asg03n6z9fzcxn
Ship the grep plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
from StringIO import StringIO
19
19
 
20
 
from bzrlib import config
 
20
from bzrlib import (
 
21
    config,
 
22
    status as _mod_status,
 
23
    )
21
24
from bzrlib.revisionspec import RevisionSpec
22
25
from bzrlib.status import show_pending_merges, show_tree_status
23
26
from bzrlib.tests import TestCaseWithTransport
43
46
        self.assertContainsRe(output.getvalue(), 'empty commit')
44
47
 
45
48
    def make_multiple_pending_tree(self):
46
 
        config.GlobalConfig().set_user_option('email', 'Joe Foo <joe@foo.com>')
 
49
        config.GlobalStack().set('email', 'Joe Foo <joe@foo.com>')
47
50
        tree = self.make_branch_and_tree('a')
48
51
        tree.commit('commit 1', timestamp=1196796819, timezone=0)
49
52
        tree2 = tree.bzrdir.clone('b').open_workingtree()
99
102
 
100
103
    def test_pending_with_ghosts(self):
101
104
        """Test when a pending merge's ancestry includes ghosts."""
102
 
        config.GlobalConfig().set_user_option('email', 'Joe Foo <joe@foo.com>')
 
105
        config.GlobalStack().set('email', 'Joe Foo <joe@foo.com>')
103
106
        tree = self.make_branch_and_tree('a')
104
107
        tree.commit('empty commit')
105
108
        tree2 = tree.bzrdir.clone('b').open_workingtree()
130
133
                     revision=[RevisionSpec.from_string("revid:%s" % r1_id),
131
134
                               RevisionSpec.from_string("revid:%s" % r2_id)])
132
135
        # return does not matter as long as it did not raise.
 
136
 
 
137
 
 
138
class TestHooks(TestCaseWithTransport):
 
139
 
 
140
    def test_constructor(self):
 
141
        """Check that creating a StatusHooks instance has the right defaults.
 
142
        """
 
143
        hooks = _mod_status.StatusHooks()
 
144
        self.assertTrue("post_status" in hooks, "post_status not in %s" % hooks)
 
145
        self.assertTrue("pre_status" in hooks, "pre_status not in %s" % hooks)
 
146
 
 
147
    def test_installed_hooks_are_StatusHooks(self):
 
148
        """The installed hooks object should be a StatusHooks.
 
149
        """
 
150
        # the installed hooks are saved in self._preserved_hooks.
 
151
        self.assertIsInstance(self._preserved_hooks[_mod_status][1],
 
152
            _mod_status.StatusHooks)
 
153
 
 
154
    def test_post_status_hook(self):
 
155
        """Ensure that post_status hook is invoked with the right args.
 
156
        """
 
157
        calls = []
 
158
        _mod_status.hooks.install_named_hook('post_status', calls.append, None)
 
159
        self.assertLength(0, calls)
 
160
        tree = self.make_branch_and_tree('.')
 
161
        r1_id = tree.commit('one', allow_pointless=True)
 
162
        r2_id = tree.commit('two', allow_pointless=True)
 
163
        r2_tree = tree.branch.repository.revision_tree(r2_id)
 
164
        output = StringIO()
 
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)])
 
168
        self.assertLength(1, calls)
 
169
        params = calls[0]
 
170
        self.assertIsInstance(params, _mod_status.StatusHookParams)
 
171
        attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
 
172
            'show_ids', 'short', 'verbose', 'specific_files']
 
173
        for a in attrs:
 
174
            self.assertTrue(hasattr(params, a),
 
175
                'Attribute "%s" not found in StatusHookParam' % a)
 
176
 
 
177
    def test_pre_status_hook(self):
 
178
        """Ensure that pre_status hook is invoked with the right args.
 
179
        """
 
180
        calls = []
 
181
        _mod_status.hooks.install_named_hook('pre_status', calls.append, None)
 
182
        self.assertLength(0, calls)
 
183
        tree = self.make_branch_and_tree('.')
 
184
        r1_id = tree.commit('one', allow_pointless=True)
 
185
        r2_id = tree.commit('two', allow_pointless=True)
 
186
        r2_tree = tree.branch.repository.revision_tree(r2_id)
 
187
        output = StringIO()
 
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)])
 
191
        self.assertLength(1, calls)
 
192
        params = calls[0]
 
193
        self.assertIsInstance(params, _mod_status.StatusHookParams)
 
194
        attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
 
195
            'show_ids', 'short', 'verbose', 'specific_files']
 
196
        for a in attrs:
 
197
            self.assertTrue(hasattr(params, a),
 
198
                'Attribute "%s" not found in StatusHookParam' % a)
 
199