server/test/unittest_hook.py
branchstable
changeset 6796 e70ca9abfc51
parent 6781 5062d86d6ffe
child 7361 6baa4f430c9b
--- a/server/test/unittest_hook.py	Fri Jan 07 18:51:50 2011 +0100
+++ b/server/test/unittest_hook.py	Mon Jan 10 12:28:09 2011 +0100
@@ -18,6 +18,8 @@
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 """unit/functional tests for cubicweb.server.hook"""
 
+from __future__ import with_statement
+
 from logilab.common.testlib import TestCase, unittest_main, mock_object
 
 
@@ -101,20 +103,23 @@
     def test_register_bad_hook1(self):
         class _Hook(hook.Hook):
             events = ('before_add_entiti',)
-        ex = self.assertRaises(Exception, self.o.register, _Hook)
-        self.assertEqual(str(ex), 'bad event before_add_entiti on %s._Hook' % __name__)
+        with self.assertRaises(Exception) as cm:
+            self.o.register(_Hook)
+        self.assertEqual(str(cm.exception), 'bad event before_add_entiti on %s._Hook' % __name__)
 
     def test_register_bad_hook2(self):
         class _Hook(hook.Hook):
             events = None
-        ex = self.assertRaises(Exception, self.o.register, _Hook)
-        self.assertEqual(str(ex), 'bad .events attribute None on %s._Hook' % __name__)
+        with self.assertRaises(Exception) as cm:
+            self.o.register(_Hook)
+        self.assertEqual(str(cm.exception), 'bad .events attribute None on %s._Hook' % __name__)
 
     def test_register_bad_hook3(self):
         class _Hook(hook.Hook):
             events = 'before_add_entity'
-        ex = self.assertRaises(Exception, self.o.register, _Hook)
-        self.assertEqual(str(ex), 'bad event b on %s._Hook' % __name__)
+        with self.assertRaises(Exception) as cm:
+            self.o.register(_Hook)
+        self.assertEqual(str(cm.exception), 'bad event b on %s._Hook' % __name__)
 
     def test_call_hook(self):
         self.o.register(AddAnyHook)