~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_status.py

  • Committer: Parth Malwankar
  • Date: 2010-08-28 06:52:03 UTC
  • mto: This revision was merged to the branch mainline in revision 5411.
  • Revision ID: parth.malwankar@gmail.com-20100828065203-f38yr49elu7jlhi3
added StatusPostHookParams and test cases

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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
 
 
146
    def test_installed_hooks_are_StatusHooks(self):
 
147
        """The installed hooks object should be a StatusHooks.
 
148
        """
 
149
        # the installed hooks are saved in self._preserved_hooks.
 
150
        self.assertIsInstance(self._preserved_hooks[_mod_status][1],
 
151
            _mod_status.StatusHooks)
 
152
 
 
153
    def test_post_status_hook(self):
 
154
        """Ensure that post_status hook is invoked with the right args.
 
155
        """
 
156
        calls = []
 
157
        _mod_status.hooks.install_named_hook('post_status', calls.append, None)
 
158
        self.assertLength(0, calls)
 
159
        tree = self.make_branch_and_tree('.')
 
160
        r1_id = tree.commit('one', allow_pointless=True)
 
161
        r2_id = tree.commit('two', allow_pointless=True)
 
162
        r2_tree = tree.branch.repository.revision_tree(r2_id)
 
163
        output = StringIO()
 
164
        show_tree_status(tree, to_file=output,
 
165
            revision=[RevisionSpec.from_string("revid:%s" % r1_id),
 
166
                RevisionSpec.from_string("revid:%s" % r2_id)])
 
167
        self.assertLength(1, calls)
 
168
        params = calls[0]
 
169
        self.assertIsInstance(params, _mod_status.StatusPostHookParams)
 
170
        attrs = ['old_tree', 'new_tree', 'versioned', 'show_ids', 'short']
 
171
        for a in attrs:
 
172
            self.assertTrue(hasattr(params, a),
 
173
                'Attribute "%s" not found in StatusPostHookParam' % a)
 
174