Changeset 58
- Timestamp:
- Mon Jun 5 21:28:22 2006
- Files:
-
- branches/0.9-stable/unit_tests/test_result.py (modified) (diff)
- branches/0.9-stable/unit_tests/test_proxy.py (modified) (diff)
- branches/0.9-stable/nose/core.py (modified) (diff)
- branches/0.9-stable/nose/plugins/cover.py (modified) (diff)
- branches/0.9-stable/nose/result.py (modified) (diff)
- branches/0.9-stable/nose/proxy.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
branches/0.9-stable/unit_tests/test_result.py
r40 r58 4 4 from nose.config import Config 5 5 from nose.exc import DeprecatedTest, SkipTest 6 from nose.result import start_capture, end_capture 6 7 7 8 class TestResult(unittest.TestCase): … … 20 21 self.tr = nose.result.TextTestResult(stream, None, 2, Config()) 21 22 22 def tearDown(self): 23 nose.result.end_capture() 23 # def tearDown(self): 24 # nose.result.end_capture() 24 25 25 26 def test_capture(self): 26 nose.result.start_capture() 27 print "Hello" 28 self.assertEqual(nose.result.buffer.getvalue(), "Hello\n") 29 nose.result.end_capture() 27 start_capture() 28 try: 29 print "Hello" 30 self.assertEqual(sys.stdout.getvalue(), "Hello\n") 31 finally: 32 end_capture() 30 33 31 34 def test_init(self): … … 51 54 52 55 # test with capture 53 tr.capture = True 54 nose.result.buffer.write("some output") 55 tr.addError(test, err) 56 self.assertEqual(tr.errors[1], 57 (test, tr._exc_info_to_string(err, test), 58 'some output')) 59 self.assertEqual(buf, [ 'ERROR', 'ERROR' ]) 56 start_capture() 57 try: 58 tr.capture = True 59 print "some output" 60 tr.addError(test, err) 61 self.assertEqual(tr.errors[1], 62 (test, tr._exc_info_to_string(err, test), 63 'some output\n')) 64 self.assertEqual(buf, [ 'ERROR', 'ERROR' ]) 65 finally: 66 end_capture() 60 67 61 68 # test deprecated … … 92 99 93 100 # test with capture 94 tr.capture = True 95 nose.result.buffer.write("some output") 96 tr.addFailure(test, err) 97 self.assertEqual(tr.failures[1], 98 (test, tr._exc_info_to_string(err, test), 99 'some output')) 100 self.assertEqual(buf, [ 'FAIL', 'FAIL' ]) 101 start_capture() 102 try: 103 tr.capture = True 104 print "some output" 105 tr.addFailure(test, err) 106 self.assertEqual(tr.failures[1], 107 (test, tr._exc_info_to_string(err, test), 108 'some output\n')) 109 self.assertEqual(buf, [ 'FAIL', 'FAIL' ]) 110 finally: 111 end_capture() 101 112 102 113 def test_start_stop(self): -
branches/0.9-stable/unit_tests/test_proxy.py
r40 r58 24 24 class TC(unittest.TestCase): 25 25 def runTest(self): 26 print "RUNTEST %s" % self 26 27 pass 27 28 … … 81 82 self.assertEqual(len(res.failures), 1) 82 83 84 # shouldStop is proxied 85 self.assertEqual(pr.shouldStop, res.shouldStop) 86 pr.shouldStop = True 87 assert res.shouldStop 88 83 89 def test_output_capture(self): 84 90 … … 113 119 Result.conf = c 114 120 115 errcase = TestProxy(self.ErrTC('test_err')) 116 failcase = TestProxy(self.ErrTC('test_fail')) 117 passcase = TestProxy(self.TC()) 121 errcase = self.ErrTC('test_err') 122 failcase = self.ErrTC('test_fail') 123 passcase = self.TC() 118 124 119 125 suite = ResultProxySuite([errcase, failcase, passcase]) 126 print list(suite) 127 128 for test in suite: 129 print test 130 assert isinstance(test, TestProxy) 120 131 121 132 d = dummy() 122 133 res = unittest._TextTestResult(d, 1, 1) 123 134 suite.run(res) 124 125 135 res.printErrors() 136 print d.buf 126 137 127 138 # split internal \n in strings into own lines -
branches/0.9-stable/nose/core.py
r55 r58 417 417 l = logging.getLogger(logger_name) 418 418 l.setLevel(logging.DEBUG) 419 if not l.handlers: 419 if not l.handlers and not logger_name.startswith('nose'): 419 419 l.addHandler(handler) 420 420 -
branches/0.9-stable/nose/plugins/cover.py
r40 r58 38 38 dest="cover_packages", 39 39 help="Restrict coverage output to selected packages " 40 " (implies -l)[NOSE_COVER_PACKAGE]")40 "[NOSE_COVER_PACKAGE]") 40 40 parser.add_option("--cover-erase", action="store_true", 41 41 default=env.get('NOSE_COVER_ERASE'), … … 48 48 default=env.get('NOSE_COVER_TESTS'), 49 49 help="Include test modules in coverage report " 50 " (implies -l)[NOSE_COVER_TESTS]")50 "[NOSE_COVER_TESTS]") 50 50 51 51 def configure(self, options, config): … … 79 79 def report(self, stream): 80 80 log.debug("Coverage report") 81 import coverage 81 import coverage 82 coverage.stop() 82 83 modules = [ module 83 84 for name, module in sys.modules.items() 84 85 if self.wantModuleCoverage(name, module) ] 85 86 log.debug("Coverage report will cover modules: %s", modules) 86 coverage.report(modules, stream) 87 coverage.report(modules, file=stream) 86 87 87 88 def wantModuleCoverage(self, name, module): -
branches/0.9-stable/nose/result.py
r40 r58 19 19 from nose.plugins import call_plugins 20 20 21 buffer = StringIO() 21 # buffer = StringIO() 21 21 stdout = [] 22 22 … … 41 41 self.addSkip(test) 42 42 else: 43 self.capt = buffer.getvalue()43 self.capt = self.getBuffer() 43 43 if self.conf.debugErrors: 44 44 if self.conf.capture: … … 55 55 56 56 def addFailure(self, test, err): 57 self.capt = buffer.getvalue()57 self.capt = self.getBuffer() 57 57 if self.conf.debugFailures: 58 58 if self.conf.capture: … … 80 80 81 81 def addSuccess(self, test): 82 self.capt = buffer.getvalue()82 self.capt = self.getBuffer() 82 82 self.resetBuffer() 83 83 call_plugins(self.conf.plugins, 'addSuccess', test, self.capt) 84 84 85 def getBuffer(self): 86 try: 87 return sys.stdout.getvalue() 88 except AttributeError: 89 # capture is probably off 90 return '' 91 85 92 def isDeprecated(self, err): 86 if err[0] is DeprecatedTest: 93 if err[0] is DeprecatedTest or isinstance(err[0], DeprecatedTest): 86 93 return True 87 # FIXME also if is subclass or instance of DeprecatedTest?88 94 return False 89 95 90 96 def isSkip(self, err): 91 if err[0] is SkipTest: 97 if err[0] is SkipTest or isinstance(err[0], SkipTest): 91 97 return True 92 # FIXME also if is subclass or instance of SkipTest?93 98 return False 94 99 95 100 def resetBuffer(self): 96 buffer.truncate(0) 97 buffer.seek(0) 101 sys.stdout.truncate(0) 102 sys.stdout.seek(0) 98 103 99 104 def startTest(self, test): … … 216 221 """Start capturing output to stdout. DOES NOT reset the buffer. 217 222 """ 223 log.debug('start capture from %r' % sys.stdout) 218 224 stdout.append(sys.stdout) 219 sys.stdout = buffer 220 225 sys.stdout = StringIO() 226 log.debug('sys.stdout is now %r' % sys.stdout) 221 227 222 228 def end_capture(): … … 225 231 if stdout: 226 232 sys.stdout = stdout.pop() 233 log.debug('capture ended, sys.stdout is now %r' % sys.stdout) 227 234 228 235 -
branches/0.9-stable/nose/proxy.py
r40 r58 7 7 TestLoader. 8 8 """ 9 import logging 9 10 import unittest 10 11 from nose.result import Result, ln 11 12 12 13 log = logging.getLogger(__name__) 14 13 15 class ResultProxy(Result): 14 16 """Result proxy. Performs nose-specific result operations, such as … … 20 22 21 23 def addError(self, test, err): 24 log.debug('Proxy addError %s %s', test, err) 22 25 Result.addError(self, test, err) 23 26 … … 31 34 32 35 def addFailure(self, test, err): 36 log.debug('Proxy addFailure %s %s', test, err) 33 37 Result.addFailure(self, test, err) 34 38 … … 60 64 61 65 def _set_shouldStop(self, val): 62 self.result.shou dlStop = val66 self.result.shouldStop = val 62 66 63 67 shouldStop = property(_get_shouldStop, _set_shouldStop) … … 68 72 """Test suite that supports output capture, etc, by wrapping each test in 69 73 a TestProxy. 70 """ 71 def __iter__(self): 72 return iter(map(TestProxy, self._tests)) 73 74 """ 75 def addTest(self, test): 76 """Add test, first wrapping in TestProxy""" 77 self._tests.append(TestProxy(test)) 74 78 79 75 80 class TestProxy(unittest.TestCase): 76 81 """Test case that wraps the test result in a ResultProxy. … … 80 85 def __init__(self, wrapped_test): 81 86 self.wrapped_test = wrapped_test 87 log.debug('%r.__init__', self) 88 89 def __call__(self, *arg, **kw): 90 log.debug('%r.__call__', self) 91 self.run(*arg, **kw) 92 93 def __repr__(self): 94 return "TestProxy for: %r" % self.wrapped_test 82 95 83 def __call__(self, result): 84 self.run(result) 96 def __str__(self): 97 return str(self.wrapped_test) 85 98 86 99 def id(self): … … 88 101 89 102 def run(self, result): 103 log.debug('TestProxy run test %s in proxy %s for result %s', 104 self, self.resultProxy, result) 90 105 self.wrapped_test(self.resultProxy(result)) 91 106
