diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-01-06 18:09:10 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-01-06 18:09:10 +0100 |
commit | 9d26ddc592edb56db975fbc94c661befdccb35ee (patch) | |
tree | 587b439fe7f41824b7b6be24e24bd0ebe60e0f99 | |
parent | b643995a125f3d93c90a392887371f347221b9fb (diff) | |
download | logilab-common-9d26ddc592edb56db975fbc94c661befdccb35ee.tar.gz |
testlib: proper assertRaises compatible with old usage and as unittest2 context manager
-rw-r--r-- | testlib.py | 12 |
1 files changed, 3 insertions, 9 deletions
@@ -1143,25 +1143,19 @@ succeeded test into", osp.join(os.getcwd(), FILE_RESTART) # XXX cube vcslib : test_branches_from_app if callableObj is None: _assert = super(TestCase, self).assertRaises - return _assert(self, excClass, callableObj, *args, **kwargs) + return _assert(excClass, callableObj, *args, **kwargs) try: callableObj(*args, **kwargs) except excClass, exc: - class ProxyException(exc.__class__): + class ProxyException: def __init__(self, obj): - super(ProxyException, self).__setattr__("_obj", obj) + self._obj = obj def __getattr__(self, attr): warn_msg = ("This exception was retrieved with the old testlib way " "`exc = self.assertRaises(Exc, callable)`, please use " "the context manager instead'") warnings.warn(warn_msg, DeprecationWarning, 2) return self._obj.__getattribute__(attr) - def __setattr__(self, attr, value): - warn_msg = ("This exception was retrieved with the old testlib way " - "`exc = self.assertRaises(Exc, callable)`, please use " - "the context manager instead'") - warnings.warn(warn_msg, DeprecationWarning, 2) - return self._obj.__setattr__(attr, value) return ProxyException(exc) else: if hasattr(excClass, '__name__'): |