def test_proxy_handles_missing_methods(self): from nose.case import Test class TC(unittest.TestCase): def runTest(self): pass test = TC() case = Test(test) res = unittest.TestResult() proxy = ResultProxy(res, case) proxy.beforeTest(test) proxy.afterTest(test)
def test_attributes_are_proxied(self): res = unittest.TestResult() proxy = ResultProxy(res, test=None) proxy.errors proxy.failures proxy.shouldStop proxy.testsRun
def test_proxy_has_nose_methods(self): res = unittest.TestResult() proxy = ResultProxy(res, test=None) methods = ['beforeTest', 'afterTest'] for method in methods: m = getattr(proxy, method) assert ismethod(m), "%s is not a method" % method
def test_proxy_has_basic_methods(self): res = unittest.TestResult() proxy = ResultProxy(res, test=None) methods = [ 'addError', 'addFailure', 'addSuccess', 'startTest', 'stopTest', 'stop' ] for method in methods: m = getattr(proxy, method) assert ismethod(m), "%s is not a method" % method
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_test_cases_can_access_result_attributes(self): from nose.case import Test class TC(unittest.TestCase): def run(self, result): unittest.TestCase.run(self, result) print "errors", result.errors print "failures", result.failures def runTest(self): pass test = TC() case = Test(test) res = unittest.TestResult() proxy = ResultProxy(res, test=case) case(proxy)
def __call__(self, result, test): """Return a ResultProxy for the current test. On first call, plugins are given a chance to replace the result used for the remaining tests. If a plugin returns a value from prepareTestResult, that object will be used as the result for all tests. """ if not self.__prepared: self.__prepared = True plug_result = self.config.plugins.prepareTestResult(result) if plug_result is not None: self.__result = result = plug_result if self.__result is not None: result = self.__result return ResultProxy(result, test, config=self.config)
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 run(self, result, debug=False): result = ResultProxy(result, self._tests[0], config) return super(Suite, self).run(result, debug=debug)
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')