summaryrefslogtreecommitdiff
path: root/bzrlib/tests/blackbox/test_hooks.py
diff options
context:
space:
mode:
Diffstat (limited to 'bzrlib/tests/blackbox/test_hooks.py')
-rw-r--r--bzrlib/tests/blackbox/test_hooks.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/bzrlib/tests/blackbox/test_hooks.py b/bzrlib/tests/blackbox/test_hooks.py
new file mode 100644
index 0000000..2d49a06
--- /dev/null
+++ b/bzrlib/tests/blackbox/test_hooks.py
@@ -0,0 +1,75 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Tests for commands related to hooks"""
+
+from bzrlib.branch import Branch
+from bzrlib.tests import TestCaseWithTransport
+
+def _foo_hook():
+ pass
+
+class TestHooks(TestCaseWithTransport):
+
+ def _check_hooks_output(self, command_output, hooks):
+ for hook_type in Branch.hooks:
+ s = "\n ".join(hooks.get(hook_type, ["<no hooks installed>"]))
+ self.assert_("%s:\n %s" % (hook_type, s) in command_output)
+
+ def test_hooks_with_no_hooks(self):
+ self.make_branch('.')
+ out, err = self.run_bzr('hooks')
+ self.assertEqual(err, "")
+ for hook_type in Branch.hooks:
+ self._check_hooks_output(out, {})
+
+ def test_hooks_with_unnamed_hook(self):
+ self.make_branch('.')
+ def foo(): return
+ Branch.hooks.install_named_hook('post_push', foo, None)
+ out, err = self.run_bzr('hooks')
+ self._check_hooks_output(out, {'post_push': ["No hook name"]})
+
+ def test_hooks_with_named_hook(self):
+ self.make_branch('.')
+ def foo(): return
+ name = "Foo Bar Hook"
+ Branch.hooks.install_named_hook('post_push', foo, name)
+ out, err = self.run_bzr('hooks')
+ self._check_hooks_output(out, {'post_push': [name]})
+
+ def test_hooks_no_branch(self):
+ self.run_bzr('hooks')
+
+ def test_hooks_lazy_with_unnamed_hook(self):
+ self.make_branch('.')
+ def foo(): return
+ Branch.hooks.install_named_hook_lazy('post_push',
+ 'bzrlib.tests.blackbox.test_hooks',
+ '_foo_hook',
+ None)
+ out, err = self.run_bzr('hooks')
+ self._check_hooks_output(out, {'post_push': ["No hook name"]})
+
+ def test_hooks_lazy_with_named_hook(self):
+ self.make_branch('.')
+ def foo(): return
+ Branch.hooks.install_named_hook_lazy('post_push',
+ 'bzrlib.tests.blackbox.test_hooks',
+ '_foo_hook',
+ 'hook has a name')
+ out, err = self.run_bzr('hooks')
+ self._check_hooks_output(out, {'post_push': ["hook has a name"]})