[Python-Dev] [Python-checkins] r85288 - in python/branches/py3k/Lib: concurrent/futures/_base.py test/test_concurrent_futures.py (original) (raw)
Benjamin Peterson benjamin at python.org
Wed Oct 6 17:02:22 CEST 2010
- Previous message: [Python-Dev] socket.fromfd() documentation problem
- Next message: [Python-Dev] hashlib bug when built on OS X 10.6 for 10.5
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2010/10/6 brian.quinlan <python-checkins at python.org>:
Author: brian.quinlan Date: Wed Oct 6 15:05:45 2010 New Revision: 85288
Log: Fixes 9903: testconcurrentfutures writes on stderr Modified: python/branches/py3k/Lib/concurrent/futures/base.py python/branches/py3k/Lib/test/testconcurrentfutures.py Modified: python/branches/py3k/Lib/concurrent/futures/base.py ============================================================================== --- python/branches/py3k/Lib/concurrent/futures/base.py (original) +++ python/branches/py3k/Lib/concurrent/futures/base.py Wed Oct 6 15:05:45 2010 @@ -40,9 +40,8 @@ # Logger for internal use by the futures package. LOGGER = logging.getLogger("concurrent.futures") -handler = logging.StreamHandler() -LOGGER.addHandler(handler) -del handler +STDERRHANDLER = logging.StreamHandler() +LOGGER.addHandler(STDERRHANDLER) class Error(Exception): """Base class for all future-related exceptions.""" Modified: python/branches/py3k/Lib/test/testconcurrentfutures.py ============================================================================== --- python/branches/py3k/Lib/test/testconcurrentfutures.py (original) +++ python/branches/py3k/Lib/test/testconcurrentfutures.py Wed Oct 6 15:05:45 2010 @@ -9,6 +9,8 @@ # without thread support. test.support.importmodule('threading') +import io +import logging import multiprocessing import sys import threading @@ -21,7 +23,8 @@ from concurrent import futures from concurrent.futures.base import ( - PENDING, RUNNING, CANCELLED, CANCELLEDANDNOTIFIED, FINISHED, Future, wait) + PENDING, RUNNING, CANCELLED, CANCELLEDANDNOTIFIED, FINISHED, Future, + LOGGER, STDERRHANDLER, wait) import concurrent.futures.process def createfuture(state=PENDING, exception=None, result=None): @@ -617,24 +620,33 @@ self.assertTrue(wascancelled) def testdonecallbackraises(self): - raisingwascalled = False - fnwascalled = False - - def raisingfn(callbackfuture): - nonlocal raisingwascalled - raisingwascalled = True - raise Exception('doh!') - - def fn(callbackfuture): - nonlocal fnwascalled - fnwascalled = True - - f = Future() - f.adddonecallback(raisingfn) - f.adddonecallback(fn) - f.setresult(5) - self.assertTrue(raisingwascalled) - self.assertTrue(fnwascalled) + LOGGER.removeHandler(STDERRHANDLER) + loggingstream = io.StringIO() + handler = logging.StreamHandler(loggingstream) + LOGGER.addHandler(handler) + try: + raisingwascalled = False + fnwascalled = False + + def raisingfn(callbackfuture): + nonlocal raisingwascalled + raisingwascalled = True + raise Exception('doh!') + + def fn(callbackfuture): + nonlocal fnwascalled + fnwascalled = True + + f = Future() + f.adddonecallback(raisingfn) + f.adddonecallback(fn) + f.setresult(5) + self.assertTrue(raisingwascalled) + self.assertTrue(fnwascalled) + self.assertIn('Exception: doh!', loggingstream.getvalue()) + finally: + LOGGER.removeHandler(handler) + LOGGER.addHandler(STDERRHANDLER)
You could use TestCase.addCleanup() here.
-- Regards, Benjamin
- Previous message: [Python-Dev] socket.fromfd() documentation problem
- Next message: [Python-Dev] hashlib bug when built on OS X 10.6 for 10.5
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]