[Checkins] SVN: zope.hookable/trunk/ 100% unit test coverage.
Tres Seaver
cvs-admin at zope.org
Mon Jun 4 16:51:59 UTC 2012
Log message for revision 126578:
100% unit test coverage.
Changed:
_U zope.hookable/trunk/
U zope.hookable/trunk/CHANGES.txt
U zope.hookable/trunk/src/zope/hookable/tests/test_hookable.py
-=-
Modified: zope.hookable/trunk/CHANGES.txt
===================================================================
--- zope.hookable/trunk/CHANGES.txt 2012-06-04 16:51:51 UTC (rev 126577)
+++ zope.hookable/trunk/CHANGES.txt 2012-06-04 16:51:55 UTC (rev 126578)
@@ -4,6 +4,8 @@
4.0.0 (unreleased)
------------------
+- 100% unit test coverage.
+
- Added 'setup.py docs' alias (installs ``Sphinx`` and dependencies).
- Added 'setup.py dev' alias (runs ``setup.py develop`` plus installs
Modified: zope.hookable/trunk/src/zope/hookable/tests/test_hookable.py
===================================================================
--- zope.hookable/trunk/src/zope/hookable/tests/test_hookable.py 2012-06-04 16:51:51 UTC (rev 126577)
+++ zope.hookable/trunk/src/zope/hookable/tests/test_hookable.py 2012-06-04 16:51:55 UTC (rev 126578)
@@ -15,11 +15,84 @@
"""
import unittest
+class HookableTests(unittest.TestCase):
+
+ def _callFUT(self, *args, **kw):
+ from zope.hookable import hookable
+ return hookable(*args, **kw)
+
+ def test_before_hook(self):
+ def _foo():
+ return 'FOO'
+ hooked = self._callFUT(_foo)
+ self.assertTrue(hooked.original is _foo)
+ self.assertTrue(hooked.implementation is _foo)
+ self.assertEqual(hooked(), 'FOO')
+
+ def test_after_hook(self):
+ def _foo():
+ return 'FOO'
+ def _bar():
+ return 'BAR'
+ hooked = self._callFUT(_foo)
+ old = hooked.sethook(_bar)
+ self.assertTrue(old is _foo)
+ self.assertTrue(hooked.original is _foo)
+ self.assertTrue(hooked.implementation is _bar)
+ self.assertEqual(hooked(), 'BAR')
+
+ def test_after_hook_and_reset(self):
+ def _foo():
+ return 'FOO'
+ def _bar():
+ return 'BAR'
+ hooked = self._callFUT(_foo)
+ old = hooked.sethook(_bar)
+ hooked.reset()
+ self.assertTrue(old is _foo)
+ self.assertTrue(hooked.original is _foo)
+ self.assertTrue(hooked.implementation is _foo)
+ self.assertEqual(hooked(), 'FOO')
+
+ def test_original_cannot_be_deleted(self):
+ def _foo():
+ return 'FOO'
+ hooked = self._callFUT(_foo)
+ def _try():
+ del hooked.original
+ self.assertRaises((TypeError, AttributeError), _try)
+
+ def test_implementation_cannot_be_deleted(self):
+ def _foo():
+ return 'FOO'
+ hooked = self._callFUT(_foo)
+ def _try():
+ del hooked.implementation
+ self.assertRaises((TypeError, AttributeError), _try)
+
+ def test_no_args(self):
+ self.assertRaises(TypeError, self._callFUT)
+
+ def test_too_many_args(self):
+ def _foo():
+ return 'FOO'
+ self.assertRaises(TypeError, self._callFUT, _foo, _foo)
+
+ def test_w_implementation_kwarg(self):
+ def _foo():
+ return 'FOO'
+ hooked = self._callFUT(implementation=_foo)
+ self.assertTrue(hooked.original is _foo)
+ self.assertTrue(hooked.implementation is _foo)
+ self.assertEqual(hooked(), 'FOO')
+
+ def test_w_unknown_kwarg(self):
+ def _foo():
+ return 'FOO'
+ self.assertRaises(TypeError, self._callFUT, nonesuch=_foo)
+
+
def test_suite():
- import doctest
return unittest.TestSuite((
- doctest.DocTestSuite('zope.hookable',
- optionflags=doctest.ELLIPSIS |
- doctest.IGNORE_EXCEPTION_DETAIL,
- ),
+ unittest.makeSuite(HookableTests),
))
More information about the checkins
mailing list