def test_proxy_proxies(self): from nose.case import Test class Dummy: def __init__(self): self.__dict__['called'] = [] def __getattr__(self, attr): c = self.__dict__['called'] c.append(attr) def dummy(*arg, **kw): pass return dummy class TC(unittest.TestCase): def runTest(self): pass try: raise Exception("exception") except: err = sys.exc_info() test = TC() case = Test(test) res = Dummy() proxy = ResultProxy(res, test=case) proxy.addError(test, err) proxy.addFailure(test, err) proxy.addSuccess(test) proxy.startTest(test) proxy.stopTest(test) proxy.beforeTest(test) proxy.afterTest(test) proxy.stop() proxy.shouldStop = 'yes please' for method in [ 'addError', 'addFailure', 'addSuccess', 'startTest', 'stopTest', 'beforeTest', 'afterTest', 'stop' ]: assert method in res.called, "%s was not proxied" self.assertEqual(res.shouldStop, 'yes please')
def test_coercion_of_custom_exception(self): from nose.case import Test class CustomException(Exception): def __init__(self, message, two, three): Exception.__init__(self, message) class TC(unittest.TestCase): def runTest(self): pass test = TC() case = Test(test) res = unittest.TestResult() try: raise CustomException("the error", 2, 3) except: etype, val, tb = sys.exc_info() val = str(val) # simulate plugin shenanigans proxy = ResultProxy(res, test=case) # Python 3 coercion should happen here without error proxy.addError(test, (etype, val, tb)) proxy.addFailure(test, (etype, val, tb))
def test_proxy_proxies(self): from nose.case import Test class Dummy: def __init__(self): self.__dict__['called'] = [] def __getattr__(self, attr): c = self.__dict__['called'] c.append(attr) def dummy(*arg, **kw): pass return dummy class TC(unittest.TestCase): def runTest(self): pass try: raise Exception("exception") except: err = sys.exc_info() test = TC() case = Test(test) res = Dummy() proxy = ResultProxy(res, test=case) proxy.addError(test, err) proxy.addFailure(test, err) proxy.addSuccess(test) proxy.startTest(test) proxy.stopTest(test) proxy.beforeTest(test) proxy.afterTest(test) proxy.stop() proxy.shouldStop = 'yes please' for method in ['addError', 'addFailure', 'addSuccess', 'startTest', 'stopTest', 'beforeTest', 'afterTest', 'stop']: assert method in res.called, "%s was not proxied" self.assertEqual(res.shouldStop, 'yes please')